66 lines
1.8 KiB
Elixir
Raw Permalink Normal View History

2016-11-25 00:33:18 -07:00
------------------------------------------------------------------------
--# GTK Scale for getting numeric input
------------------------------------------------------------------------
include GtkEngine.e
constant docs = `<b><u>GtkScale</u></b>
For getting numeric input.
Drag the handle or use the mouse wheel
or right button to change value.
`
constant win = create(GtkWindow,"border=10,position=1,$destroy=Quit")
constant panel = create(GtkBox,"orientation=VERTICAL,spacing=5")
add(win,panel)
constant lbl = create(GtkLabel)
set(lbl,"markup",docs)
pack(panel,lbl)
constant scale = create(GtkScale,{
{"orientation",HORIZONTAL},
{"range",0,5}, -- range is min,max
{"value",0},
{"digits",2},
{"font","sans 12"},
{"increments",0.01,0.01}, -- step,page (these control response to mouse wheel, etc)
{"margin bottom",5},
{"draw value",TRUE},
{"has origin",TRUE}})
-- decorate the scale with legends and tick marks;
for i = 0 to 5 by 0.25 do
if integer(i) then -- put numbers at integer positions,
set(scale,"add mark",i,3,
sprintf("<span color='red'><small>%g</small></span>",i))
end if
set(scale,"add mark",i,3,"") -- tick marks at every .25 position
end for
add(panel,scale)
constant
btn1 = create(GtkButton,"gtk-quit","Quit"),
btn2 = create(GtkButton,"gtk-ok",_("ShowValue")),
btnbox = create(GtkButtonBox)
set(btn2,"can default",TRUE) -- ok button defaults when <enter> key pressed;
set(win,"default",btn2)
add(btnbox,{btn1,btn2})
pack(panel,-btnbox)
show_all(win)
main()
--------------------
function ShowValue()
--------------------
atom amt = get(scale,"value")
Info(win,,"<u>GtkScale</u>\n",
sprintf("Value is: <span color='red'>%.2f</span>",amt))
return 1
end function