ui/ui/container.h

changeset 0
2483f517c562
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/ui/container.h	Sun Jan 21 16:30:18 2024 +0100
@@ -0,0 +1,184 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2017 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.
+ */
+
+#ifndef UI_CONTAINER_H
+#define UI_CONTAINER_H
+
+#include "toolkit.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+   
+typedef enum UiSubContainerType {
+    UI_CONTAINER_VBOX = 0,
+    UI_CONTAINER_HBOX,
+    UI_CONTAINER_GRID
+} UiSubContainerType;
+
+typedef enum UiTabViewType {
+    UI_TABVIEW_DEFAULT = 0,
+    UI_TABVIEW_DOC,
+    UI_TABVIEW_NAVIGATION_SIDE,
+    UI_TABVIEW_NAVIGATION_TOP,
+    UI_TABVIEW_NAVIGATION_TOP2,
+    UI_TABVIEW_INVISIBLE
+} UiTabViewType;
+
+typedef struct UiContainerArgs {
+    UiTri fill;
+    UiBool hexpand;
+    UiBool vexpand;
+    int colspan;
+    int rowspan;
+
+    int margin;
+    int spacing;
+    int columnspacing;
+    int rowspacing;
+} UiContainerArgs;
+
+typedef struct UiFrameArgs {
+    UiTri fill;
+    UiBool hexpand;
+    UiBool vexpand;
+    int colspan;
+    int rowspan;
+
+    UiSubContainerType subcontainer;
+
+    int margin;
+    int spacing;
+    int columnspacing;
+    int rowspacing;
+
+    const char* label;
+    UiBool isexpanded;
+} UiFrameArgs;
+
+typedef struct UiTabViewArgs {
+    UiTri fill;
+    UiBool hexpand;
+    UiBool vexpand;
+    int colspan;
+    int rowspan;
+
+    UiTabViewType tabview;
+
+    UiSubContainerType subcontainer;
+
+    int margin;
+    int spacing;
+    int columnspacing;
+    int rowspacing;
+
+    const char* label;
+    UiBool isexpanded;
+} UiTabViewArgs;
+
+
+
+#define UI_CTN(obj, ctn) for(ctn;ui_container_finish(obj);ui_container_begin_close(obj))
+
+#define ui_vbox(obj, ...) for(ui_vbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_hbox(obj, ...) for(ui_hbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_grid(obj, ...) for(ui_grid_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_frame(obj, ...) for(ui_frame_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_expander(obj, ...) for(ui_expander_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_scrolledwindow(obj, ...) for(ui_scrolledwindow_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_tabview(obj, ...) for(ui_tabview_create(obj, (UiTabViewArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+
+#define ui_vbox0(obj) for(ui_vbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_hbox0(obj) for(ui_hbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_grid0(obj) for(ui_grid_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_frame0(obj) for(ui_frame_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_expander0(obj) for(ui_expande_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_scrolledwindow0(obj) for(ui_scrolledwindow_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_tabview0(obj) for(ui_tabview_create(obj, (UiTabViewArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
+
+#define ui_tab(obj, label) for(ui_tab_create(obj, label);ui_container_finish(obj);ui_container_begin_close(obj))
+
+UIEXPORT void ui_end(UiObject *obj);
+    
+UIEXPORT UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args);
+UIEXPORT UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args);
+UIEXPORT UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args);
+UIEXPORT UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args);
+UIEXPORT UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args);
+UIEXPORT UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args);
+UIEXPORT UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args);
+
+UIEXPORT void ui_tab_create(UiObject* obj, const char* title);
+
+UIEXPORT UIWIDGET ui_scrolledwindow_deprecated(UiObject *obj);
+
+UIEXPORT UIWIDGET ui_sidebar(UiObject *obj);
+
+UIEXPORT UIWIDGET ui_hsplitpane(UiObject *obj, int max);
+UIEXPORT UIWIDGET ui_vsplitpane(UiObject *obj, int max);
+
+UIEXPORT UIWIDGET ui_tabview_deprecated(UiObject *obj);
+
+UIEXPORT void ui_select_tab(UIWIDGET tabview, int tab);
+
+// box container layout functions
+UIEXPORT void ui_layout_fill(UiObject *obj, UiBool fill);
+// grid container layout functions
+UIEXPORT void ui_layout_hexpand(UiObject *obj, UiBool expand);
+UIEXPORT void ui_layout_vexpand(UiObject *obj, UiBool expand);
+UIEXPORT void ui_layout_width(UiObject *obj, int width);
+UIEXPORT void ui_layout_height(UiObject* obj, int width);
+UIEXPORT void ui_layout_colspan(UiObject *obj, int cols);
+UIEXPORT void ui_layout_rowspan(UiObject* obj, int rows);
+UIEXPORT void ui_newline(UiObject *obj);
+
+
+UIEXPORT UiTabbedPane* ui_tabbed_document_view(UiObject *obj);
+
+UIEXPORT UiObject* ui_document_tab(UiTabbedPane *view);
+
+
+/* used for macro */
+UIEXPORT void ui_container_begin_close(UiObject *obj);
+UIEXPORT int ui_container_finish(UiObject *obj);
+
+#define UI_APPLY_LAYOUT1(obj, args) \
+    if(args.fill != UI_DEFAULT) ui_layout_fill(obj, args.fill == UI_ON ? 1 : 0 ); \
+    if(args.hexpand) ui_layout_hexpand(obj, 1); \
+    if(args.vexpand) ui_layout_vexpand(obj, 1); \
+    if(args.colspan > 0) ui_layout_colspan(obj, args.colspan); \
+    if(args.rowspan > 0) ui_layout_rowspan(obj, args.rowspan); \
+    /*force caller to add ';'*/(void)0
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UI_CONTAINER_H */
+

mercurial