ui/gtk/container.c

changeset 65
4697592e24ba
parent 62
70d2aee84432
child 66
8d490d97aab8
equal deleted inserted replaced
64:6ef2c7f73a30 65:4697592e24ba
103 gtk_box_pack_start(GTK_BOX(ct->widget), widget, expand, fill, 0); 103 gtk_box_pack_start(GTK_BOX(ct->widget), widget, expand, fill, 0);
104 104
105 ui_reset_layout(ct->layout); 105 ui_reset_layout(ct->layout);
106 } 106 }
107 107
108 UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid) {
109 UiGridContainer *ct = ucx_mempool_calloc(
110 obj->ctx->mempool,
111 1,
112 sizeof(UiGridContainer));
113 ct->container.widget = grid;
114 ct->container.add = ui_grid_container_add;
115 return (UiContainer*)ct;
116 }
117
118 void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
119 UiGridContainer *grid = (UiGridContainer*)ct;
120
121 if(ct->layout.newline) {
122 grid->x = 0;
123 grid->y++;
124 ct->layout.newline = FALSE;
125 }
126
127 gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, 1, 1);
128 grid->x++;
129
130 ui_reset_layout(ct->layout);
131 }
132
133 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) {
134 UiTabViewContainer *ct = ucx_mempool_calloc(
135 obj->ctx->mempool,
136 1,
137 sizeof(UiTabViewContainer));
138 ct->container.widget = tabview;
139 ct->container.add = ui_tabview_container_add;
140 return (UiContainer*)ct;
141 }
142
143 void ui_tabview_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
144 gtk_notebook_append_page(
145 GTK_NOTEBOOK(ct->widget),
146 widget,
147 gtk_label_new(ct->layout.label));
148 }
149
150
108 UIWIDGET ui_vbox(UiObject *obj) { 151 UIWIDGET ui_vbox(UiObject *obj) {
109 UiContainer *ct = uic_get_current_container(obj); 152 UiContainer *ct = uic_get_current_container(obj);
110 153
111 GtkWidget *vbox = ui_gtk_vbox_new(); 154 GtkWidget *vbox = ui_gtk_vbox_new();
112 ct->add(ct, vbox, TRUE); 155 ct->add(ct, vbox, TRUE);
127 UiObject *newobj = uic_object_new(obj, hbox); 170 UiObject *newobj = uic_object_new(obj, hbox);
128 newobj->container = ui_box_container(obj, hbox); 171 newobj->container = ui_box_container(obj, hbox);
129 uic_obj_add(obj, newobj); 172 uic_obj_add(obj, newobj);
130 173
131 return hbox; 174 return hbox;
175 }
176
177 UIWIDGET ui_grid(UiObject *obj) {
178 UiContainer *ct = uic_get_current_container(obj);
179
180 GtkWidget *grid = gtk_grid_new();
181 ct->add(ct, grid, TRUE);
182
183 UiObject *newobj = uic_object_new(obj, grid);
184 newobj->container = ui_grid_container(obj, grid);
185 uic_obj_add(obj, newobj);
186
187 return grid;
188 }
189
190 UIWIDGET ui_tabview(UiObject *obj) {
191 GtkWidget *tabview = gtk_notebook_new();
192 gtk_notebook_set_show_border(GTK_NOTEBOOK(tabview), FALSE);
193 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(tabview), FALSE);
194
195 UiContainer *ct = uic_get_current_container(obj);
196 ct->add(ct, tabview, TRUE);
197
198 UiObject *tabviewobj = uic_object_new(obj, tabview);
199 tabviewobj->container = ui_tabview_container(obj, tabview);
200 uic_obj_add(obj, tabviewobj);
201
202 return tabview;
203 }
204
205 void ui_tab(UiObject *obj, char *title) {
206 UiContainer *ct = uic_get_current_container(obj);
207 ct->layout.label = title;
208 ui_vbox(obj);
209 }
210
211 void ui_select_tab(UIWIDGET tabview, int tab) {
212 gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab);
132 } 213 }
133 214
134 215
135 /* -------------------- Sidebar -------------------- */ 216 /* -------------------- Sidebar -------------------- */
136 UIWIDGET ui_sidebar(UiObject *obj) { 217 UIWIDGET ui_sidebar(UiObject *obj) {
254 335
255 void ui_layout_fill(UiObject *obj, UiBool fill) { 336 void ui_layout_fill(UiObject *obj, UiBool fill) {
256 UiContainer *ct = uic_get_current_container(obj); 337 UiContainer *ct = uic_get_current_container(obj);
257 ct->layout.fill = ui_bool2lb(fill); 338 ct->layout.fill = ui_bool2lb(fill);
258 } 339 }
340
341 void ui_newline(UiObject *obj) {
342 UiContainer *ct = uic_get_current_container(obj);
343 ct->layout.newline = TRUE;
344 }

mercurial