]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.h
Remove <gtk/gtk.h> from gtkutil/container.h
[xonotic/netradiant.git] / libs / uilib / uilib.h
index 945f762e76af310f9171f39fbfb83c3007e00d9d..6ebb6420deda599407c771f2d83bb282d5274bdc 100644 (file)
@@ -223,6 +223,11 @@ namespace ui {
     WRAP(Container, Widget, _GtkContainer, (),
     ,
          void add(Widget widget);
+
+         void remove(Widget widget);
+
+         template<class Lambda>
+         void foreach(Lambda &&lambda);
     );
 
     WRAP(Bin, Container, _GtkBin, (),
@@ -497,6 +502,30 @@ namespace ui {
 
 #undef WRAP
 
+    // callbacks
+
+    namespace {
+        using GtkCallback = void (*)(_GtkWidget *, void *);
+        extern "C" {
+        void gtk_container_foreach(_GtkContainer *, GtkCallback, void *);
+        }
+    }
+
+#define this (*static_cast<self>(this))
+
+    template<class Lambda>
+    void IContainer::foreach(Lambda &&lambda)
+    {
+        GtkCallback cb = [](_GtkWidget *widget, void *data) -> void {
+            using Function = typename std::decay<Lambda>::type;
+            Function *f = static_cast<Function *>(data);
+            (*f)(Widget(widget));
+        };
+        gtk_container_foreach(this, cb, &lambda);
+    }
+
+#undef this
+
 }
 
 #endif