Skip to content

Instantly share code, notes, and snippets.

@sebastjan-hribar
Created August 20, 2014 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebastjan-hribar/7fddbca9a0f461b27229 to your computer and use it in GitHub Desktop.
Save sebastjan-hribar/7fddbca9a0f461b27229 to your computer and use it in GitHub Desktop.
require 'green_shoes'
def set_no_days
@no_of_days = case @month
when 4 then 1..30
when 6 then 1..30
when 9 then 1..30
when 11 then 1..30
when 2 then 1..28
else 1..31
end
end
def draw_days (no_of_days)
no_of_days.each do |day|
stack width: 30, height: 30 do
border black
button day.to_s, width: 30, height: 30 do
@selected_date = day.to_s + "." + "#{@month}" + "." + "#{@year}"
alert @selected_date
end
end
end
end
Shoes.app height: 700, width: 600 do
button "Select date" do
window title: "Date picker", margin: 35, width: 300, height: 400 do
set_no_days
background antiquewhite
@month = Time.now.month
@year = Time.now.year
@day = Time.now.day
@today = "#{@day}.#{@month}.#{@year}"
@year_slot = stack margin_bottom: 5 do
para "Year: #{@year}", :align => "center"
end
@month_slot = stack margin_bottom: 5 do
para "Month: #{@month}", :align => "center"
end
@today_slot = flow do
button "#{@today}", margin_bottom: 15 do
@selected_date = @today
alert @selected_date
end
end
@year_buttons_slot = flow margin_bottom: 5 do
para "Change year"
button "<=" do
@year = @year - 1
@year_slot.clear
@year_slot.append {para "Year: #{@year}", :align => "center"}
@month_slot.clear
@month = 1
@month_slot.append {para "Month: #{@month}", :align => "center"}
end
button "=>" do
@year = @year + 1
@year_slot.clear
@year_slot.append {para "Year: #{@year}", :align => "center"}
@month_slot.clear
@month = 1
@month_slot.append {para "Month: #{@month}", :align => "center"}
end
end
@month_buttons_slot = flow margin_bottom: 5 do
para "Change month"
button "<=" do
@month = @month - 1 unless @month == 1
set_no_days
@month_slot.clear
@month_slot.append {para "Month: #{@month}", :align => "center"}
@days_slot.clear
@days_slot.append {draw_days(@no_of_days)}
end
button "=>" do
@month = @month + 1 unless @month == 12
set_no_days
@month_slot.clear
@month_slot.append {para "Month: #{@month}", :align => "center"}
@days_slot.clear
@days_slot.append {draw_days(@no_of_days)}
end
end
@days_slot = flow do
draw_days(@no_of_days)
end
end #window end
end #button end
end #App end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment