X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=libs%2Fuilib%2Fuilib.h;h=d8f41c85d88559371a36f86c2ed90a33235537c3;hp=c6a3bb1fb1ff2bd858b234dbda6338f63ce0e808;hb=62a7627ffa241188e92e8417340fdf8ed5f6be82;hpb=0110e3a8f3ab54c17a1785e17c7246adf8e13a46 diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index c6a3bb1f..d8f41c85 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -31,6 +31,7 @@ struct _GtkImage; struct _GtkItem; struct _GtkLabel; struct _GtkListStore; +struct _GtkTreeIter; struct _GtkMenu; struct _GtkMenuBar; struct _GtkMenuItem; @@ -56,6 +57,7 @@ struct _GtkToolItem; struct _GtkTreeModel; struct _GtkTreePath; struct _GtkTreeSelection; +struct _GtkTreeStore; struct _GtkTreeView; struct _GtkTreeViewColumn; struct _GtkVBox; @@ -82,31 +84,6 @@ namespace ui { void process(); - extern class Widget root; - - enum class alert_type { - OK, - OKCANCEL, - YESNO, - YESNOCANCEL, - NOYES, - }; - - enum class alert_icon { - Default, - Error, - Warning, - Question, - Asterisk, - }; - - enum class alert_response { - OK, - CANCEL, - YES, - NO, - }; - enum class window_type { TOP, POPUP @@ -126,6 +103,11 @@ namespace ui { NEVER }; + enum class Packing { + START, + END + }; + namespace details { enum class Convert { @@ -165,8 +147,8 @@ namespace ui { }; } - extern struct Null {} null; - extern struct New_t {} New; + const struct Null {} null = {}; + const struct New_t {} New = {}; class Object : public details::Convertible, @@ -188,6 +170,9 @@ namespace ui { void unref() { g_object_unref(_handle); } + void ref() + { g_object_ref(_handle); } + template gulong connect(char const *detailed_signal, Lambda &&c_handler, void *data); @@ -207,9 +192,12 @@ namespace ui { public: \ using self = name *; \ using native = T *; \ - explicit name(native h) : super(reinterpret_cast(h)) {} \ - explicit name(Null n) : name((native) nullptr) {} \ + protected: \ + explicit name(native h) noexcept : super(reinterpret_cast(h)) {} \ + public: \ + explicit name(Null n) noexcept : name((native) nullptr) {} \ explicit name(New_t); \ + static name from(native h) { return name(h); } \ static name from(void *ptr) { return name((native) ptr); } \ ctors \ }; \ @@ -240,14 +228,10 @@ namespace ui { int height; }; + class Window; WRAP(Widget, Object, _GtkWidget, (), , - alert_response alert( - std::string text, - std::string title = "NetRadiant", - alert_type type = alert_type::OK, - alert_icon icon = alert_icon::Default - ); + Window window(); const char *file_dialog( bool open, const char *title, @@ -258,9 +242,12 @@ namespace ui { bool want_save = false ); bool visible(); + void visible(bool shown); void show(); + void hide(); Dimensions dimensions(); void dimensions(int width, int height); + void destroy(); ); WRAP(Container, Widget, _GtkContainer, (), @@ -327,7 +314,8 @@ namespace ui { WRAP(ToggleButton, Button, _GtkToggleButton, (), , - bool active(); + bool active() const; + void active(bool value); ); WRAP(CheckButton, ToggleButton, _GtkCheckButton, (), @@ -391,6 +379,9 @@ namespace ui { WRAP(Box, Container, _GtkBox, (), , + void pack_start(ui::Widget child, bool expand, bool fill, unsigned int padding); + void pack_end(ui::Widget child, bool expand, bool fill, unsigned int padding); + void set_child_packing(ui::Widget child, bool expand, bool fill, unsigned int padding, ui::Packing packing); ); WRAP(VBox, Box, _GtkVBox, (), @@ -427,9 +418,24 @@ namespace ui { , ); + struct TableAttach { + unsigned int left, right, top, bottom; + }; + + struct TableAttachOptions { + // todo: type safety + unsigned int x, y; + }; + + struct TablePadding { + unsigned int x, y; + }; + WRAP(Table, Container, _GtkTable, (), Table(std::size_t rows, std::size_t columns, bool homogenous); , + // 5 = expand | fill + void attach(Widget child, TableAttach attach, TableAttachOptions options = {5, 5}, TablePadding padding = {0, 0}); ); WRAP(TextView, Container, _GtkTextView, (), @@ -524,6 +530,15 @@ namespace ui { WRAP(ListStore, Object, _GtkListStore, (ITreeModel), , void clear(); + + template + void append(T... args); + + void append(); + ); + + WRAP(TreeStore, Object, _GtkTreeStore, (ITreeModel), + , ); WRAP(TreeSelection, Object, _GtkTreeSelection, (), @@ -546,6 +561,41 @@ namespace ui { #undef WRAP + // global + + enum class alert_response { + OK, + CANCEL, + YES, + NO, + }; + + enum class alert_type { + OK, + OKCANCEL, + YESNO, + YESNOCANCEL, + NOYES, + }; + + enum class alert_icon { + Default, + Error, + Warning, + Question, + Asterisk, + }; + + extern class Window root; + + alert_response alert( + Window parent, + std::string text, + std::string title = RADIANT_NAME, + alert_type type = alert_type::OK, + alert_icon icon = alert_icon::Default + ); + // callbacks namespace { @@ -575,11 +625,23 @@ namespace ui { GtkCallback cb = [](_GtkWidget *widget, void *data) -> void { using Function = typename std::decay::type; Function *f = static_cast(data); - (*f)(Widget(widget)); + (*f)(Widget::from(widget)); }; gtk_container_foreach(this, cb, &lambda); } + namespace { + extern "C" { + void gtk_list_store_insert_with_values(_GtkListStore *, _GtkTreeIter *, gint position, ...); + } + } + + template + void IListStore::append(T... args) { + static_assert(sizeof...(args) % 2 == 0, "received an odd number of arguments"); + gtk_list_store_insert_with_values(this, NULL, -1, args..., -1); + } + #undef this }