Mercurial > projects > doodle
annotate doodle/gtk/palette.d @ 136:752676232e4b
Port to GtkD-2.0 (gtk+3)
author | David Bryant <bagnose@gmail.com> |
---|---|
date | Wed, 26 Sep 2012 17:36:31 +0930 |
parents | bc5baa585b32 |
children |
rev | line source |
---|---|
61 | 1 module doodle.gtk.palette; |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
2 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
3 public { |
61 | 4 import doodle.tk.palette; |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
5 import gtk.Toolbar; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
6 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
7 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
8 private { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
9 import doodle.core.logging; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
10 import gtk.ToolButton; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
11 import gtk.RadioToolButton; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
12 import gtk.Image; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
13 import gtk.Label; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
14 import glib.ListSG; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
15 import std.stdio; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
16 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
17 |
61 | 18 class Palette(T) : Toolbar, IPalette!T { |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
19 this() { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
20 // INVALID, MENU, SMALL_TOOLBAR, LARGE_TOOLBAR, |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
21 // BUTTON, DND, DIALOG |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
22 setIconSize(GtkIconSize.LARGE_TOOLBAR); |
66 | 23 // ICONS, TEXT, BOTH, BOTH_HORIZ |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
24 setStyle(GtkToolbarStyle.ICONS); |
66 | 25 // HORIZONTAL, VERTICAL |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
26 setOrientation(GtkOrientation.HORIZONTAL); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
27 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
28 |
61 | 29 override void configure(Item[] items, Callback callback) { |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
30 _callback = callback; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
31 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
32 RadioToolButton group; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
33 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
34 foreach(index, item; items) { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
35 RadioToolButton button; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
36 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
37 if (index == 0) { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
38 ListSG list; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
39 button = new RadioToolButton(list); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
40 group = button; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
41 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
42 else { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
43 button = new RadioToolButton(group); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
44 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
45 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
46 auto image = new Image(_iconBase ~ "/" ~ item.iconPath); |
102 | 47 auto label = new Label(item.labelText); |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
48 button.setIconWidget(image); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
49 button.setLabelWidget(label); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
50 button.setTooltipText(item.tooltipText); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
51 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
52 _buttons[item.t] = button; |
119
8343c1dafac6
Make it compile under latest GtkD. Rewrote dupes.d as a single function
David Bryant <bagnose@gmail.com>
parents:
102
diff
changeset
|
53 button.setDataFull(_indexStr, cast(gpointer)item.t, null); |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
54 button.addOnClicked(&onClicked); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
55 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
56 insert(button); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
57 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
58 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
59 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
60 void activate(T t) { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
61 RadioToolButton button = _buttons[t]; |
132 | 62 if (!button.getActive()) { |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
63 button.setActive(true); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
64 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
65 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
66 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
67 private { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
68 immutable _iconBase = "/home/daveb/source/d/doodle/doodle/gtk/data"; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
69 immutable _indexStr = "index"; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
70 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
71 Callback _callback; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
72 RadioToolButton[T] _buttons; |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
73 |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
74 void onClicked(ToolButton toolButton) { |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
75 RadioToolButton button = cast(RadioToolButton)toolButton; |
132 | 76 if (button.getActive()) { |
60
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
77 T t = cast(T)button.getData(_indexStr); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
78 _callback(t); |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
79 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
80 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
81 } |
e64baac3efb2
Attempt at a templatised palette
David Bryant <bagnose@gmail.com>
parents:
diff
changeset
|
82 } |