]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.h
Misc fixes
[xonotic/netradiant.git] / libs / uilib / uilib.h
index f02a51727939bc8ed1fa7f98b04b7e78065d5546..7afd8b68ecb1c76f3341804f7cb5602cb0efdb6c 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef INCLUDED_UILIB_H
 #define INCLUDED_UILIB_H
 
+#include "globaldefs.h"
+
 #include <string>
 #include <glib-object.h>
 
@@ -57,6 +59,7 @@ struct _GtkToolItem;
 struct _GtkTreeModel;
 struct _GtkTreePath;
 struct _GtkTreeSelection;
+struct _GtkTreeStore;
 struct _GtkTreeView;
 struct _GtkTreeViewColumn;
 struct _GtkVBox;
@@ -83,31 +86,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
@@ -166,8 +144,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<Object, _GtkObject *, details::Convert::Explicit>,
@@ -211,9 +189,12 @@ namespace ui {
     public: \
         using self = name *; \
         using native = T *; \
-        explicit name(native h) : super(reinterpret_cast<super::native>(h)) {} \
-        explicit name(Null n) : name((native) nullptr) {} \
+    protected: \
+        explicit name(native h) noexcept : super(reinterpret_cast<super::native>(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 \
     }; \
@@ -284,13 +265,6 @@ namespace ui {
     WRAP(Window, Bin, _GtkWindow, (),
          explicit Window(window_type type);
     ,
-         alert_response alert(
-                 std::string text,
-                 std::string title = "NetRadiant",
-                 alert_type type = alert_type::OK,
-                 alert_icon icon = alert_icon::Default
-         );
-
          Window create_dialog_window(
                  const char *title,
                  void func(),
@@ -337,7 +311,8 @@ namespace ui {
 
     WRAP(ToggleButton, Button, _GtkToggleButton, (),
     ,
-         bool active();
+         bool active() const;
+         void active(bool value);
     );
 
     WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
@@ -439,9 +414,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, (),
@@ -543,6 +533,10 @@ namespace ui {
          void append();
     );
 
+    WRAP(TreeStore, Object, _GtkTreeStore, (ITreeModel),
+    ,
+    );
+
     WRAP(TreeSelection, Object, _GtkTreeSelection, (),
     ,
     );
@@ -563,6 +557,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 = "NetRadiant",
+            alert_type type = alert_type::OK,
+            alert_icon icon = alert_icon::Default
+    );
+
     // callbacks
 
     namespace {
@@ -572,7 +601,9 @@ namespace ui {
         }
     }
 
+WARNING_SUPPRESS_CLANG(keyword-macro)
 #define this (*static_cast<self>(this))
+WARNING_RESTORE_CLANG(keyword-macro)
 
     template<class Lambda>
     gulong Object::connect(char const *detailed_signal, Lambda &&c_handler, void *data)
@@ -592,7 +623,7 @@ namespace ui {
         GtkCallback cb = [](_GtkWidget *widget, void *data) -> void {
             using Function = typename std::decay<Lambda>::type;
             Function *f = static_cast<Function *>(data);
-            (*f)(Widget(widget));
+            (*f)(Widget::from(widget));
         };
         gtk_container_foreach(this, cb, &lambda);
     }