]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.h
bikeshedding: some wording
[xonotic/netradiant.git] / libs / uilib / uilib.h
index 1b082456d4259b2e494f9fe0bb91fcdd5020f2bc..e6c5ff6a91d68b8fbc583123590d5391ea7650d0 100644 (file)
@@ -84,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
@@ -167,8 +142,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>,
@@ -212,9 +187,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 \
     }; \
@@ -285,13 +263,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(),
@@ -338,7 +309,8 @@ namespace ui {
 
     WRAP(ToggleButton, Button, _GtkToggleButton, (),
     ,
-         bool active();
+         bool active() const;
+         void active(bool value);
     );
 
     WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
@@ -583,6 +555,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 {
@@ -612,7 +619,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);
     }