1 #ifndef INCLUDED_UILIB_H
2 #define INCLUDED_UILIB_H
13 struct _GtkCellEditable;
14 struct _GtkCellRenderer;
15 struct _GtkCellRendererText;
16 struct _GtkCheckButton;
18 struct _GtkComboBoxText;
39 struct _GtkScrolledWindow;
40 struct _GtkSpinButton;
42 struct _GtkTearoffMenuItem;
44 struct _GtkToggleButton;
48 struct _GtkTreeViewColumn;
53 struct _GTypeInstance;
59 void init(int argc, char *argv[]);
63 extern class Widget root;
65 enum class alert_type {
73 enum class alert_icon {
81 enum class alert_response {
88 enum class window_type {
99 template<class Self, class T, Convert mode>
102 template<class Self, class T>
103 struct Convertible<Self, T, Convert::Implicit> {
105 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
108 template<class Self, class T>
109 struct Convertible<Self, T, Convert::Explicit> {
110 explicit operator T() const
111 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
114 template<class Self, class... T>
120 template<class Self, class Interfaces>
123 struct Mixin<Self, void()> {
124 using type = All<Self>;
126 template<class Self, class... Interfaces>
127 struct Mixin<Self, void(Interfaces...)> {
128 using type = All<Self, Interfaces...>;
133 public details::Convertible<Object, _GtkObject *, details::Convert::Explicit>,
134 public details::Convertible<Object, _GTypeInstance *, details::Convert::Explicit> {
136 using native = _GtkObject *;
139 Object(native h) : _handle(h)
142 explicit operator bool() const
143 { return _handle != nullptr; }
145 explicit operator void *() const
148 static_assert(sizeof(Object) == sizeof(Object::native), "object slicing");
150 #define WRAP(name, super, T, interfaces, ctors, methods) \
154 using self = name *; \
157 class name : public super, public details::Convertible<name, T *, details::Convert::Implicit>, public I##name, public details::Mixin<name, void interfaces>::type { \
159 using self = name *; \
160 using native = T *; \
161 explicit name(native h) : super(reinterpret_cast<super::native>(h)) {} \
164 inline bool operator<(name self, name other) { return self._handle < other._handle; } \
165 static_assert(sizeof(name) == sizeof(super), "object slicing")
167 // https://developer.gnome.org/gtk2/stable/ch01.html
169 WRAP(CellEditable, Object, _GtkCellEditable, (),
173 WRAP(Editable, Object, _GtkEditable, (),
176 void editable(bool value);
179 WRAP(Widget, Object, _GtkWidget, (),
182 alert_response alert(
184 std::string title = "NetRadiant",
185 alert_type type = alert_type::OK,
186 alert_icon icon = alert_icon::Default
188 const char *file_dialog(
191 const char *path = nullptr,
192 const char *pattern = nullptr,
193 bool want_load = false,
194 bool want_import = false,
195 bool want_save = false
199 WRAP(Container, Widget, _GtkContainer, (),
203 WRAP(Bin, Container, _GtkBin, (),
208 WRAP(Window, Bin, _GtkWindow, (),
210 Window(window_type type);
212 Window create_dialog_window(
220 Window create_modal_dialog_window(
227 Window create_floating_window(const char *title);
229 std::uint64_t on_key_press(
230 bool (*f)(Widget widget, _GdkEventKey *event, void *extra),
231 void *extra = nullptr
234 void add_accel_group(AccelGroup group);
237 WRAP(Dialog, Window, _GtkDialog, (),
241 WRAP(Alignment, Bin, _GtkAlignment, (),
242 Alignment(float xalign, float yalign, float xscale, float yscale);
246 WRAP(Frame, Bin, _GtkFrame, (),
247 Frame(const char *label = nullptr);
251 WRAP(Button, Bin, _GtkButton, (),
253 Button(const char *label);
257 WRAP(ToggleButton, Button, _GtkToggleButton, (),
262 WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
263 CheckButton(const char *label);
267 WRAP(Item, Bin, _GtkItem, (),
271 WRAP(MenuItem, Item, _GtkMenuItem, (),
273 MenuItem(const char *label, bool mnemonic = false);
276 WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (),
281 WRAP(ComboBox, Bin, _GtkComboBox, (),
285 WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (),
290 WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
295 WRAP(Box, Container, _GtkBox, (),
299 WRAP(VBox, Box, _GtkVBox, (),
300 VBox(bool homogenous, int spacing);
304 WRAP(HBox, Box, _GtkHBox, (),
305 HBox(bool homogenous, int spacing);
309 WRAP(Paned, Container, _GtkPaned, (),
313 WRAP(HPaned, Paned, _GtkHPaned, (),
318 WRAP(VPaned, Paned, _GtkVPaned, (),
323 WRAP(MenuShell, Container, _GtkMenuShell, (),
327 WRAP(Menu, Widget, _GtkMenu, (),
332 WRAP(Table, Widget, _GtkTable, (),
333 Table(std::size_t rows, std::size_t columns, bool homogenous);
337 WRAP(TextView, Widget, _GtkTextView, (),
343 WRAP(TreeView, Widget, _GtkTreeView, (),
345 TreeView(TreeModel model);
349 WRAP(Misc, Widget, _GtkMisc, (),
353 WRAP(Label, Widget, _GtkLabel, (),
354 Label(const char *label);
358 WRAP(Image, Widget, _GtkImage, (),
363 WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable),
365 Entry(std::size_t max_length);
370 WRAP(SpinButton, Entry, _GtkSpinButton, (),
371 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
375 WRAP(Range, Widget, _GtkRange, (),
379 WRAP(Scale, Range, _GtkScale, (),
383 WRAP(HScale, Scale, _GtkHScale, (),
384 HScale(Adjustment adjustment);
385 HScale(double min, double max, double step);
389 WRAP(Adjustment, Object, _GtkAdjustment, (),
390 Adjustment(double value,
391 double lower, double upper,
392 double step_increment, double page_increment,
397 WRAP(CellRenderer, Object, _GtkCellRenderer, (),
401 WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (),
406 struct TreeViewColumnAttribute {
407 const char *attribute;
410 WRAP(TreeViewColumn, Object, _GtkTreeViewColumn, (),
411 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
415 WRAP(AccelGroup, Object, _GtkAccelGroup, (),
420 WRAP(ListStore, Object, _GtkListStore, (),
424 WRAP(TreeModel, Widget, _GtkTreeModel, (),
428 WRAP(TreePath, Object, _GtkTreePath, (),
430 TreePath(const char *path);