Sun, 01 Oct 2023 16:53:02 +0200
implement new api style for box and grid containers (WinUI3)
/* * 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 struct UiContainerArgs { UiTri fill; UiBool hexpand; UiBool vexpand; int colspan; int rowspan; int margin; int spacing; int columnspacing; int rowspacing; } UiContainerArgs; #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)) void ui_end(UiObject *obj); UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args); UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args); UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args); UIWIDGET ui_scrolledwindow(UiObject *obj); UIWIDGET ui_sidebar(UiObject *obj); UIWIDGET ui_hsplitpane(UiObject *obj, int max); UIWIDGET ui_vsplitpane(UiObject *obj, int max); UIWIDGET ui_tabview(UiObject *obj); void ui_tab(UiObject *obj, char *title); void ui_select_tab(UIWIDGET tabview, int tab); // box container layout functions void ui_layout_fill(UiObject *obj, UiBool fill); // grid container layout functions void ui_layout_hexpand(UiObject *obj, UiBool expand); void ui_layout_vexpand(UiObject *obj, UiBool expand); void ui_layout_width(UiObject *obj, int width); void ui_layout_height(UiObject* obj, int width); void ui_layout_colspan(UiObject *obj, int cols); void ui_layout_rowspan(UiObject* obj, int rows); void ui_newline(UiObject *obj); UiTabbedPane* ui_tabbed_document_view(UiObject *obj); UiObject* ui_document_tab(UiTabbedPane *view); /* used for macro */ void ui_container_begin_close(UiObject *obj); 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 */