1 #ifndef INCLUDED_UILIB_H
2 #define INCLUDED_UILIB_H
6 using ui_alignment = struct _GtkAlignment;
7 using ui_box = struct _GtkBox;
8 using ui_button = struct _GtkButton;
9 using ui_checkbutton = struct _GtkCheckButton;
10 using ui_evkey = struct _GdkEventKey;
11 using ui_hbox = struct _GtkHBox;
12 using ui_label = struct _GtkLabel;
13 using ui_menu = struct _GtkMenu;
14 using ui_menuitem = struct _GtkMenuItem;
15 using ui_modal = struct ModalDialog;
16 using ui_scrolledwindow = struct _GtkScrolledWindow;
17 using ui_treemodel = struct _GtkTreeModel;
18 using ui_treeview = struct _GtkTreeView;
19 using ui_typeinst = struct _GTypeInstance;
20 using ui_vbox = struct _GtkVBox;
21 using ui_widget = struct _GtkWidget;
22 using ui_window = struct _GtkWindow;
26 void init(int argc, char *argv[]);
30 enum class alert_type {
38 enum class alert_icon {
46 enum class alert_response {
53 template<class Self, class T>
57 { return (T *) static_cast<const Self *>(this)->_handle; }
67 Base(void *h) : _handle(h)
70 explicit operator bool() const
71 { return _handle != nullptr; }
73 explicit operator ui_typeinst *() const
74 { return (ui_typeinst *) _handle; }
76 explicit operator void *() const
80 static_assert(sizeof(Base) == sizeof(ui_widget *), "object slicing");
82 class Widget : public Base, public Convertible<Widget, ui_widget> {
84 using native = ui_widget;
85 explicit Widget(ui_widget *h = nullptr) : Base((void *) h)
88 alert_response alert(std::string text, std::string title = "NetRadiant",
89 alert_type type = alert_type::OK, alert_icon icon = alert_icon::DEFAULT);
91 const char *file_dialog(bool open, const char *title, const char *path = nullptr,
92 const char *pattern = nullptr, bool want_load = false, bool want_import = false,
93 bool want_save = false);
96 static_assert(sizeof(Widget) == sizeof(Base), "object slicing");
100 #define WRAP(name, super, impl, methods) \
101 class name : public super, public Convertible<name, impl> { \
103 using native = impl; \
104 explicit name(impl *h) : super(reinterpret_cast<super::native *>(h)) {} \
107 static_assert(sizeof(name) == sizeof(super), "object slicing")
109 WRAP(Alignment, Widget, ui_alignment,
110 Alignment(float xalign, float yalign, float xscale, float yscale);
113 WRAP(Box, Widget, ui_box,);
115 WRAP(Button, Widget, ui_button,
117 Button(const char *label);
120 WRAP(CheckButton, Widget, ui_checkbutton,
121 CheckButton(const char *label);
124 WRAP(HBox, Box, ui_hbox,
125 HBox(bool homogenous, int spacing);
128 WRAP(Label, Widget, ui_label,
129 Label(const char *label);
132 WRAP(Menu, Widget, ui_menu,
136 WRAP(MenuItem, Widget, ui_menuitem,
137 MenuItem(const char *label, bool mnemonic = false);
140 WRAP(ScrolledWindow, Widget, ui_scrolledwindow,
144 WRAP(SpinButton, Widget, ui_widget,);
146 WRAP(TreeModel, Widget, ui_treemodel,);
148 WRAP(TreeView, Widget, ui_treeview,
149 TreeView(TreeModel model);
152 WRAP(VBox, Box, ui_vbox,
153 VBox(bool homogenous, int spacing);
156 WRAP(Window, Widget, ui_window,
157 Window() : Window(nullptr) {};
159 Window create_dialog_window(const char *title, void func(), void *data, int default_w = -1,
162 Window create_modal_dialog_window(const char *title, ui_modal &dialog, int default_w = -1,
165 Window create_floating_window(const char *title);
167 std::uint64_t on_key_press(bool (*f)(Widget widget, ui_evkey *event, void *extra),
168 void *extra = nullptr);