Mercurial > projects > doodle
diff doodle/gtk/palette.d @ 61:08ffc44fc21a
More palette work.
author | daveb |
---|---|
date | Wed, 11 Aug 2010 15:07:58 +0930 |
parents | doodle/gtk/palette2.d@e64baac3efb2 |
children | 43cc2135ced0 |
line wrap: on
line diff
--- a/doodle/gtk/palette.d Tue Aug 10 22:55:54 2010 +0930 +++ b/doodle/gtk/palette.d Wed Aug 11 15:07:58 2010 +0930 @@ -15,7 +15,7 @@ import std.stdio; } -class Palette : Toolbar, IPalette { +class Palette(T) : Toolbar, IPalette!T { this() { // INVALID, MENU, SMALL_TOOLBAR, LARGE_TOOLBAR, // BUTTON, DND, DIALOG @@ -27,12 +27,12 @@ setTooltips(true); } - override void configure(in Item[] items) { - _items = items.dup; + override void configure(Item[] items, Callback callback) { + _callback = callback; RadioToolButton group; - foreach(index, item; _items) { + foreach(index, item; items) { RadioToolButton button; if (index == 0) { @@ -50,29 +50,33 @@ button.setLabelWidget(label); button.setTooltipText(item.tooltipText); - int * i = new int; - *i = index; - button.objectGSetDataFull(_indexStr, cast(gpointer)i); + _buttons[item.t] = button; + button.objectGSetDataFull(_indexStr, cast(gpointer)item.t); button.addOnClicked(&onClicked); insert(button); } } - override void activate(in int index) { - warning("Not yet implemented"); + void activate(T t) { + RadioToolButton button = _buttons[t]; + if (!button.getActive) { + button.setActive(true); + } } private { immutable _iconBase = "/home/daveb/source/d/doodle/doodle/gtk/data"; immutable _indexStr = "index"; - Item[] _items; + + Callback _callback; + RadioToolButton[T] _buttons; void onClicked(ToolButton toolButton) { RadioToolButton button = cast(RadioToolButton)toolButton; if (button.getActive) { - int * i = cast(int *)button.getData(_indexStr); - _items[*i].callback(*i); + T t = cast(T)button.getData(_indexStr); + _callback(t); } } }