ui/gtk/display.c

changeset 108
77254bd6dccb
parent 60
ee4e4742391e
child 109
c3dfcb8f0be7
equal deleted inserted replaced
107:b34bd1557c6c 108:77254bd6dccb
44 #else 44 #else
45 gtk_misc_set_alignment(GTK_MISC(widget), xalign, yalign); 45 gtk_misc_set_alignment(GTK_MISC(widget), xalign, yalign);
46 #endif 46 #endif
47 } 47 }
48 48
49 UIWIDGET ui_label_create(UiObject *obj, UiLabelArgs args) { 49 UIWIDGET ui_label_create(UiObject *obj, UiLabelArgs *args) {
50 UiObject* current = uic_current_obj(obj); 50 UiObject* current = uic_current_obj(obj);
51 51
52 const char *css_class = NULL; 52 const char *css_class = NULL;
53 char *markup = NULL; 53 char *markup = NULL;
54 if(args.label) { 54 if(args->label) {
55 #if GTK_MAJOR_VERSION < 3 55 #if GTK_MAJOR_VERSION < 3
56 switch(args.style) { 56 switch(args->style) {
57 case UI_LABEL_STYLE_DEFAULT: break; 57 case UI_LABEL_STYLE_DEFAULT: break;
58 case UI_LABEL_STYLE_TITLE: { 58 case UI_LABEL_STYLE_TITLE: {
59 cxmutstr m = cx_asprintf("<b>%s</b>", args.label); 59 cxmutstr m = cx_asprintf("<b>%s</b>", args->label);
60 markup = m.ptr; 60 markup = m.ptr;
61 args.label = NULL; 61 args->label = NULL;
62 } 62 }
63 case UI_LABEL_STYLE_SUBTITLE: { 63 case UI_LABEL_STYLE_SUBTITLE: {
64 break; 64 break;
65 } 65 }
66 case UI_LABEL_STYLE_DIM: { 66 case UI_LABEL_STYLE_DIM: {
67 break; 67 break;
68 } 68 }
69 } 69 }
70 # else 70 # else
71 switch(args.style) { 71 switch(args->style) {
72 case UI_LABEL_STYLE_DEFAULT: break; 72 case UI_LABEL_STYLE_DEFAULT: break;
73 case UI_LABEL_STYLE_TITLE: { 73 case UI_LABEL_STYLE_TITLE: {
74 css_class = "ui_label_title"; 74 css_class = "ui_label_title";
75 break; 75 break;
76 } 76 }
85 } 85 }
86 # endif 86 # endif
87 } 87 }
88 88
89 89
90 GtkWidget *widget = gtk_label_new(args.label); 90 GtkWidget *widget = gtk_label_new(args->label);
91 if(markup) { 91 if(markup) {
92 gtk_label_set_markup(GTK_LABEL(widget), markup); 92 gtk_label_set_markup(GTK_LABEL(widget), markup);
93 free(markup); 93 free(markup);
94 } 94 }
95 95
96 if(css_class) { 96 if(css_class) {
97 WIDGET_ADD_CSS_CLASS(widget, css_class); 97 WIDGET_ADD_CSS_CLASS(widget, css_class);
98 } 98 }
99 99
100 switch(args.align) { 100 switch(args->align) {
101 case UI_ALIGN_DEFAULT: break; 101 case UI_ALIGN_DEFAULT: break;
102 case UI_ALIGN_LEFT: set_alignment(widget, 0, .5); break; 102 case UI_ALIGN_LEFT: set_alignment(widget, 0, .5); break;
103 case UI_ALIGN_RIGHT: set_alignment(widget, 1, .5); break; 103 case UI_ALIGN_RIGHT: set_alignment(widget, 1, .5); break;
104 case UI_ALIGN_CENTER: break; // TODO 104 case UI_ALIGN_CENTER: break; // TODO
105 } 105 }
106 106
107 107
108 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); 108 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_STRING);
109 if(var) { 109 if(var) {
110 UiString* value = (UiString*)var->value; 110 UiString* value = (UiString*)var->value;
111 value->obj = widget; 111 value->obj = widget;
112 value->get = ui_label_get; 112 value->get = ui_label_get;
113 value->set = ui_label_set; 113 value->set = ui_label_set;
114 } 114 }
115 115
116 UI_APPLY_LAYOUT1(current, args); 116 UI_APPLY_LAYOUT2(current, args);
117 current->container->add(current->container, widget, FALSE); 117 current->container->add(current->container, widget);
118 118
119 return widget; 119 return widget;
120 } 120 }
121 121
122 UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs args) { 122 UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs *args) {
123 args.align = UI_ALIGN_LEFT; 123 args->align = UI_ALIGN_LEFT;
124 return ui_label_create(obj, args); 124 return ui_label_create(obj, args);
125 } 125 }
126 126
127 UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs args) { 127 UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs *args) {
128 args.align = UI_ALIGN_RIGHT; 128 args->align = UI_ALIGN_RIGHT;
129 return ui_label_create(obj, args); 129 return ui_label_create(obj, args);
130 } 130 }
131 131
132 char* ui_label_get(UiString *s) { 132 char* ui_label_get(UiString *s) {
133 if(s->value.ptr) { 133 if(s->value.ptr) {
148 } 148 }
149 149
150 UIWIDGET ui_space_deprecated(UiObject *obj) { 150 UIWIDGET ui_space_deprecated(UiObject *obj) {
151 GtkWidget *widget = gtk_label_new(""); 151 GtkWidget *widget = gtk_label_new("");
152 UiContainer *ct = uic_get_current_container(obj); 152 UiContainer *ct = uic_get_current_container(obj);
153 ct->add(ct, widget, TRUE); 153 ct->add(ct, widget);
154 154
155 return widget; 155 return widget;
156 } 156 }
157 157
158 UIWIDGET ui_separator_deprecated(UiObject *obj) { 158 UIWIDGET ui_separator_deprecated(UiObject *obj) {
160 GtkWidget *widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); 160 GtkWidget *widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
161 #else 161 #else
162 GtkWidget *widget = gtk_hseparator_new(); 162 GtkWidget *widget = gtk_hseparator_new();
163 #endif 163 #endif
164 UiContainer *ct = uic_get_current_container(obj); 164 UiContainer *ct = uic_get_current_container(obj);
165 ct->add(ct, widget, FALSE); 165 ct->add(ct, widget);
166 166
167 return widget; 167 return widget;
168 } 168 }
169 169
170 /* ------------------------- progress bar ------------------------- */ 170 /* ------------------------- progress bar ------------------------- */
172 typedef struct UiProgressBarRange { 172 typedef struct UiProgressBarRange {
173 double min; 173 double min;
174 double max; 174 double max;
175 } UiProgressBarRange; 175 } UiProgressBarRange;
176 176
177 UIWIDGET ui_progressbar_create(UiObject *obj, UiProgressbarArgs args) { 177 UIWIDGET ui_progressbar_create(UiObject *obj, UiProgressbarArgs *args) {
178 UiObject* current = uic_current_obj(obj); 178 UiObject* current = uic_current_obj(obj);
179 179
180 GtkWidget *progressbar = gtk_progress_bar_new(); 180 GtkWidget *progressbar = gtk_progress_bar_new();
181 if(args.max > args.min) { 181 if(args->max > args->min) {
182 UiProgressBarRange *range = malloc(sizeof(UiProgressBarRange)); 182 UiProgressBarRange *range = malloc(sizeof(UiProgressBarRange));
183 range->min = args.min; 183 range->min = args->min;
184 range->max = args.max; 184 range->max = args->max;
185 g_signal_connect( 185 g_signal_connect(
186 progressbar, 186 progressbar,
187 "destroy", 187 "destroy",
188 G_CALLBACK(ui_destroy_userdata), 188 G_CALLBACK(ui_destroy_userdata),
189 range); 189 range);
190 g_object_set_data(G_OBJECT(progressbar), "ui_range", range); 190 g_object_set_data(G_OBJECT(progressbar), "ui_range", range);
191 } 191 }
192 192
193 193
194 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_DOUBLE); 194 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_DOUBLE);
195 if(var && var->value) { 195 if(var && var->value) {
196 UiDouble *value = var->value; 196 UiDouble *value = var->value;
197 value->get = ui_progressbar_get; 197 value->get = ui_progressbar_get;
198 value->set = ui_progressbar_set; 198 value->set = ui_progressbar_set;
199 value->obj = progressbar; 199 value->obj = progressbar;
200 ui_progressbar_set(value, value->value); 200 ui_progressbar_set(value, value->value);
201 } 201 }
202 202
203 UI_APPLY_LAYOUT1(current, args); 203 UI_APPLY_LAYOUT2(current, args);
204 current->container->add(current->container, progressbar, FALSE); 204 current->container->add(current->container, progressbar);
205 205
206 return progressbar; 206 return progressbar;
207 } 207 }
208 208
209 double ui_progressbar_get(UiDouble *d) { 209 double ui_progressbar_get(UiDouble *d) {
226 } 226 }
227 227
228 228
229 /* ------------------------- progress spinner ------------------------- */ 229 /* ------------------------- progress spinner ------------------------- */
230 230
231 UIWIDGET ui_progressspinner_create(UiObject* obj, UiProgressbarSpinnerArgs args) { 231 UIWIDGET ui_progressspinner_create(UiObject* obj, UiProgressbarSpinnerArgs *args) {
232 UiObject* current = uic_current_obj(obj); 232 UiObject* current = uic_current_obj(obj);
233 233
234 GtkWidget *spinner = gtk_spinner_new(); 234 GtkWidget *spinner = gtk_spinner_new();
235 235
236 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); 236 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_INTEGER);
237 if(var && var->value) { 237 if(var && var->value) {
238 UiInteger *value = var->value; 238 UiInteger *value = var->value;
239 value->get = ui_spinner_get; 239 value->get = ui_spinner_get;
240 value->set = ui_spinner_set; 240 value->set = ui_spinner_set;
241 value->obj = spinner; 241 value->obj = spinner;
242 ui_spinner_set(value, value->value); 242 ui_spinner_set(value, value->value);
243 } 243 }
244 244
245 UI_APPLY_LAYOUT1(current, args); 245 UI_APPLY_LAYOUT2(current, args);
246 current->container->add(current->container, spinner, FALSE); 246 current->container->add(current->container, spinner);
247 247
248 return spinner; 248 return spinner;
249 } 249 }
250 250
251 int64_t ui_spinner_get(UiInteger *i) { 251 int64_t ui_spinner_get(UiInteger *i) {

mercurial