ui/gtk/display.c

branch
newapi
changeset 261
b39f0e61fd99
parent 174
0358f1d9c506
child 262
81778b9589d0
equal deleted inserted replaced
260:eebb0626d020 261:b39f0e61fd99
31 31
32 #include "display.h" 32 #include "display.h"
33 #include "container.h" 33 #include "container.h"
34 #include "../common/context.h" 34 #include "../common/context.h"
35 #include "../common/object.h" 35 #include "../common/object.h"
36 #include "../ui/display.h"
36 37
37 static void set_alignment(GtkWidget *widget, float xalign, float yalign) { 38 static void set_alignment(GtkWidget *widget, float xalign, float yalign) {
38 #if GTK_MAJOR_VERSION >= 3 && GTK_MINOR_VERSION >= 16 39 #if GTK_MAJOR_VERSION >= 3 && GTK_MINOR_VERSION >= 16
39 gtk_label_set_xalign(GTK_LABEL(widget), xalign); 40 gtk_label_set_xalign(GTK_LABEL(widget), xalign);
40 gtk_label_set_yalign(GTK_LABEL(widget), yalign); 41 gtk_label_set_yalign(GTK_LABEL(widget), yalign);
41 #else 42 #else
42 gtk_misc_set_alignment(GTK_MISC(widget), xalign, yalign); 43 gtk_misc_set_alignment(GTK_MISC(widget), xalign, yalign);
43 #endif 44 #endif
44 } 45 }
45 46
46 UIWIDGET ui_label(UiObject *obj, char *label) { 47 UIWIDGET ui_label_create(UiObject *obj, UiLabelArgs args) {
47 GtkWidget *widget = gtk_label_new(label); 48 UiObject* current = uic_current_obj(obj);
48 49
49 UiContainer *ct = uic_get_current_container(obj); 50 GtkWidget *widget = gtk_label_new(args.label);
50 ct->add(ct, widget, FALSE); 51 switch(args.align) {
52 case UI_ALIGN_DEFAULT: break;
53 case UI_ALIGN_LEFT: set_alignment(widget, 0, .5); break;
54 case UI_ALIGN_RIGHT: set_alignment(widget, 1, .5); break;
55 case UI_ALIGN_CENTER: break; // TODO
56 }
57
58 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING);
59 if(var) {
60 UiString* value = (UiString*)var->value;
61 value->obj = widget;
62 value->get = ui_label_get;
63 value->set = ui_label_set;
64 }
65
66 UI_APPLY_LAYOUT1(current, args);
67 current->container->add(current->container, widget, FALSE);
51 68
52 return widget; 69 return widget;
53 } 70 }
54 71
55 UIWIDGET ui_llabel(UiObject *obj, char *label) { 72 UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs args) {
56 UIWIDGET widget = ui_label(obj, label); 73 args.align = UI_ALIGN_LEFT;
57 set_alignment(widget, 0, .5); 74 return ui_label_create(obj, args);
58 return widget;
59 } 75 }
60 76
61 UIWIDGET ui_rlabel(UiObject *obj, char *label) { 77 UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs args) {
62 UIWIDGET widget = ui_label(obj, label); 78 args.align = UI_ALIGN_RIGHT;
63 //gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_RIGHT); 79 return ui_label_create(obj, args);
64
65 set_alignment(widget, 1, .5);
66 return widget;
67 } 80 }
68 81
69 UIWIDGET ui_space(UiObject *obj) { 82 char* ui_label_get(UiString *s) {
83 if(s->value.ptr) {
84 s->value.free(s->value.ptr);
85 }
86 s->value.ptr = g_strdup(gtk_label_get_text(GTK_LABEL(s->obj)));
87 s->value.free = (ui_freefunc)g_free;
88 return s->value.ptr;
89 }
90
91 void ui_label_set(UiString *s, const char *value) {
92 gtk_label_set_text(GTK_LABEL(s->obj), value);
93 if(s->value.ptr) {
94 s->value.free(s->value.ptr);
95 s->value.ptr = NULL;
96 s->value.free = NULL;
97 }
98 }
99
100 UIWIDGET ui_space_deprecated(UiObject *obj) {
70 GtkWidget *widget = gtk_label_new(""); 101 GtkWidget *widget = gtk_label_new("");
71 UiContainer *ct = uic_get_current_container(obj); 102 UiContainer *ct = uic_get_current_container(obj);
72 ct->add(ct, widget, TRUE); 103 ct->add(ct, widget, TRUE);
73 104
74 return widget; 105 return widget;
86 return widget; 117 return widget;
87 } 118 }
88 119
89 /* ------------------------- progress bar ------------------------- */ 120 /* ------------------------- progress bar ------------------------- */
90 121
91 UIWIDGET ui_progressbar(UiObject *obj, UiDouble *value) { 122 UIWIDGET ui_progressbar_deprecated(UiObject *obj, UiDouble *value) {
92 UiVar *var = malloc(sizeof(UiVar)); 123 UiVar *var = malloc(sizeof(UiVar));
93 var->value = value; 124 var->value = value;
94 var->type = UI_VAR_SPECIAL; 125 var->type = UI_VAR_SPECIAL;
95 return ui_progressbar_var(obj, var); 126 return ui_progressbar_var(obj, var);
96 } 127 }

mercurial