1 #ifndef INCLUDED_UILIB_H
2 #define INCLUDED_UILIB_H
6 using ui_accelgroup = struct _GtkAccelGroup;
7 using ui_adjustment = struct _GtkAdjustment;
8 using ui_alignment = struct _GtkAlignment;
9 using ui_box = struct _GtkBox;
10 using ui_button = struct _GtkButton;
11 using ui_checkbutton = struct _GtkCheckButton;
12 using ui_combobox = struct _GtkComboBox;
13 using ui_cellrenderer = struct _GtkCellRenderer;
14 using ui_cellrenderertext = struct _GtkCellRendererText;
15 using ui_entry = struct _GtkEntry;
16 using ui_evkey = struct _GdkEventKey;
17 using ui_frame = struct _GtkFrame;
18 using ui_hbox = struct _GtkHBox;
19 using ui_hpaned = struct _GtkHPaned;
20 using ui_image = struct _GtkImage;
21 using ui_label = struct _GtkLabel;
22 using ui_menu = struct _GtkMenu;
23 using ui_menuitem = struct _GtkMenuItem;
24 using ui_modal = struct ModalDialog;
25 using ui_object = struct _GtkObject;
26 using ui_paned = struct _GtkPaned;
27 using ui_scrolledwindow = struct _GtkScrolledWindow;
28 using ui_spinbutton = struct _GtkSpinButton;
29 using ui_table = struct _GtkTable;
30 using ui_treemodel = struct _GtkTreeModel;
31 using ui_treepath = struct _GtkTreePath;
32 using ui_treeview = struct _GtkTreeView;
33 using ui_treeviewcolumn = struct _GtkTreeViewColumn;
34 using ui_typeinst = struct _GTypeInstance;
35 using ui_vbox = struct _GtkVBox;
36 using ui_vpaned = struct _GtkVPaned;
37 using ui_widget = struct _GtkWidget;
38 using ui_window = struct _GtkWindow;
42 void init(int argc, char *argv[]);
46 enum class alert_type {
54 enum class alert_icon {
62 enum class alert_response {
69 enum class window_type {
74 template<class Self, class T, bool implicit = true>
77 template<class Self, class T>
78 struct Convertible<Self, T, true> {
80 { return reinterpret_cast<T *>(static_cast<const Self *>(this)->_handle); }
83 template<class Self, class T>
84 struct Convertible<Self, T, false> {
85 explicit operator T *() const
86 { return reinterpret_cast<T *>(static_cast<const Self *>(this)->_handle); }
89 class Object : public Convertible<Object, ui_object, false> {
91 using native = ui_object;
94 Object(void *h) : _handle(h)
97 explicit operator bool() const
98 { return _handle != nullptr; }
100 explicit operator ui_typeinst *() const
101 { return (ui_typeinst *) _handle; }
103 explicit operator void *() const
107 static_assert(sizeof(Object) == sizeof(ui_widget *), "object slicing");
109 class Widget : public Object, public Convertible<Widget, ui_widget> {
111 using native = ui_widget;
112 explicit Widget(ui_widget *h = nullptr) : Object((void *) h)
115 alert_response alert(std::string text, std::string title = "NetRadiant",
116 alert_type type = alert_type::OK, alert_icon icon = alert_icon::DEFAULT);
118 const char *file_dialog(bool open, const char *title, const char *path = nullptr,
119 const char *pattern = nullptr, bool want_load = false, bool want_import = false,
120 bool want_save = false);
123 static_assert(sizeof(Widget) == sizeof(Object), "object slicing");
127 #define WRAP(name, super, impl, methods) \
128 class name : public super, public Convertible<name, impl> { \
130 using native = impl; \
131 explicit name(impl *h) : super(reinterpret_cast<super::native *>(h)) {} \
134 static_assert(sizeof(name) == sizeof(super), "object slicing")
136 WRAP(AccelGroup, Object, ui_accelgroup,
140 WRAP(Adjustment, Widget, ui_adjustment,
141 Adjustment(double value,
142 double lower, double upper,
143 double step_increment, double page_increment,
147 WRAP(Alignment, Widget, ui_alignment,
148 Alignment(float xalign, float yalign, float xscale, float yscale);
151 WRAP(Box, Widget, ui_box,);
153 WRAP(Button, Widget, ui_button,
155 Button(const char *label);
158 WRAP(CellRenderer, Object, ui_cellrenderer,);
160 WRAP(CellRendererText, CellRenderer, ui_cellrenderertext,
164 WRAP(CheckButton, Widget, ui_checkbutton,
165 CheckButton(const char *label);
168 WRAP(ComboBox, Widget, ui_combobox,);
170 ComboBox ComboBoxText();
172 WRAP(Entry, Widget, ui_entry,
174 Entry(std::size_t max_length);
177 WRAP(Frame, Widget, ui_frame,
178 Frame(const char *label = nullptr);
181 WRAP(HBox, Box, ui_hbox,
182 HBox(bool homogenous, int spacing);
185 WRAP(Image, Widget, ui_image,
189 WRAP(Label, Widget, ui_label,
190 Label(const char *label);
193 WRAP(Menu, Widget, ui_menu,
197 WRAP(MenuItem, Widget, ui_menuitem,
198 MenuItem(const char *label, bool mnemonic = false);
201 WRAP(Paned, Widget, ui_paned,);
203 WRAP(HPaned, Paned, ui_hpaned,
207 WRAP(VPaned, Paned, ui_vpaned,
211 WRAP(ScrolledWindow, Widget, ui_scrolledwindow,
215 WRAP(SpinButton, Widget, ui_spinbutton,
216 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
219 WRAP(Table, Widget, ui_table,
220 Table(std::size_t rows, std::size_t columns, bool homogenous);
223 WRAP(TreeModel, Widget, ui_treemodel,);
225 WRAP(TreePath, Object, ui_treepath,
227 TreePath(const char *path);
230 WRAP(TreeView, Widget, ui_treeview,
232 TreeView(TreeModel model);
235 struct TreeViewColumnAttribute {
236 const char *attribute;
239 WRAP(TreeViewColumn, Widget, ui_treeviewcolumn,
240 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
243 WRAP(VBox, Box, ui_vbox,
244 VBox(bool homogenous, int spacing);
247 WRAP(Window, Widget, ui_window,
248 Window() : Window(nullptr) {};
249 Window(window_type type);
251 Window create_dialog_window(const char *title, void func(), void *data, int default_w = -1,
254 Window create_modal_dialog_window(const char *title, ui_modal &dialog, int default_w = -1,
257 Window create_floating_window(const char *title);
259 std::uint64_t on_key_press(bool (*f)(Widget widget, ui_evkey *event, void *extra),
260 void *extra = nullptr);