51
|
1 module doodle.gtk.palette;
|
|
2
|
|
3 public {
|
|
4 import doodle.tk.palette;
|
|
5 import gtk.Toolbar;
|
|
6 }
|
|
7
|
|
8 private {
|
54
|
9 import doodle.core.logging;
|
51
|
10 import gtk.ToolButton;
|
54
|
11 import gtk.RadioToolButton;
|
|
12 import gtk.Image;
|
51
|
13 import glib.ListSG;
|
|
14 import std.stdio;
|
|
15 }
|
|
16
|
|
17 class Palette : Toolbar, IPalette {
|
|
18 this() {
|
|
19 setIconSize(GtkIconSize.LARGE_TOOLBAR);
|
|
20 setStyle(GtkToolbarStyle.ICONS);
|
|
21 setOrientation(GtkOrientation.HORIZONTAL);
|
|
22 setTooltips(true);
|
|
23 }
|
|
24
|
54
|
25 override void configure(in Item[] items) {
|
|
26 _items = items.dup;
|
|
27 ListSG group;
|
52
|
28
|
54
|
29 foreach(index, item; _items) {
|
|
30 auto button = new RadioToolButton(group);
|
|
31 if (index == 0) group = button.getGroup;
|
|
32 auto image = new Image(_iconBase ~ "/" ~ item.iconPath);
|
|
33 button.setLabelWidget(image);
|
|
34 button.setTooltipText(item.tooltipText);
|
|
35
|
|
36 int * i = new int;
|
|
37 *i = index;
|
|
38 button.objectGSetDataFull(_indexStr, cast(gpointer)i);
|
|
39 button.addOnClicked(&onClicked);
|
|
40
|
|
41 insert(button);
|
|
42 }
|
51
|
43 }
|
|
44
|
54
|
45 override void activate(in int index) {
|
|
46 warning("Not yet implemented");
|
51
|
47 }
|
|
48
|
|
49 private {
|
54
|
50 immutable _iconBase = "/home/daveb/source/d/doodle/doodle/gtk/data";
|
|
51 immutable _indexStr = "index";
|
|
52 Item[] _items;
|
51
|
53
|
54
|
54 void onClicked(ToolButton toolButton) {
|
|
55 RadioToolButton button = cast(RadioToolButton)toolButton;
|
|
56 if (button.getActive) {
|
|
57 int * i = cast(int *)button.getData(_indexStr);
|
|
58 _items[*i].callback(*i);
|
|
59 }
|
51
|
60 }
|
|
61 }
|
|
62 }
|