31 |
31 |
32 #include "container.h" |
32 #include "container.h" |
33 #include "../common/context.h" |
33 #include "../common/context.h" |
34 #include "../common/object.h" |
34 #include "../common/object.h" |
35 |
35 |
36 GtkWidget* ui_gtk_vbox_new() { |
36 GtkWidget* ui_gtk_vbox_new(int spacing) { |
37 #ifdef UI_GTK3 |
37 #ifdef UI_GTK3 |
38 return gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
38 return gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing); |
39 #else |
39 #else |
40 return gtk_vbox_new(FALSE, 0); |
40 return gtk_vbox_new(FALSE, spacing); |
41 #endif |
41 #endif |
42 } |
42 } |
43 |
43 |
44 GtkWidget* ui_gtk_hbox_new() { |
44 GtkWidget* ui_gtk_hbox_new(int spacing) { |
45 #ifdef UI_GTK3 |
45 #ifdef UI_GTK3 |
46 return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
46 return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, spacing); |
47 #else |
47 #else |
48 return gtk_hbox_new(FALSE, 0); |
48 return gtk_hbox_new(FALSE, spacing); |
49 #endif |
49 #endif |
50 } |
50 } |
51 |
51 |
52 /* -------------------- Frame Container (deprecated) -------------------- */ |
52 /* -------------------- Frame Container (deprecated) -------------------- */ |
53 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) { |
53 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) { |
201 ct->current = widget; |
201 ct->current = widget; |
202 } |
202 } |
203 |
203 |
204 |
204 |
205 UIWIDGET ui_vbox(UiObject *obj) { |
205 UIWIDGET ui_vbox(UiObject *obj) { |
206 UiContainer *ct = uic_get_current_container(obj); |
206 return ui_vbox_sp(obj, 0, 0); |
207 |
207 } |
208 GtkWidget *vbox = ui_gtk_vbox_new(); |
208 |
209 ct->add(ct, vbox, TRUE); |
209 UIWIDGET ui_hbox(UiObject *obj) { |
|
210 return ui_hbox_sp(obj, 0, 0); |
|
211 } |
|
212 |
|
213 static GtkWidget* box_set_margin(GtkWidget *box, int margin) { |
|
214 GtkWidget *ret = box; |
|
215 #ifdef UI_GTK3 |
|
216 #if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 12 |
|
217 gtk_widget_set_margin_start(box, margin); |
|
218 gtk_widget_set_margin_end(box, margin); |
|
219 #else |
|
220 gtk_widget_set_margin_left(box, margin); |
|
221 gtk_widget_set_margin_right(box, margin); |
|
222 #endif |
|
223 gtk_widget_set_margin_top(box, margin); |
|
224 gtk_widget_set_margin_bottom(box, margin); |
|
225 #elif defined(UI_GTK2) |
|
226 GtkWidget *a = gtk_alignment_new(0.5, 0.5, 1, 1); |
|
227 gtk_alignment_set_padding(GTK_ALIGNMENT(a), margin, margin, margin, margin); |
|
228 gtk_container_add(GTK_CONTAINER(a), box); |
|
229 ret = a; |
|
230 #endif |
|
231 return ret; |
|
232 } |
|
233 |
|
234 UIWIDGET ui_vbox_sp(UiObject *obj, int margin, int spacing) { |
|
235 UiContainer *ct = uic_get_current_container(obj); |
|
236 |
|
237 GtkWidget *vbox = ui_gtk_vbox_new(spacing); |
|
238 GtkWidget *widget = margin > 0 ? box_set_margin(vbox, margin) : vbox; |
|
239 ct->add(ct, widget, TRUE); |
210 |
240 |
211 UiObject *newobj = uic_object_new(obj, vbox); |
241 UiObject *newobj = uic_object_new(obj, vbox); |
212 newobj->container = ui_box_container(obj, vbox); |
242 newobj->container = ui_box_container(obj, vbox); |
213 uic_obj_add(obj, newobj); |
243 uic_obj_add(obj, newobj); |
214 |
244 |
215 return vbox; |
245 return widget; |
216 } |
246 } |
217 |
247 |
218 UIWIDGET ui_hbox(UiObject *obj) { |
248 UIWIDGET ui_hbox_sp(UiObject *obj, int margin, int spacing) { |
219 UiContainer *ct = uic_get_current_container(obj); |
249 UiContainer *ct = uic_get_current_container(obj); |
220 |
250 |
221 GtkWidget *hbox = ui_gtk_hbox_new(); |
251 GtkWidget *hbox = ui_gtk_hbox_new(spacing); |
222 ct->add(ct, hbox, TRUE); |
252 GtkWidget *widget = margin > 0 ? box_set_margin(hbox, margin) : hbox; |
|
253 ct->add(ct, widget, TRUE); |
223 |
254 |
224 UiObject *newobj = uic_object_new(obj, hbox); |
255 UiObject *newobj = uic_object_new(obj, hbox); |
225 newobj->container = ui_box_container(obj, hbox); |
256 newobj->container = ui_box_container(obj, hbox); |
226 uic_obj_add(obj, newobj); |
257 uic_obj_add(obj, newobj); |
227 |
258 |
228 return hbox; |
259 return widget; |
229 } |
260 } |
230 |
261 |
231 UIWIDGET ui_grid(UiObject *obj) { |
262 UIWIDGET ui_grid(UiObject *obj) { |
232 return ui_grid_sp(obj, 0, 0, 0); |
263 return ui_grid_sp(obj, 0, 0, 0); |
233 } |
264 } |
308 #else |
339 #else |
309 GtkWidget *paned = gtk_hpaned_new(); |
340 GtkWidget *paned = gtk_hpaned_new(); |
310 #endif |
341 #endif |
311 gtk_paned_set_position(GTK_PANED(paned), 200); |
342 gtk_paned_set_position(GTK_PANED(paned), 200); |
312 |
343 |
313 GtkWidget *sidebar = ui_gtk_vbox_new(); |
344 GtkWidget *sidebar = ui_gtk_vbox_new(0); |
314 gtk_paned_pack1(GTK_PANED(paned), sidebar, TRUE, FALSE); |
345 gtk_paned_pack1(GTK_PANED(paned), sidebar, TRUE, FALSE); |
315 |
346 |
316 UiObject *left = uic_object_new(obj, sidebar); |
347 UiObject *left = uic_object_new(obj, sidebar); |
317 UiContainer *ct1 = ui_box_container(obj, sidebar); |
348 UiContainer *ct1 = ui_box_container(obj, sidebar); |
318 left->container = ct1; |
349 left->container = ct1; |