ui/ui/container.h

Mon, 02 Oct 2023 10:10:09 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 02 Oct 2023 10:10:09 +0200
branch
newapi
changeset 195
0f2e69873875
parent 194
e2281ace0769
child 198
f2332d0d3318
permissions
-rw-r--r--

add expander (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 enum UiSubContainerType {
    UI_CONTAINER_VBOX = 0,
    UI_CONTAINER_HBOX,
    UI_CONTAINER_GRID
} UiSubContainerType;

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;


#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_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))

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_frame_create(UiObject* obj, UiFrameArgs args);
UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args);
UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args);


UIWIDGET ui_scrolledwindow_deprecated(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 */

mercurial