1 #ifndef INCLUDED_UILIB_H
2 #define INCLUDED_UILIB_H
6 using ui_typeinst = struct _GTypeInstance;
7 using ui_widget = struct _GtkWidget;
8 using ui_window = struct _GtkWindow;
9 using ui_menuitem = struct _GtkMenuItem;
10 using ui_label = struct _GtkLabel;
12 using ui_evkey = struct _GdkEventKey;
14 using ui_modal = struct ModalDialog;
18 void init(int argc, char *argv[]);
22 enum class alert_type {
30 enum class alert_icon {
38 enum class alert_response {
45 template<class Self, class T>
49 { return (T *) static_cast<const Self *>(this)->_handle; }
59 Base(void *h) : _handle(h)
62 explicit operator bool() const
63 { return _handle != nullptr; }
65 explicit operator ui_typeinst *() const
66 { return (ui_typeinst *) _handle; }
68 explicit operator void *() const
72 static_assert(sizeof(Base) == sizeof(ui_widget *), "object slicing");
74 class Widget : public Base, public Convertible<Widget, ui_widget> {
76 explicit Widget(ui_widget *h = nullptr) : Base((void *) h)
79 alert_response alert(std::string text, std::string title = "NetRadiant",
80 alert_type type = alert_type::OK, alert_icon icon = alert_icon::DEFAULT);
82 const char *file_dialog(bool open, const char *title, const char *path = nullptr,
83 const char *pattern = nullptr, bool want_load = false, bool want_import = false,
84 bool want_save = false);
87 static_assert(sizeof(Widget) == sizeof(Base), "object slicing");
91 #define WIDGET(name, impl, methods) \
92 class name : public Widget, public Convertible<name, impl> { \
94 explicit name(impl *h = nullptr) : Widget(reinterpret_cast<ui_widget *>(h)) {} \
97 static_assert(sizeof(name) == sizeof(Widget), "object slicing")
99 WIDGET(Window, ui_window,
100 Window create_dialog_window(const char *title, void func(), void *data, int default_w = -1,
103 Window create_modal_dialog_window(const char *title, ui_modal &dialog, int default_w = -1,
106 Window create_floating_window(const char *title);
108 std::uint64_t on_key_press(bool (*f)(Widget widget, ui_evkey *event, void *extra),
109 void *extra = nullptr);
112 WIDGET(CheckButton, ui_widget,);
114 WIDGET(SpinButton, ui_widget,);
116 WIDGET(MenuItem, ui_menuitem,);
118 WIDGET(Label, ui_label,
119 Label(const char *label);