74 lines
2.3 KiB
Elixir
Raw Permalink Normal View History

2016-11-25 00:33:18 -07:00
-------------------------------------------------------------------------------------
--# Toggle button, custom check button, Switch
-------------------------------------------------------------------------------------
include GtkEngine.e
include std/utils.e -- for iif()
constant docs = "<u><b>Various Buttons</b></u>"
constant -- strings used to display control states;
up = "<span color='blue'>Up</span>",
down = "<span color='red'>Down</span>",
on = "<span color='red'>On</span>",
off = "<span color='blue'>Off</span>",
checked = "<span color='red'>Checked</span>",
unchecked = "<span color='blue'>Unchecked</span>"
constant win = create(GtkWindow,"size=350x100,border=10,position=1,$destroy=Quit")
constant panel = add(win,create(GtkBox,VERTICAL))
constant lbl = add(panel,create(GtkLabel,{{"markup",docs}}))
constant box1 = add(panel,create(GtkGrid,"margin_bottom=5,column_homogeneous=1"))
constant
sizegroup = create(GtkSizeGroup,GTK_SIZE_GROUP_BOTH),
btn1 = create(GtkToggleButton,"gtk-edit#_Edit"),
btn2 = create(GtkCheckButton,"face-plain-symbolic#",_("ToggleMe")),
btn3 = create(GtkSwitch)
add(box1,{btn1,btn2,btn3})
set(btn1,"tooltip markup","A normal ToggleButton")
set(btn2,"tooltip markup","A <i>crazy</i> CheckButton!")
set(btn3,"tooltip markup","A Switch")
constant box2 = pack_end(panel,create(GtkButtonBox,"margin_top=10"))
add(box2,
{create(GtkButton,"gtk-quit","Quit"),
create(GtkButton,"gtk-ok",_("ShowStatus"))})
show_all(win)
main()
-----------------------------------
function ToggleMe(atom ctl)
-----------------------------------
object img = get(ctl,"image")
if get(ctl,"active") then
set(img,"from icon name","face-laugh",GTK_ICON_SIZE_LARGE_TOOLBAR)
set(ctl,"label"," Happy")
else
set(img,"from icon name","face-plain",GTK_ICON_SIZE_LARGE_TOOLBAR)
set(ctl,"label"," Sad")
end if
return 1
end function
--------------------------------------------------
function ShowStatus(atom ctl)
--------------------------------------------------
Info(win,"Buttons","Active buttons",
sprintf("Toggle Button is: %s\nCheckButton is: %s\nSwitch is: %s",
{iif(get(btn1,"active"),down,up),
iif(get(btn2,"active"),checked,unchecked),
iif(get(btn3,"active"),on,off)}))
return 1
end function