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;
|
55
|
13 import gtk.Label;
|
51
|
14 import glib.ListSG;
|
|
15 import std.stdio;
|
|
16 }
|
|
17
|
|
18 class Palette : Toolbar, IPalette {
|
|
19 this() {
|
55
|
20 // INVALID, MENU, SMALL_TOOLBAR, LARGE_TOOLBAR,
|
|
21 // BUTTON, DND, DIALOG
|
51
|
22 setIconSize(GtkIconSize.LARGE_TOOLBAR);
|
55
|
23 // ICONS, TEXT, BOTH, BOTH_HORIZ
|
51
|
24 setStyle(GtkToolbarStyle.ICONS);
|
55
|
25 // HORIZONTAL, VERTICAL
|
51
|
26 setOrientation(GtkOrientation.HORIZONTAL);
|
|
27 setTooltips(true);
|
|
28 }
|
|
29
|
54
|
30 override void configure(in Item[] items) {
|
|
31 _items = items.dup;
|
55
|
32
|
|
33 RadioToolButton group;
|
52
|
34
|
54
|
35 foreach(index, item; _items) {
|
55
|
36 RadioToolButton button;
|
|
37
|
|
38 if (index == 0) {
|
|
39 ListSG list;
|
|
40 button = new RadioToolButton(list);
|
|
41 group = button;
|
|
42 }
|
|
43 else {
|
|
44 button = new RadioToolButton(group);
|
|
45 }
|
|
46
|
54
|
47 auto image = new Image(_iconBase ~ "/" ~ item.iconPath);
|
55
|
48 auto label = new Label(item.tooltipText);
|
|
49 button.setIconWidget(image);
|
|
50 button.setLabelWidget(label);
|
54
|
51 button.setTooltipText(item.tooltipText);
|
|
52
|
|
53 int * i = new int;
|
|
54 *i = index;
|
|
55 button.objectGSetDataFull(_indexStr, cast(gpointer)i);
|
|
56 button.addOnClicked(&onClicked);
|
|
57
|
|
58 insert(button);
|
|
59 }
|
51
|
60 }
|
|
61
|
54
|
62 override void activate(in int index) {
|
|
63 warning("Not yet implemented");
|
51
|
64 }
|
|
65
|
|
66 private {
|
54
|
67 immutable _iconBase = "/home/daveb/source/d/doodle/doodle/gtk/data";
|
|
68 immutable _indexStr = "index";
|
|
69 Item[] _items;
|
51
|
70
|
54
|
71 void onClicked(ToolButton toolButton) {
|
|
72 RadioToolButton button = cast(RadioToolButton)toolButton;
|
|
73 if (button.getActive) {
|
|
74 int * i = cast(int *)button.getData(_indexStr);
|
|
75 _items[*i].callback(*i);
|
|
76 }
|
51
|
77 }
|
|
78 }
|
|
79 }
|