70 lines
1.8 KiB
Elixir
70 lines
1.8 KiB
Elixir
|
|
||
|
-----------------------------------------------------------------
|
||
|
--# GtkComboBox with images
|
||
|
-----------------------------------------------------------------
|
||
|
|
||
|
include GtkEngine.e
|
||
|
|
||
|
constant docs = `<u><b>GtkComboBox</b></u>
|
||
|
with a little work, you can add images
|
||
|
to a combo!
|
||
|
|
||
|
Click on the dotted line to 'tear-off' a menu!
|
||
|
`
|
||
|
-- We have to use the GtkComboBox, rather than the simpler
|
||
|
-- GtkComboBoxText, because we're adding an image to each
|
||
|
-- option;
|
||
|
|
||
|
enum NAME,PIX
|
||
|
|
||
|
constant items = {
|
||
|
{"Fish",create(GdkPixbuf,"thumbnails/fish.png",30,30)},
|
||
|
{"Fox",create(GdkPixbuf,"thumbnails/fox.png",30,30)},
|
||
|
{"Mouse",create(GdkPixbuf,"thumbnails/mouse.png",30,30)}
|
||
|
}
|
||
|
|
||
|
constant win = create(GtkWindow,"size=200x100,border_width=10,position=1,$destroy=Quit")
|
||
|
|
||
|
constant panel = create(GtkBox,"orientation=VERTICAL")
|
||
|
add(win,panel)
|
||
|
|
||
|
constant doclbl = create(GtkLabel)
|
||
|
set(doclbl,"markup",docs)
|
||
|
add(panel,doclbl)
|
||
|
|
||
|
constant
|
||
|
mdl = create(GtkListStore,{gSTR,gPIX}),
|
||
|
renderer1 = create(GtkCellRendererText),
|
||
|
renderer2 = create(GtkCellRendererPixbuf)
|
||
|
set(mdl,"data",items)
|
||
|
|
||
|
constant combo = create(GtkComboBox,{
|
||
|
{"model",mdl},
|
||
|
{"pack start",renderer1,TRUE},
|
||
|
{"add attribute",renderer1,"text",1},
|
||
|
{"pack start",renderer2,TRUE},
|
||
|
{"add attribute",renderer2,"pixbuf",2},
|
||
|
{"active",1},
|
||
|
{"connect","changed",_("UpdateTitleBar")}})
|
||
|
|
||
|
-- try this:
|
||
|
set(combo,"add tearoffs",TRUE)
|
||
|
set(combo,"title","Animals")
|
||
|
|
||
|
-- or this:
|
||
|
-- set(combo,"wrap width",2)
|
||
|
|
||
|
add(panel,combo)
|
||
|
|
||
|
show_all(win)
|
||
|
main()
|
||
|
|
||
|
-----------------------------------------
|
||
|
function UpdateTitleBar(atom ctl)
|
||
|
-----------------------------------------
|
||
|
integer x = get(ctl,"active")
|
||
|
set(win,"title",items[x][NAME])
|
||
|
set(win,"icon",items[x][PIX])
|
||
|
return 1
|
||
|
end function
|