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_label = struct _GtkLabel;
21 using ui_menu = struct _GtkMenu;
22 using ui_menuitem = struct _GtkMenuItem;
23 using ui_modal = struct ModalDialog;
24 using ui_object = struct _GtkObject;
25 using ui_paned = struct _GtkPaned;
26 using ui_scrolledwindow = struct _GtkScrolledWindow;
27 using ui_spinbutton = struct _GtkSpinButton;
28 using ui_table = struct _GtkTable;
29 using ui_treemodel = struct _GtkTreeModel;
30 using ui_treepath = struct _GtkTreePath;
31 using ui_treeview = struct _GtkTreeView;
32 using ui_treeviewcolumn = struct _GtkTreeViewColumn;
33 using ui_typeinst = struct _GTypeInstance;
34 using ui_vbox = struct _GtkVBox;
35 using ui_vpaned = struct _GtkVPaned;
36 using ui_widget = struct _GtkWidget;
37 using ui_window = struct _GtkWindow;
41 void init(int argc, char *argv[]);
45 enum class alert_type {
53 enum class alert_icon {
61 enum class alert_response {
68 template<class Self, class T, bool implicit = true>
71 template<class Self, class T>
72 struct Convertible<Self, T, true> {
74 { return reinterpret_cast<T *>(static_cast<const Self *>(this)->_handle); }
77 template<class Self, class T>
78 struct Convertible<Self, T, false> {
79 explicit operator T *() const
80 { return reinterpret_cast<T *>(static_cast<const Self *>(this)->_handle); }
83 class Object : public Convertible<Object, ui_object, false> {
85 using native = ui_object;
88 Object(void *h) : _handle(h)
91 explicit operator bool() const
92 { return _handle != nullptr; }
94 explicit operator ui_typeinst *() const
95 { return (ui_typeinst *) _handle; }
97 explicit operator void *() const
101 static_assert(sizeof(Object) == sizeof(ui_widget *), "object slicing");
103 class Widget : public Object, public Convertible<Widget, ui_widget> {
105 using native = ui_widget;
106 explicit Widget(ui_widget *h = nullptr) : Object((void *) h)
109 alert_response alert(std::string text, std::string title = "NetRadiant",
110 alert_type type = alert_type::OK, alert_icon icon = alert_icon::DEFAULT);
112 const char *file_dialog(bool open, const char *title, const char *path = nullptr,
113 const char *pattern = nullptr, bool want_load = false, bool want_import = false,
114 bool want_save = false);
117 static_assert(sizeof(Widget) == sizeof(Object), "object slicing");
121 #define WRAP(name, super, impl, methods) \
122 class name : public super, public Convertible<name, impl> { \
124 using native = impl; \
125 explicit name(impl *h) : super(reinterpret_cast<super::native *>(h)) {} \
128 static_assert(sizeof(name) == sizeof(super), "object slicing")
130 WRAP(AccelGroup, Object, ui_accelgroup,
134 WRAP(Adjustment, Widget, ui_adjustment,
135 Adjustment(double value,
136 double lower, double upper,
137 double step_increment, double page_increment,
141 WRAP(Alignment, Widget, ui_alignment,
142 Alignment(float xalign, float yalign, float xscale, float yscale);
145 WRAP(Box, Widget, ui_box,);
147 WRAP(Button, Widget, ui_button,
149 Button(const char *label);
152 WRAP(CellRenderer, Object, ui_cellrenderer,);
154 WRAP(CellRendererText, CellRenderer, ui_cellrenderertext,
158 WRAP(CheckButton, Widget, ui_checkbutton,
159 CheckButton(const char *label);
162 WRAP(ComboBox, Widget, ui_combobox,);
164 ComboBox ComboBoxText();
166 WRAP(Entry, Widget, ui_entry,
168 Entry(std::size_t max_length);
171 WRAP(Frame, Widget, ui_frame,
172 Frame(const char *label = nullptr);
175 WRAP(HBox, Box, ui_hbox,
176 HBox(bool homogenous, int spacing);
179 WRAP(Label, Widget, ui_label,
180 Label(const char *label);
183 WRAP(Menu, Widget, ui_menu,
187 WRAP(MenuItem, Widget, ui_menuitem,
188 MenuItem(const char *label, bool mnemonic = false);
191 WRAP(Paned, Widget, ui_paned,);
193 WRAP(HPaned, Paned, ui_hpaned,
197 WRAP(VPaned, Paned, ui_vpaned,
201 WRAP(ScrolledWindow, Widget, ui_scrolledwindow,
205 WRAP(SpinButton, Widget, ui_spinbutton,
206 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
209 WRAP(Table, Widget, ui_table,
210 Table(std::size_t rows, std::size_t columns, bool homogenous);
213 WRAP(TreeModel, Widget, ui_treemodel,);
215 WRAP(TreePath, Object, ui_treepath,
217 TreePath(const char *path);
220 WRAP(TreeView, Widget, ui_treeview,
221 TreeView(TreeModel model);
224 struct TreeViewColumnAttribute {
225 const char *attribute;
228 WRAP(TreeViewColumn, Widget, ui_treeviewcolumn,
229 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
232 WRAP(VBox, Box, ui_vbox,
233 VBox(bool homogenous, int spacing);
236 WRAP(Window, Widget, ui_window,
237 Window() : Window(nullptr) {};
239 Window create_dialog_window(const char *title, void func(), void *data, int default_w = -1,
242 Window create_modal_dialog_window(const char *title, ui_modal &dialog, int default_w = -1,
245 Window create_floating_window(const char *title);
247 std::uint64_t on_key_press(bool (*f)(Widget widget, ui_evkey *event, void *extra),
248 void *extra = nullptr);