|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2017 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef UI_CONTAINER_H |
|
30 #define UI_CONTAINER_H |
|
31 |
|
32 #include "toolkit.h" |
|
33 |
|
34 #ifdef __cplusplus |
|
35 extern "C" { |
|
36 #endif |
|
37 |
|
38 typedef enum UiSubContainerType { |
|
39 UI_CONTAINER_VBOX = 0, |
|
40 UI_CONTAINER_HBOX, |
|
41 UI_CONTAINER_GRID |
|
42 } UiSubContainerType; |
|
43 |
|
44 typedef enum UiTabViewType { |
|
45 UI_TABVIEW_DEFAULT = 0, |
|
46 UI_TABVIEW_DOC, |
|
47 UI_TABVIEW_NAVIGATION_SIDE, |
|
48 UI_TABVIEW_NAVIGATION_TOP, |
|
49 UI_TABVIEW_NAVIGATION_TOP2, |
|
50 UI_TABVIEW_INVISIBLE |
|
51 } UiTabViewType; |
|
52 |
|
53 typedef struct UiContainerArgs { |
|
54 UiTri fill; |
|
55 UiBool hexpand; |
|
56 UiBool vexpand; |
|
57 int colspan; |
|
58 int rowspan; |
|
59 |
|
60 int margin; |
|
61 int spacing; |
|
62 int columnspacing; |
|
63 int rowspacing; |
|
64 } UiContainerArgs; |
|
65 |
|
66 typedef struct UiFrameArgs { |
|
67 UiTri fill; |
|
68 UiBool hexpand; |
|
69 UiBool vexpand; |
|
70 int colspan; |
|
71 int rowspan; |
|
72 |
|
73 UiSubContainerType subcontainer; |
|
74 |
|
75 int margin; |
|
76 int spacing; |
|
77 int columnspacing; |
|
78 int rowspacing; |
|
79 |
|
80 const char* label; |
|
81 UiBool isexpanded; |
|
82 } UiFrameArgs; |
|
83 |
|
84 typedef struct UiTabViewArgs { |
|
85 UiTri fill; |
|
86 UiBool hexpand; |
|
87 UiBool vexpand; |
|
88 int colspan; |
|
89 int rowspan; |
|
90 |
|
91 UiTabViewType tabview; |
|
92 |
|
93 UiSubContainerType subcontainer; |
|
94 |
|
95 int margin; |
|
96 int spacing; |
|
97 int columnspacing; |
|
98 int rowspacing; |
|
99 |
|
100 const char* label; |
|
101 UiBool isexpanded; |
|
102 } UiTabViewArgs; |
|
103 |
|
104 |
|
105 |
|
106 #define UI_CTN(obj, ctn) for(ctn;ui_container_finish(obj);ui_container_begin_close(obj)) |
|
107 |
|
108 #define ui_vbox(obj, ...) for(ui_vbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
109 #define ui_hbox(obj, ...) for(ui_hbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
110 #define ui_grid(obj, ...) for(ui_grid_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
111 #define ui_frame(obj, ...) for(ui_frame_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
112 #define ui_expander(obj, ...) for(ui_expander_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
113 #define ui_scrolledwindow(obj, ...) for(ui_scrolledwindow_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
114 #define ui_tabview(obj, ...) for(ui_tabview_create(obj, (UiTabViewArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
115 |
|
116 #define ui_vbox0(obj) for(ui_vbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
117 #define ui_hbox0(obj) for(ui_hbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
118 #define ui_grid0(obj) for(ui_grid_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
119 #define ui_frame0(obj) for(ui_frame_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
120 #define ui_expander0(obj) for(ui_expande_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
121 #define ui_scrolledwindow0(obj) for(ui_scrolledwindow_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
122 #define ui_tabview0(obj) for(ui_tabview_create(obj, (UiTabViewArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) |
|
123 |
|
124 #define ui_tab(obj, label) for(ui_tab_create(obj, label);ui_container_finish(obj);ui_container_begin_close(obj)) |
|
125 |
|
126 UIEXPORT void ui_end(UiObject *obj); |
|
127 |
|
128 UIEXPORT UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args); |
|
129 UIEXPORT UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args); |
|
130 UIEXPORT UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args); |
|
131 UIEXPORT UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args); |
|
132 UIEXPORT UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args); |
|
133 UIEXPORT UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args); |
|
134 UIEXPORT UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args); |
|
135 |
|
136 UIEXPORT void ui_tab_create(UiObject* obj, const char* title); |
|
137 |
|
138 UIEXPORT UIWIDGET ui_scrolledwindow_deprecated(UiObject *obj); |
|
139 |
|
140 UIEXPORT UIWIDGET ui_sidebar(UiObject *obj); |
|
141 |
|
142 UIEXPORT UIWIDGET ui_hsplitpane(UiObject *obj, int max); |
|
143 UIEXPORT UIWIDGET ui_vsplitpane(UiObject *obj, int max); |
|
144 |
|
145 UIEXPORT UIWIDGET ui_tabview_deprecated(UiObject *obj); |
|
146 |
|
147 UIEXPORT void ui_select_tab(UIWIDGET tabview, int tab); |
|
148 |
|
149 // box container layout functions |
|
150 UIEXPORT void ui_layout_fill(UiObject *obj, UiBool fill); |
|
151 // grid container layout functions |
|
152 UIEXPORT void ui_layout_hexpand(UiObject *obj, UiBool expand); |
|
153 UIEXPORT void ui_layout_vexpand(UiObject *obj, UiBool expand); |
|
154 UIEXPORT void ui_layout_width(UiObject *obj, int width); |
|
155 UIEXPORT void ui_layout_height(UiObject* obj, int width); |
|
156 UIEXPORT void ui_layout_colspan(UiObject *obj, int cols); |
|
157 UIEXPORT void ui_layout_rowspan(UiObject* obj, int rows); |
|
158 UIEXPORT void ui_newline(UiObject *obj); |
|
159 |
|
160 |
|
161 UIEXPORT UiTabbedPane* ui_tabbed_document_view(UiObject *obj); |
|
162 |
|
163 UIEXPORT UiObject* ui_document_tab(UiTabbedPane *view); |
|
164 |
|
165 |
|
166 /* used for macro */ |
|
167 UIEXPORT void ui_container_begin_close(UiObject *obj); |
|
168 UIEXPORT int ui_container_finish(UiObject *obj); |
|
169 |
|
170 #define UI_APPLY_LAYOUT1(obj, args) \ |
|
171 if(args.fill != UI_DEFAULT) ui_layout_fill(obj, args.fill == UI_ON ? 1 : 0 ); \ |
|
172 if(args.hexpand) ui_layout_hexpand(obj, 1); \ |
|
173 if(args.vexpand) ui_layout_vexpand(obj, 1); \ |
|
174 if(args.colspan > 0) ui_layout_colspan(obj, args.colspan); \ |
|
175 if(args.rowspan > 0) ui_layout_rowspan(obj, args.rowspan); \ |
|
176 /*force caller to add ';'*/(void)0 |
|
177 |
|
178 |
|
179 #ifdef __cplusplus |
|
180 } |
|
181 #endif |
|
182 |
|
183 #endif /* UI_CONTAINER_H */ |
|
184 |