ui/common/container.c

changeset 112
c3f2f16fa4b8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/common/container.c	Sun Oct 19 21:20:08 2025 +0200
@@ -0,0 +1,87 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "container.h"
+#include "object.h"
+
+void ui_end_new(UiObject *obj) {
+    if(!obj->container_end) {
+        return;
+    }
+    UiContainerX *rm = obj->container_end;
+    uic_object_pop_container(obj);
+    ui_free(obj->ctx, rm);
+}
+
+void ui_newline(UiObject *obj) {
+    UiContainerX *container = obj->container_end;
+    if(container) {
+        container->newline = TRUE;
+    }
+}
+
+void uic_layout_setup_expand_fill(
+        UiLayout *layout,
+        UiBool def_hexpand,
+        UiBool def_vexpand,
+        UiBool def_hfill,
+        UiBool def_vfill)
+{
+    if(layout->fill) {
+        layout->hfill = TRUE;
+        layout->vfill = TRUE;
+        layout->hexpand = TRUE;
+        layout->vexpand = TRUE;
+        return;
+    }
+    
+    if(!layout->override_defaults) {
+        if(def_hexpand) {
+            layout->hexpand = TRUE;
+        }
+        if(def_hfill) {
+            layout->hfill = TRUE;
+        }
+        if(def_vexpand) {
+            layout->vexpand = TRUE;
+        }
+        if(def_vfill) {
+            layout->vfill = TRUE;
+        }
+    }
+}
+
+void uic_layout_setup_margin(UiLayout *layout) {
+    int margin = layout->margin;
+    if(margin > 0) {
+        layout->margin_left = margin;
+        layout->margin_right = margin;
+        layout->margin_top = margin;
+        layout->margin_bottom = margin;
+    }
+}

mercurial