SDK Multiplataforma en C logo

SDK Multiplataforma en C

¡Hola GUI!

❮ Anterior
Siguiente ❯

GuiHello es una aplicación, que a modo de ejemplo, muestra las características de la librería Gui para la creación de interfaces de usuario. El código fuente está en la caperta /src/howto/guihello de la distribución del SDK.


1. ¡Hola Label!

Captura de controles de interfaz tipo Label.
Figura 1: Controles Label.
Listado 1: howto/guihello/labels.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* Labels basics */
    
#include "labels.h"
#include "guiall.h"

/*---------------------------------------------------------------------------*/

static const char_t *i_LABEL_01 = "Hello.";
static const char_t *i_LABEL_02 = "Hello, I'm a Label.";
static const char_t *i_LABEL_03 = "Hello, I'm a Label, longer than first.";
static const char_t *i_LABEL_04 = "Hello, I'm a Label, longer than first and longer than second.";
static const char_t *i_LABEL_05 = "Hello, I'm a Label, longer than first, longer than second and longer than third.";
static const char_t *i_LABEL_06 = "Hello, I'm a Label, longer than first, longer than second, longer than third and longer than fourth.";
static const char_t *i_LABEL_07 = "Mouse sensitive label";

/*---------------------------------------------------------------------------*/

static void i_OnLayoutWidth(Layout *layout, Event *event)
{
    const EvButton *p = event_params(event, EvButton);
    real32_t width = 0;
    switch (p->index) {
    case 0:
        width = 0;
        break;
    case 1:
        width = 100;
        break;
    case 2:
        width = 200;
        break;
    case 3:
        width = 300;
        break;
    case 4:
        width = 400;
        break;
    cassert_default();
    }

    layout_hsize(layout, 0, width);
    layout_update(layout);
}

/*---------------------------------------------------------------------------*/

static PopUp *i_width_popup(Layout *layout)
{
    PopUp *popup = popup_create();
    popup_add_elem(popup, "Natural", NULL);
    popup_add_elem(popup, "100px", NULL);
    popup_add_elem(popup, "200px", NULL);
    popup_add_elem(popup, "300px", NULL);
    popup_add_elem(popup, "400px", NULL);
    popup_OnSelect(popup, listener(layout, i_OnLayoutWidth, Layout));
    return popup;
}

/*---------------------------------------------------------------------------*/

Panel *labels_single_line(void)
{
    Panel *panel = panel_create();
    Layout *layout = layout_create(1, 7);
    PopUp *popup = i_width_popup(layout);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Label *label5 = label_create();
    Label *label6 = label_create();
    color_t c1 = gui_alt_color(color_rgb(192, 255, 255), color_rgb(48, 112, 112));
    color_t c2 = gui_alt_color(color_rgb(255, 192, 255), color_rgb(128, 48, 112));
    color_t c3 = gui_alt_color(color_rgb(255, 255, 192), color_rgb(112, 112, 48));
    label_text(label1, i_LABEL_01);
    label_text(label2, i_LABEL_02);
    label_text(label3, i_LABEL_03);
    label_text(label4, i_LABEL_04);
    label_text(label5, i_LABEL_05);
    label_text(label6, i_LABEL_06);
    label_bgcolor(label1, c1);
    label_bgcolor(label2, c2);
    label_bgcolor(label3, c3);
    label_bgcolor(label4, c1);
    label_bgcolor(label5, c2);
    label_bgcolor(label6, c3);
    layout_popup(layout, popup, 0, 0);
    layout_label(layout, label1, 0, 1);
    layout_label(layout, label2, 0, 2);
    layout_label(layout, label3, 0, 3);
    layout_label(layout, label4, 0, 4);
    layout_label(layout, label5, 0, 5);
    layout_label(layout, label6, 0, 6);
    layout_vmargin(layout, 0, 5);
    panel_layout(panel, layout);
    return panel;
}

/*---------------------------------------------------------------------------*/

Panel *labels_multi_line(void)
{
    Panel *panel = panel_create();
    Layout *layout = layout_create(1, 7);
    PopUp *popup = i_width_popup(layout);
    Label *label1 = label_multiline();
    Label *label2 = label_multiline();
    Label *label3 = label_multiline();
    Label *label4 = label_multiline();
    Label *label5 = label_multiline();
    Label *label6 = label_multiline();
    color_t c1 = gui_alt_color(color_rgb(192, 255, 255), color_rgb(48, 112, 112));
    color_t c2 = gui_alt_color(color_rgb(255, 192, 255), color_rgb(128, 48, 112));
    color_t c3 = gui_alt_color(color_rgb(255, 255, 192), color_rgb(112, 112, 48));
    label_text(label1, i_LABEL_01);
    label_text(label2, i_LABEL_02);
    label_text(label3, i_LABEL_03);
    label_text(label4, i_LABEL_04);
    label_text(label5, i_LABEL_05);
    label_text(label6, i_LABEL_06);
    label_bgcolor(label1, c1);
    label_bgcolor(label2, c2);
    label_bgcolor(label3, c3);
    label_bgcolor(label4, c1);
    label_bgcolor(label5, c2);
    label_bgcolor(label6, c3);
    label_align(label4, ekLEFT);
    label_align(label5, ekCENTER);
    label_align(label6, ekRIGHT);
    layout_popup(layout, popup, 0, 0);
    layout_label(layout, label1, 0, 1);
    layout_label(layout, label2, 0, 2);
    layout_label(layout, label3, 0, 3);
    layout_label(layout, label4, 0, 4);
    layout_label(layout, label5, 0, 5);
    layout_label(layout, label6, 0, 6);
    layout_vmargin(layout, 0, 5);
    panel_layout(panel, layout);
    return panel;
}

/*---------------------------------------------------------------------------*/

Panel *labels_mouse_over(void)
{
    Panel *panel = panel_create();
    Layout *layout = layout_create(1, 5);
    Font *font = font_system(20, ekFNORMAL | ekFPIXELS);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Label *label5 = label_create();
    label_text(label1, i_LABEL_07);
    label_text(label2, i_LABEL_07);
    label_text(label3, i_LABEL_07);
    label_text(label4, i_LABEL_07);
    label_text(label5, i_LABEL_07);
    label_font(label1, font);
    label_font(label2, font);
    label_font(label3, font);
    label_font(label4, font);
    label_font(label5, font);
    label_color_over(label1, kCOLOR_RED);
    label_color_over(label2, kCOLOR_RED);
    label_color_over(label3, kCOLOR_RED);
    label_color_over(label4, kCOLOR_RED);
    label_color_over(label5, kCOLOR_RED);
    label_style_over(label1, ekFBOLD);
    label_style_over(label2, ekFITALIC);
    label_style_over(label3, ekFSTRIKEOUT);
    label_style_over(label4, ekFUNDERLINE);
    label_bgcolor_over(label5, kCOLOR_CYAN);
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_label(layout, label3, 0, 2);
    layout_label(layout, label4, 0, 3);
    layout_label(layout, label5, 0, 4);
    panel_layout(panel, layout);
    font_destroy(&font);
    return panel;
}


2. ¡Hola Button!

Captura de controles de interfaz tipo Button.
Figura 2: Controles Button.
Listado 2: howto/guihello/buttons.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* Buttons demo */

#include "buttons.h"
#include "res.h"
#include "guiall.h"

/*---------------------------------------------------------------------------*/

static Layout *i_flatbuttons(void)
{
    Layout *layout = layout_create(6, 1);
    Button *button1 = button_flat();
    Button *button2 = button_flat();
    Button *button3 = button_flat();
    Button *button4 = button_flat();
    Button *button5 = button_flat();
    Button *button6 = button_flat();
    button_text(button1, "Open File");
    button_text(button2, "Save File");
    button_text(button3, "Search File");
    button_text(button4, "Edit File");
    button_text(button5, "Add File");
    button_text(button6, "Delete File");
    button_image(button1, (const Image*)FOLDER24_PNG);
    button_image(button2, (const Image*)DISK24_PNG);
    button_image(button3, (const Image*)SEARCH24_PNG);
    button_image(button4, (const Image*)EDIT24_PNG);
    button_image(button5, (const Image*)PLUS24_PNG);
    button_image(button6, (const Image*)ERROR24_PNG);
    layout_button(layout, button1, 0, 0);
    layout_button(layout, button2, 1, 0);
    layout_button(layout, button3, 2, 0);
    layout_button(layout, button4, 3, 0);
    layout_button(layout, button5, 4, 0);
    layout_button(layout, button6, 5, 0);
    return layout;
} 

/*---------------------------------------------------------------------------*/

static Layout *i_radios(void)
{
    Layout *layout = layout_create(1, 4);
    Button *radio1 = button_radio();
    Button *radio2 = button_radio();
    Button *radio3 = button_radio();
    Button *radio4 = button_radio();
    button_text(radio1, "Wireframe");
    button_text(radio2, "Shaded");
    button_text(radio3, "Realistic");
    button_text(radio4, "V-Ray");
    button_state(radio1, ekON);
    layout_button(layout, radio1, 0, 0);
    layout_button(layout, radio2, 0, 1);
    layout_button(layout, radio3, 0, 2);
    layout_button(layout, radio4, 0, 3);
    layout_margin(layout, 5);
    layout_vmargin(layout, 0, 3);
    layout_vmargin(layout, 1, 3);
    layout_vmargin(layout, 2, 3);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_checks(void)
{
    Layout *layout = layout_create(1, 4);
    Button *check1 = button_check();
    Button *check2 = button_check();
    Button *check3 = button_check();
    Button *check4 = button_check();
    button_text(check1, "Lines");
    button_text(check2, "Meshes");
    button_text(check3, "Materials");
    button_text(check4, "Lights");
    button_state(check1, ekON);
    button_state(check2, ekOFF);
    button_state(check3, ekOFF);
    button_state(check4, ekON);
    layout_button(layout, check1, 0, 0);
    layout_button(layout, check2, 0, 1);
    layout_button(layout, check3, 0, 2);
    layout_button(layout, check4, 0, 3);
    layout_margin(layout, 5);
    layout_vmargin(layout, 0, 3);
    layout_vmargin(layout, 1, 3);
    layout_vmargin(layout, 2, 3);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_pushes(void)
{
    Layout *layout = layout_create(4, 1);
    Button *button1 = button_push();
    Button *button2 = button_push();
    Button *button3 = button_push();
    button_text(button1, "Retry");
    button_text(button2, "Cancel");
    button_text(button3, "Ok");
    button_image(button1, (const Image*)RETRY_PNG);
    layout_button(layout, button1, 0, 0);
    layout_button(layout, button2, 2, 0);
    layout_button(layout, button3, 3, 0);
    layout_hmargin(layout, 2, 5);
    layout_hexpand(layout, 1);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_buttons(void)
{
    Layout *layout = layout_create(1, 3);
    Layout *layout1 = i_flatbuttons();
    Layout *layout2 = layout_create(2, 2);
    Layout *layout3 = i_radios();
    Layout *layout4 = i_checks();
    Layout *layout5 = i_pushes();
    Button *check1 = button_check();
    Button *check2 = button_check3();
    button_text(check1, "Enable 3D Render");
    button_text(check2, "Enable Preview Settings");
    button_state(check1, ekON);
    button_state(check2, ekMIXED);
    layout_layout(layout, layout1, 0, 0);
    layout_button(layout2, check1, 0, 0);
    layout_layout(layout2, layout3, 0, 1);
    layout_button(layout2, check2, 1, 0);
    layout_layout(layout2, layout4, 1, 1);
    layout_layout(layout, layout2, 0, 1);
    layout_layout(layout, layout5, 0, 2);
    layout_halign(layout, 0, 0, ekLEFT);
    layout_margin(layout2, 5);
    layout_hmargin(layout2, 0, 10);
    layout_margin(layout5, 5);
    return layout;
}

/*---------------------------------------------------------------------------*/

Panel *buttons_basics(void)
{
    Layout *layout = i_buttons();
    Panel *panel = panel_create();
    panel_layout(panel, layout);
    return panel;
}


3. ¡Hola PopUp y Combo!

Captura de controles de interfaz tipo PopUp.
Figura 3: Controles PopUp.
Captura de controles de interfaz tipo Combo.
Figura 4: Controles Combo.
Listado 3: howto/guihello/popcom.c
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* PopUp and Combo */

#include "popcom.h"
#include "guiall.h"
#include "res.h"

/*---------------------------------------------------------------------------*/

static void i_popups(Layout *layout)
{ 
    Label *label1 = label_create();
    Label *label2 = label_create();
    PopUp *popup1 = popup_create();
    PopUp *popup2 = popup_create();
    label_text(label1, "Language:");
    label_text(label2, "Color:");
    popup_add_elem(popup1, "English", (const Image*)UKING_PNG);
    popup_add_elem(popup1, "Español", (const Image*)SPAIN_PNG);
    popup_add_elem(popup1, "Portugues", (const Image*)PORTUGAL_PNG);
    popup_add_elem(popup1, "Italiana", (const Image*)ITALY_PNG);
    popup_add_elem(popup1, "Tiếng Việt", (const Image*)VIETNAM_PNG);
    popup_add_elem(popup1, "России", (const Image*)RUSSIA_PNG);
    popup_add_elem(popup1, "日本語", (const Image*)JAPAN_PNG);
    popup_add_elem(popup2, "Red", (const Image*)RED_PNG);
    popup_add_elem(popup2, "Blue", (const Image*)BLUE_PNG);
    popup_add_elem(popup2, "Green", (const Image*)GREEN_PNG);
    popup_add_elem(popup2, "Yellow", (const Image*)YELLOW_PNG);
    popup_add_elem(popup2, "Black", (const Image*)BLACK_PNG);
    popup_add_elem(popup2, "White", (const Image*)WHITE_PNG);
    popup_list_height(popup1, 10);
    popup_list_height(popup2, 10);
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_popup(layout, popup1, 1, 0);
    layout_popup(layout, popup2, 1, 1);
}

/*---------------------------------------------------------------------------*/

static void i_combos(Layout *layout)
{
    Label *label1 = label_create();
    Label *label2 = label_create();
    Combo *combo1 = combo_create();
    Combo *combo2 = combo_create();
    label_text(label1, "Search:");
    label_text(label2, "Folder:");
    combo_add_elem(combo1, "Search", NULL);
    combo_add_elem(combo1, "Disk", NULL);
    combo_add_elem(combo1, "Edit", NULL);
    combo_add_elem(combo2, "/home/fran/Desktop", NULL);
    combo_add_elem(combo2, "/usr/include", NULL);
    combo_add_elem(combo2, "/mnt/volume1", NULL);
    combo_add_elem(combo2, "/etc/html/log.txt", NULL);
    layout_label(layout, label1, 2, 0);
    layout_label(layout, label2, 2, 1);
    layout_combo(layout, combo1, 3, 0);
    layout_combo(layout, combo2, 3, 1);
}

/*---------------------------------------------------------------------------*/

Panel *popup_combo(void)
{
    Panel *panel = panel_create();
    Layout *layout = layout_create(4, 2);
    i_popups(layout);
    i_combos(layout);
    layout_margin(layout, 10.f);
    layout_vmargin(layout, 0, 10.f);
    layout_hmargin(layout, 0, 5.f);
    layout_hmargin(layout, 1, 10.f);
    layout_hmargin(layout, 2, 5.f);
    layout_hsize(layout, 1, 150.f);
    layout_hsize(layout, 3, 150.f);
    panel_layout(panel, layout);
    return panel;
}

4. ¡Hola Edit y UpDown!

Captura de controles de interfaz tipo Edit y UpDown.
Figura 5: Controles Edit y UpDown.
Listado 4: howto/guihello/form.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* Form demo */

#include "form.h"
#include "res.h"
#include "guiall.h"

/*---------------------------------------------------------------------------*/

static void i_OnFilter(void *noused, Event *e)
{
    const EvText *params = event_params(e, EvText);
    EvTextFilter *result = event_result(e, EvTextFilter);
    uint32_t i = 0, j = 0;
    while (params->text[i] != '\0')
    {
        if (params->text[i] >= '0' && params->text[i] <= '9')
        {
            result->text[j] = params->text[i];
            j += 1;
        }

        i += 1;
    }

    result->text[j] = '\0';
    result->apply = TRUE;
    unref(noused);
}

/*---------------------------------------------------------------------------*/

static void i_OnUpDown(Edit *edit, Event *e)
{
    const EvButton *params = event_params(e, EvButton);
    int32_t n = str_to_i32(edit_get_text(edit), 10, NULL);
    char_t text[64];
    n += (params->index == 0) ? 1 : -1;
    bstd_sprintf(text, sizeof(text), "%d", n);
    edit_text(edit, text);
}

/*---------------------------------------------------------------------------*/

static Layout *i_numbers(color_t colorbg)
{
    Layout *layout = layout_create(5, 1);
    Label *label = label_create();
    Edit *edit1 = edit_create();
    Edit *edit2 = edit_create();
    UpDown *updown1 = updown_create();
    UpDown *updown2 = updown_create();
    label_text(label, "Height (cm):");
    edit_text(edit1, "25");
    edit_text(edit2, "175");
    edit_align(edit1, ekRIGHT);
    edit_align(edit2, ekRIGHT);
    edit_OnFilter(edit1, listener(NULL, i_OnFilter, void));
    edit_OnFilter(edit2, listener(NULL, i_OnFilter, void));
    edit_bgcolor_focus(edit1, colorbg);
    edit_bgcolor_focus(edit2, colorbg);
    updown_OnClick(updown1, listener(edit1, i_OnUpDown, Edit));
    updown_OnClick(updown2, listener(edit2, i_OnUpDown, Edit));
    updown_tooltip(updown1, "Increase/Decrease age");
    updown_tooltip(updown2, "Increase/Decrease height");
    layout_label(layout, label, 2, 0);
    layout_edit(layout, edit1, 0, 0);
    layout_edit(layout, edit2, 3, 0);
    layout_updown(layout, updown1, 1, 0);
    layout_updown(layout, updown2, 4, 0);
    layout_hmargin(layout, 1, 10.f);
    layout_hmargin(layout, 2, 10.f);
    layout_hexpand2(layout, 0, 3, .5f);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_edits(void)
{
    color_t colorbg = gui_alt_color(color_bgr(0xFFFFe4), color_bgr(0x101010));
    Layout *layout1 = layout_create(2, 6);
    Layout *layout2 = i_numbers(colorbg);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Label *label5 = label_create();
    Label *label6 = label_create();
    Edit *edit1 = edit_create();
    Edit *edit2 = edit_create();
    Edit *edit3 = edit_create();
    Edit *edit4 = edit_create();
    Edit *edit5 = edit_create();
    label_text(label1, "User Name:");
    label_text(label2, "Password:");
    label_text(label3, "Address:");
    label_text(label4, "City:");
    label_text(label5, "Phone:");
    label_text(label6, "Age:");
    label_color_over(label1, color_rgb(255, 128, 52));
    label_color_over(label2, color_rgb(70, 129, 207));
    label_color_over(label3, color_rgb(119, 188, 31));
    label_style_over(label4, ekFITALIC | ekFUNDERLINE);
    edit_text(edit1, "Amanda Callister");
    edit_text(edit2, "aQwe56nhjJk");
    edit_text(edit3, "35, Tuam Road");
    edit_text(edit4, "Galway - Ireland");
    edit_text(edit5, "+35 654 333 000");
    edit_passmode(edit2, TRUE);
    edit_bgcolor_focus(edit1, colorbg);
    edit_bgcolor_focus(edit2, colorbg);
    edit_bgcolor_focus(edit3, colorbg);
    edit_bgcolor_focus(edit4, colorbg);
    edit_bgcolor_focus(edit5, colorbg);
    layout_label(layout1, label1, 0, 0);
    layout_label(layout1, label2, 0, 1);
    layout_label(layout1, label3, 0, 2);
    layout_label(layout1, label4, 0, 3);
    layout_label(layout1, label5, 0, 4);
    layout_label(layout1, label6, 0, 5);
    layout_edit(layout1, edit1, 1, 0);
    layout_edit(layout1, edit2, 1, 1);
    layout_edit(layout1, edit3, 1, 2);
    layout_edit(layout1, edit4, 1, 3);
    layout_edit(layout1, edit5, 1, 4);
    layout_layout(layout1, layout2, 1, 5);
    layout_hmargin(layout1, 0, 5);
    layout_hexpand(layout1, 1);
    layout_vmargin(layout1, 0, 5);
    layout_vmargin(layout1, 1, 5);
    layout_vmargin(layout1, 2, 5);
    layout_vmargin(layout1, 3, 5);
    layout_vmargin(layout1, 4, 5);
    return layout1;
}

/*---------------------------------------------------------------------------*/

static Layout *i_form(void)
{
    Layout *layout1 = layout_create(1, 2);
    Layout *layout2 = i_edits();
    Label *label = label_multiline();
    label_text(label, "Please fill in all the information on the form. We will use this data to send commercial mail at all hours, not caring much if it bothers you or not.");
    label_color(label, gui_alt_color(color_rgb(255, 0, 0), color_rgb(180, 180, 180)));
    label_bgcolor(label, gui_alt_color(color_rgb(216, 191, 216), color_rgb(80, 40, 40)));
    label_bgcolor_over(label, gui_alt_color(color_rgb(255, 250, 205), color_rgb(105, 100, 55)));
    label_style_over(label, ekFUNDERLINE);
    layout_layout(layout1, layout2, 0, 0);
    layout_label(layout1, label, 0, 1);
    layout_hsize(layout1, 0, 300);
    layout_vmargin(layout1, 0, 10);
    layout_margin(layout1, 10);
    return layout1;
}

/*---------------------------------------------------------------------------*/

Panel *form_basic(void)
{
    Layout *layout = i_form();
    Panel *panel = panel_create();
    panel_layout(panel, layout);
    return panel;
}


5. ¡Hola ListBox!

Captura de controles de interfaz tipo ListBox.
Figura 6: Controles ListBox.
Listado 5: howto/guihello/listboxes.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* Listboxes */
    
#include "listboxes.h"
#include "guiall.h"
#include "res.h"

/*---------------------------------------------------------------------------*/

static ListBox *i_full_listbox(void)
{
    ListBox *listbox = listbox_create();
    listbox_size(listbox, s2df(150, 200));
    listbox_multisel(listbox, TRUE);
    listbox_checkbox(listbox, TRUE);
    listbox_add_elem(listbox, "Sales presentation", resid_image(POWERPOINT_PNG));
    listbox_add_elem(listbox, "Balance 2017", resid_image(POWERPOINT_PNG));
    listbox_add_elem(listbox, "The Last of Us Analysis", resid_image(POWERPOINT_PNG));
    listbox_add_elem(listbox, "Phone list", resid_image(ACCESS_PNG));
    listbox_add_elem(listbox, "Customer database", resid_image(ACCESS_PNG));
    listbox_add_elem(listbox, "My first book", resid_image(WORD_PNG));
    listbox_add_elem(listbox, "Letter to April", resid_image(WORD_PNG));
    listbox_add_elem(listbox, "Cookbook Recipes", resid_image(WORD_PNG));
    listbox_add_elem(listbox, "Dog playing piano", resid_image(JPG_PNG));
    listbox_add_elem(listbox, "Hollidays 2019", resid_image(JPG_PNG));
    listbox_add_elem(listbox, "Amanda's party", resid_image(JPG_PNG));
    listbox_add_elem(listbox, "Flying", resid_image(JPG_PNG));
    listbox_add_elem(listbox, "The C Programing Language", resid_image(PDF_PNG));
    listbox_add_elem(listbox, "Graphics Programing with GDI+", resid_image(PDF_PNG));
    listbox_add_elem(listbox, "Personal finances", resid_image(EXCEL_PNG));
    listbox_add_elem(listbox, "Stocks 2017", resid_image(EXCEL_PNG));
    listbox_add_elem(listbox, "Website Dashboard", resid_image(EXCEL_PNG));
    listbox_add_elem(listbox, "Open Issues", resid_image(DOCUMENT_PNG));
    listbox_add_elem(listbox, "TODO List", resid_image(DOCUMENT_PNG));
    listbox_select(listbox, 0, TRUE);
    return listbox;
}

/*---------------------------------------------------------------------------*/

static ListBox *i_image_listbox(void)
{
    ListBox *listbox = listbox_create();
    listbox_size(listbox, s2df(150, 200));
    listbox_add_elem(listbox, "Spain", resid_image(SPAIN_PNG));
    listbox_add_elem(listbox, "Italy", resid_image(ITALY_PNG));
    listbox_add_elem(listbox, "United Kingdom", resid_image(UKING_PNG));
    listbox_add_elem(listbox, "Vietnam", resid_image(VIETNAM_PNG));
    listbox_add_elem(listbox, "Russia", resid_image(RUSSIA_PNG));
    listbox_add_elem(listbox, "Portugal", resid_image(PORTUGAL_PNG));
    listbox_add_elem(listbox, "Japan", resid_image(JAPAN_PNG));
    listbox_add_elem(listbox, "Disk", resid_image(DISK16_PNG));
    listbox_add_elem(listbox, "Edit", resid_image(EDIT16_PNG));
    listbox_add_elem(listbox, "Folder", resid_image(FOLDER16_PNG));
    listbox_add_elem(listbox, "Restore", resid_image(RESTORE16_PNG));
    listbox_add_elem(listbox, "Search", resid_image(SEARCH16_PNG));
    listbox_add_elem(listbox, "Error", resid_image(ERROR16_PNG));
    listbox_select(listbox, 0, TRUE);
    return listbox;
}

/*---------------------------------------------------------------------------*/

static ListBox *i_simple_listbox(void)
{
    ListBox *listbox = listbox_create();
    listbox_size(listbox, s2df(150, 200));
    listbox_add_elem(listbox, "Item 1", NULL);
    listbox_add_elem(listbox, "Item 2", NULL);
    listbox_add_elem(listbox, "Item 3", NULL);
    listbox_add_elem(listbox, "Item 4", NULL);
    //listbox_add_elem(listbox, "Item 5", NULL);
    //listbox_add_elem(listbox, "Item 6", NULL);
    //listbox_add_elem(listbox, "Item 7", NULL);
    //listbox_add_elem(listbox, "Item 8", NULL);
    //listbox_add_elem(listbox, "Item 9", NULL);
    //listbox_add_elem(listbox, "Item 10", NULL);
    //listbox_add_elem(listbox, "Item 11", NULL);
    //listbox_add_elem(listbox, "Item 12", NULL);
    //listbox_add_elem(listbox, "Item 13", NULL);
    //listbox_add_elem(listbox, "Item 14", NULL);
    //listbox_add_elem(listbox, "Item 15", NULL);
    //listbox_add_elem(listbox, "Item 16", NULL);
    //listbox_add_elem(listbox, "Item 17", NULL);
    //listbox_add_elem(listbox, "Item 18", NULL);
    //listbox_add_elem(listbox, "Item 19", NULL);
    //listbox_add_elem(listbox, "Item 20", NULL);
    listbox_select(listbox, 0, TRUE);
    return listbox;
}

/*---------------------------------------------------------------------------*/

Panel *listboxes(void)
{
    Panel *panel = panel_create();
    Layout *layout = layout_create(3, 2);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    ListBox *listbox1 = i_simple_listbox();
    ListBox *listbox2 = i_image_listbox();
    ListBox *listbox3 = i_full_listbox();
    label_text(label1, "Simple ListBox");
    label_text(label2, "With Images");
    label_text(label3, "Checks and Multiselect");
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 1, 0);
    layout_label(layout, label3, 2, 0);
    layout_listbox(layout, listbox1, 0, 1);
    layout_listbox(layout, listbox2, 1, 1);
    layout_listbox(layout, listbox3, 2, 1);
    layout_hmargin(layout, 0, 10);
    layout_hmargin(layout, 1, 10);
    layout_vmargin(layout, 0, 5);
    panel_layout(panel, layout);
    return panel;
}

6. ¡Hola Slider y Progress!

Captura de controles de interfaz tipo Slider y Progress.
Figura 7: Controles Slider y Progress.
Listado 6: howto/guihello/sliders.c
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Sliders */

#include "sliders.h"
#include "guiall.h"

/*---------------------------------------------------------------------------*/

static void i_OnSlider(Progress *prog, Event *event)
{
    const EvSlider *params = event_params(event, EvSlider);
    progress_value(prog, params->pos);
}

/*---------------------------------------------------------------------------*/

Panel *sliders(void)
{
    Layout *layout1 = layout_create(2, 1);
    Layout *layout2 = layout_create(1, 8);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Slider *slider1 = slider_create();
    Slider *slider2 = slider_create();
    Slider *slider3 = slider_vertical();
    Progress *prog1 = progress_create();
    Progress *prog2 = progress_create();
    Panel *panel = panel_create();
    label_text(label1, "Slider");
    label_text(label2, "Slider (discrete 6 steps)");
    label_text(label3, "Progress Bar");
    label_text(label4, "Progress Undefined");
    slider_steps(slider2, 6);
    slider_tooltip(slider1, "Horizontal Slider");
    slider_tooltip(slider2, "Horizontal Discrete Slider");
    slider_tooltip(slider3, "Vertical Slider");
    slider_OnMoved(slider1, listener(prog1, i_OnSlider, Progress));
    progress_undefined(prog2, TRUE);
    layout_label(layout2, label1, 0, 0);
    layout_label(layout2, label2, 0, 2);
    layout_label(layout2, label3, 0, 4);
    layout_label(layout2, label4, 0, 6);
    layout_slider(layout2, slider1, 0, 1);
    layout_slider(layout2, slider2, 0, 3);
    layout_slider(layout1, slider3, 1, 0);
    layout_progress(layout2, prog1, 0, 5);
    layout_progress(layout2, prog2, 0, 7);
    layout_hsize(layout2, 0, 300);
    layout_layout(layout1, layout2, 0, 0);
    layout_vmargin(layout2, 0, 5);
    layout_vmargin(layout2, 1, 5);
    layout_vmargin(layout2, 2, 5);
    layout_vmargin(layout2, 3, 5);
    layout_vmargin(layout2, 4, 5);
    layout_vmargin(layout2, 5, 5);
    layout_vmargin(layout2, 6, 5);
    layout_hmargin(layout1, 0, 10);
    panel_layout(panel, layout1);
    return panel;
}

7. ¡Hola TextView!

Vista de texto enriquecido a partir de un archivo RTF.
Figura 8: Control de texto enriquecido.
Listado 7: howto/guihello/textviews.c
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* Use of textviews */

#include "textviews.h"
#include "guiall.h"
#include "res.h"

/*---------------------------------------------------------------------------*/

static void i_set_rtf(TextView *text)
{
    ResPack *pack = res_respack("");
    uint32_t size = 0;
    const byte_t *data = respack_file(pack, TEXTVIEW_RTF, &size);
    Stream *stm = stm_from_block(data, size);
    textview_rtf(text, stm);
    stm_close(&stm);
    respack_destroy(&pack);
}

/*---------------------------------------------------------------------------*/

static void i_set_hard_coding(TextView *text)
{
    textview_units(text, ekFPOINTS);
    textview_lspacing(text, 1.15f);
    textview_afspace(text, 10);
    textview_family(text, "Arial");
    textview_fsize(text, 16);
    textview_writef(text, "What is Lorem Ipsum?\n");
    textview_fsize(text, 11);
    textview_writef(text, "Lorem Ipsum ");
    textview_fstyle(text, ekFBOLD);
    textview_writef(text, "is simply");
    textview_fstyle(text, ekFNORMAL);
    textview_writef(text, " dummy text of the ");
    textview_fstyle(text, ekFITALIC);
    textview_writef(text, "printing and typesetting ");
    textview_fstyle(text, ekFNORMAL);
    textview_writef(text, "industry. ");
    textview_fsize(text, 16);
    textview_color(text, color_rgb(255, 0, 0));
    textview_writef(text, "Lorem Ipsum ");
    textview_color(text, kCOLOR_DEFAULT);
    textview_fsize(text, 11);
    textview_writef(text, "has been the ");
    textview_family(text, "Courier New");
    textview_fsize(text, 14);
    textview_writef(text, "[industry's standard] ");
    textview_family(text, "Arial");
    textview_fsize(text, 11);
    textview_fstyle(text, ekFUNDERLINE);
    textview_writef(text, "dummy text");
    textview_fstyle(text, ekFNORMAL);
    textview_writef(text, " ever ");
    textview_fstyle(text, ekFSTRIKEOUT);
    textview_writef(text, "since the 1500s");
    textview_fstyle(text, ekFNORMAL);
    textview_writef(text, ", when an ");
    textview_color(text, color_rgb(0, 176, 80));
    textview_writef(text, "unknown printer ");
    textview_color(text, kCOLOR_DEFAULT);
    textview_writef(text, "took a galley of type and scrambled it to make a type specimen book");
    textview_fstyle(text, ekFITALIC);
    textview_color(text, color_rgb(0, 77, 187));
    textview_bgcolor(text, color_rgb(192, 192, 192));
    textview_writef(text, ". It has survived not only five centuries");
    textview_fstyle(text, ekFNORMAL);
    textview_color(text, kCOLOR_DEFAULT);
    textview_bgcolor(text, kCOLOR_DEFAULT);
    textview_writef(text, ", but also the leap into electronic typesetting, remaining essentially unchanged.");
}

/*---------------------------------------------------------------------------*/

Panel *textviews(void)
{
    Layout *layout = layout_create(1, 4);
    Label *label1 = label_create();
    Label *label2 = label_create();
    TextView *text1 = textview_create();
    TextView *text2 = textview_create();
    Panel *panel = panel_create();
    label_text(label1, "From RTF data");
    label_text(label2, "Hard coding");
    textview_size(text1, s2df(450, 250));
    textview_size(text2, s2df(450, 250));
    i_set_rtf(text1);
    i_set_hard_coding(text2);
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 2);
    layout_textview(layout, text1, 0, 1);
    layout_textview(layout, text2, 0, 3);
    layout_vmargin(layout, 0, 5);
    layout_vmargin(layout, 1, 10);
    layout_vmargin(layout, 2, 5);
    panel_layout(panel, layout);
    return panel;
}

8. ¡Hola SplitView!

Varias SplitView en la misma ventana.
Figura 9: SplitView.
Listado 8: howto/guihello/splits.c
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Use of splitviews */

#include "splits.h"
#include "guiall.h"

static const char_t *i_LOREM = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";

/*---------------------------------------------------------------------------*/

static void i_OnDraw(View *view, Event *e)
{
    const EvDraw *p = event_params(e, EvDraw);
    real32_t p0 = p->width / 6;
    real32_t p1 = p->height / 6;
    real32_t p2 = p->width / 3;
    real32_t p3 = p->height / 3;
    unref(view);
    draw_fill_color(p->ctx, kCOLOR_RED);
    draw_rect(p->ctx, ekFILL, 0, 0, p->width, p->height);
    draw_fill_color(p->ctx, kCOLOR_GREEN);
    draw_rect(p->ctx, ekFILL, p0, p1, p->width - 2 * p0, p->height - 2 * p1);
    draw_fill_color(p->ctx, kCOLOR_BLUE);
    draw_rect(p->ctx, ekFILL, p2, p3, p->width - 2 * p2, p->height - 2 * p3);
}

/*---------------------------------------------------------------------------*/

static Panel *i_left_panel(void)
{
    uint32_t i, n = 32;
    Panel *panel = panel_scroll(FALSE, TRUE);
    Layout *layout = layout_create(2, n);
    real32_t rmargin = panel_scroll_width(panel);

    for (i = 0; i < n; ++i)
    {
        char_t text[64];
        Label *label = label_create();
        Edit *edit = edit_create();
        bstd_sprintf(text, sizeof(text), "Value %02d", i);
        label_text(label, text);
        bstd_sprintf(text, sizeof(text), "Edit here value %02d", i);
        edit_text(edit, text);
        layout_label(layout, label, 0, i);
        layout_edit(layout, edit, 1, i);
    }

    for (i = 0; i < n - 1; ++i)
        layout_vmargin(layout, i, 3);

    layout_hmargin(layout, 0, 5);
    layout_margin4(layout, 0, rmargin + 5, 0, 0);
    layout_hexpand(layout, 1);
    panel_layout(panel, layout);
    return panel;
}

/*---------------------------------------------------------------------------*/

Panel *split_panel(void)
{
    Panel *panel1 = panel_create();
    Panel *panel2 = i_left_panel();
    Layout *layout = layout_create(1, 1);
    SplitView *split1 = splitview_vertical();
    SplitView *split2 = splitview_horizontal();
    TextView *text = textview_create();
    View *view = view_create();
    textview_writef(text, i_LOREM);
    view_OnDraw(view, listener(view, i_OnDraw, View));
    splitview_pos(split1, .25f);
    splitview_size(split1, s2df(800, 480));
    splitview_size(split2, s2df(640, 480));
    splitview_view(split2, view);
    splitview_text(split2, text);
    splitview_panel(split1, panel2);
    splitview_split(split1, split2);
    layout_splitview(layout, split1, 0, 0);
    panel_layout(panel1, layout);
    return panel1;
}

9. ¡Hola Gui Binding!

Data binding en Windows.
Figura 10: Gui Data binding.
Listado 9: howto/guihello/guibind.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* GUI data binding */

#include "guibind.h"
#include "guiall.h"

typedef struct _basictypes_t BasicTypes;

typedef enum _myenum_t
{
    ekRED,
    ekBLUE,
    ekGREEN,
    ekBLACK,
    ekMAGENTA,
    ekCYAN,
    ekYELLOW,
    ekWHITE
} myenum_t;

struct _basictypes_t
{
    bool_t bool_val;
    uint16_t uint16_val;
    real32_t real32_val;
    myenum_t enum_val;
    state_t enum3_val;
    String* str_val;
};

#define i_NUM_CONTROLS 9

/*---------------------------------------------------------------------------*/

static void i_destroy_data(BasicTypes **data)
{
    str_destroy(&(*data)->str_val);
    heap_delete(data, BasicTypes);
}

/*---------------------------------------------------------------------------*/

static Layout *i_radio_layout(void)
{
    uint32_t i = 0, n = 6;
    Layout *layout = layout_create(1, n);
    for (i = 0; i < n; ++i)
    {
        Button *radio = button_radio();
        char_t str[64];
        bstd_sprintf(str, sizeof(str), "Radio %d", i + 1);
        button_text(radio, str);
        layout_button(layout, radio, 0, i);
    }

    return layout;
}

/*---------------------------------------------------------------------------*/

static void i_title_labels(Layout* layout)
{
    Font* font = font_system(font_regular_size(), ekFBOLD);
    const char_t* strs[] = { "Label", "EditBox", "Check", "Check3", "Radio", "PopUp", "ListBox", "Slider", "UpDown" };
    uint32_t i = 0;
    for (i = 0; i < i_NUM_CONTROLS; ++i)
    {
        Label* label = label_create();
        label_text(label, strs[i]);
        label_font(label, font);
        layout_label(layout, label, 0, i);
    }

    layout_hmargin(layout, 0, 10);
    font_destroy(&font);
}

/*---------------------------------------------------------------------------*/

static void i_value_labels(Layout* layout)
{
    uint32_t i = 0;
    for (i = 0; i < i_NUM_CONTROLS; ++i)
    {
        Label* label = label_create();
        label_align(label, ekCENTER);
        layout_label(layout, label, 2, i);
        layout_halign(layout, 2, i, ekJUSTIFY);
    }

    layout_hsize(layout, 2, 80);
    layout_hmargin(layout, 0, 10);
    for (i = 0; i < i_NUM_CONTROLS - 1; ++i)
        layout_vmargin(layout, i, 5);

    cell_dbind(layout_cell(layout, 2, 0), BasicTypes, String*, str_val);
    cell_dbind(layout_cell(layout, 2, 1), BasicTypes, String*, str_val);
    cell_dbind(layout_cell(layout, 2, 2), BasicTypes, bool_t, bool_val);
    cell_dbind(layout_cell(layout, 2, 3), BasicTypes, state_t, enum3_val);
    cell_dbind(layout_cell(layout, 2, 4), BasicTypes, uint16_t, uint16_val);
    cell_dbind(layout_cell(layout, 2, 5), BasicTypes, myenum_t, enum_val);
    cell_dbind(layout_cell(layout, 2, 6), BasicTypes, myenum_t, enum_val);
    cell_dbind(layout_cell(layout, 2, 7), BasicTypes, real32_t, real32_val);
    cell_dbind(layout_cell(layout, 2, 8), BasicTypes, real32_t, real32_val);
}

/*---------------------------------------------------------------------------*/

static Layout *i_layout(void)
{
    Layout *layout = layout_create(3, 9);
    Label *label = label_create();
    Edit *edit = edit_create();
    Button *check = button_check();
    Button *check3 = button_check3();
    Layout *radios = i_radio_layout();
    PopUp *popup = popup_create();
    ListBox *listbox = listbox_create();
    Slider *slider = slider_create();
    UpDown *updown = updown_create();
    layout_label(layout, label, 1, 0);
    layout_edit(layout, edit, 1, 1);
    layout_button(layout, check, 1, 2);
    layout_button(layout, check3, 1, 3);
    layout_layout(layout, radios, 1, 4);
    layout_popup(layout, popup, 1, 5);
    layout_listbox(layout, listbox, 1, 6);
    layout_slider(layout, slider, 1, 7);
    layout_updown(layout, updown, 1, 8);
    layout_halign(layout, 1, 0, ekJUSTIFY);
    layout_halign(layout, 1, 8, ekLEFT);
    cell_dbind(layout_cell(layout, 1, 0), BasicTypes, String*, str_val);
    cell_dbind(layout_cell(layout, 1, 1), BasicTypes, String*, str_val);
    cell_dbind(layout_cell(layout, 1, 2), BasicTypes, bool_t, bool_val);
    cell_dbind(layout_cell(layout, 1, 3), BasicTypes, state_t, enum3_val);
    cell_dbind(layout_cell(layout, 1, 4), BasicTypes, uint16_t, uint16_val);
    cell_dbind(layout_cell(layout, 1, 5), BasicTypes, myenum_t, enum_val);
    cell_dbind(layout_cell(layout, 1, 6), BasicTypes, myenum_t, enum_val);
    cell_dbind(layout_cell(layout, 1, 7), BasicTypes, real32_t, real32_val);
    cell_dbind(layout_cell(layout, 1, 8), BasicTypes, real32_t, real32_val);
    i_title_labels(layout);
    i_value_labels(layout);
    return layout;
}

/*---------------------------------------------------------------------------*/

Panel* guibind(void)
{
    Layout *layout = NULL;
    Panel *panel = NULL;
    BasicTypes *data = heap_new(BasicTypes);
    data->bool_val = TRUE;
    data->uint16_val = 4;
    data->real32_val = 15.5f;
    data->enum3_val = ekMIXED;
    data->enum_val = ekCYAN;
    data->str_val = str_c("Text String");

    dbind_enum(state_t, ekOFF, "");
    dbind_enum(state_t, ekON, "");
    dbind_enum(state_t, ekMIXED, "");
    dbind_enum(myenum_t, ekRED, "Red");
    dbind_enum(myenum_t, ekBLUE, "Blue");
    dbind_enum(myenum_t, ekGREEN, "Green");
    dbind_enum(myenum_t, ekBLACK, "Black");
    dbind_enum(myenum_t, ekMAGENTA, "Magenta");
    dbind_enum(myenum_t, ekCYAN, "Cyan");
    dbind_enum(myenum_t, ekYELLOW, "Yellow");
    dbind_enum(myenum_t, ekWHITE, "While");
    dbind(BasicTypes, bool_t, bool_val);
    dbind(BasicTypes, uint16_t, uint16_val);
    dbind(BasicTypes, real32_t, real32_val);
    dbind(BasicTypes, state_t, enum3_val);
    dbind(BasicTypes, myenum_t, enum_val);
    dbind(BasicTypes, String*, str_val);
    dbind_range(BasicTypes, real32_t, real32_val, -50, 50);
    dbind_increment(BasicTypes, real32_t, real32_val, 5);

    layout = i_layout();
    panel = panel_create();
    layout_dbind(layout, NULL, BasicTypes);
    layout_dbind_obj(layout, data, BasicTypes);
    panel_data(panel, &data, i_destroy_data, BasicTypes);
    panel_layout(panel, layout);
    return panel;
}

10. ¡Hola Struct Binding!

Struct data binding en Windows.
Figura 11: Gui Struct binding.
Listado 10: howto/guihello/layoutbind.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/* GUI data binding */

#include "guibind.h"
#include "guiall.h"

typedef struct _vector_t Vector;
typedef struct _structtypes_t StructTypes;

struct _vector_t
{
    real32_t x;
    real32_t y;
    real32_t z;
};

struct _structtypes_t
{
    String *name;
    Vector vec1;
    Vector vec2;
    Vector vec3;
    Vector *pvec1;
    Vector *pvec2;
    Vector *pvec3;
    real32_t length1;
    real32_t length2;
    real32_t length3;
    real32_t length4;
    real32_t length5;
    real32_t length6;
};

/*---------------------------------------------------------------------------*/

static void i_destroy_data(StructTypes **data)
{
    str_destroy(&(*data)->name);
    heap_delete(&(*data)->pvec1, Vector);
    heap_delete(&(*data)->pvec2, Vector);
    heap_delete(&(*data)->pvec3, Vector);
    heap_delete(data, StructTypes);
}

/*---------------------------------------------------------------------------*/

static Vector i_vec_init(const real32_t x, const real32_t y, const real32_t z)
{
    Vector v;
    v.x = x;
    v.y = y;
    v.z = z;
    return v;
}

/*---------------------------------------------------------------------------*/

static real32_t i_vec_length(const Vector *vec)
{
    real32_t n = vec->x * vec->x + vec->y * vec->y + vec->z * vec->z;
    return bmath_sqrtf(n);
}

/*---------------------------------------------------------------------------*/

static void i_OnDataChange(void *non_used, Event *e)
{
    StructTypes *data = evbind_object(e, StructTypes);
    Layout *layout = event_sender(e, Layout);
    unref(non_used);

    if (evbind_modify(e, StructTypes, Vector, vec1) == TRUE)
    {
        data->length1 = i_vec_length(&data->vec1);
        layout_dbind_update(layout, StructTypes, real32_t, length1);
    }
    else if (evbind_modify(e, StructTypes, Vector, vec2) == TRUE)
    {
        data->length2 = i_vec_length(&data->vec2);
        layout_dbind_update(layout, StructTypes, real32_t, length2);
    }
    else if (evbind_modify(e, StructTypes, Vector, vec3) == TRUE)
    {
        data->length3 = i_vec_length(&data->vec3);
        layout_dbind_update(layout, StructTypes, real32_t, length3);
    }
    else if (evbind_modify(e, StructTypes, Vector*, pvec1) == TRUE)
    {
        data->length4 = i_vec_length(data->pvec1);
        layout_dbind_update(layout, StructTypes, real32_t, length4);
    }
    else if (evbind_modify(e, StructTypes, Vector*, pvec2) == TRUE)
    {
        data->length5 = i_vec_length(data->pvec2);
        layout_dbind_update(layout, StructTypes, real32_t, length5);
    }
    else if (evbind_modify(e, StructTypes, Vector*, pvec3) == TRUE)
    {
        data->length6 = i_vec_length(data->pvec3);
        layout_dbind_update(layout, StructTypes, real32_t, length6);
    }
}

/*---------------------------------------------------------------------------*/

static Layout *i_vector_layout(void)
{
    Layout *layout = layout_create(3, 3);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Edit *edit1 = edit_create();
    Edit *edit2 = edit_create();
    Edit *edit3 = edit_create();
    UpDown *updown1 = updown_create();
    UpDown *updown2 = updown_create();
    UpDown *updown3 = updown_create();
    label_text(label1, "X:");
    label_text(label2, "Y:");
    label_text(label3, "Z:");
    edit_align(edit1, ekRIGHT);
    edit_align(edit2, ekRIGHT);
    edit_align(edit3, ekRIGHT);
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_label(layout, label3, 0, 2);
    layout_edit(layout, edit1, 1, 0);
    layout_edit(layout, edit2, 1, 1);
    layout_edit(layout, edit3, 1, 2);
    layout_updown(layout, updown1, 2, 0);
    layout_updown(layout, updown2, 2, 1);
    layout_updown(layout, updown3, 2, 2);
    layout_hmargin(layout, 0, 5);
    layout_vmargin(layout, 0, 5);
    layout_vmargin(layout, 1, 5);
    layout_hsize(layout, 1, 60);
    cell_dbind(layout_cell(layout, 1, 0), Vector, real32_t, x);
    cell_dbind(layout_cell(layout, 1, 1), Vector, real32_t, y);
    cell_dbind(layout_cell(layout, 1, 2), Vector, real32_t, z);
    cell_dbind(layout_cell(layout, 2, 0), Vector, real32_t, x);
    cell_dbind(layout_cell(layout, 2, 1), Vector, real32_t, y);
    cell_dbind(layout_cell(layout, 2, 2), Vector, real32_t, z);
    layout_dbind(layout, NULL, Vector);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_name_layout(void)
{
    Layout *layout = layout_create(2, 1);
    Label *label = label_create();
    Edit *edit = edit_create();
    label_text(label, "Object Name:");
    layout_hexpand(layout, 1);
    layout_label(layout, label, 0, 0);
    layout_edit(layout, edit, 1, 0);
    layout_hmargin(layout, 0, 10);
    cell_dbind(layout_cell(layout, 1, 0), StructTypes, String*, name);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_vectors_layout(void)
{
    Layout *layout1 = layout_create(3, 4);
    Layout *layout2 = i_vector_layout();
    Layout *layout3 = i_vector_layout();
    Layout *layout4 = i_vector_layout();
    Layout *layout5 = i_vector_layout();
    Layout *layout6 = i_vector_layout();
    Layout *layout7 = i_vector_layout();
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Label *label5 = label_create();
    Label *label6 = label_create();
    label_text(label1, "vec1");
    label_text(label2, "vec2");
    label_text(label3, "vec3");
    label_text(label4, "*pvec1");
    label_text(label5, "*pvec2");
    label_text(label6, "*pvec3");
    layout_label(layout1, label1, 0, 0);
    layout_label(layout1, label2, 1, 0);
    layout_label(layout1, label3, 2, 0);
    layout_label(layout1, label4, 0, 2);
    layout_label(layout1, label5, 1, 2);
    layout_label(layout1, label6, 2, 2);
    layout_layout(layout1, layout2, 0, 1);
    layout_layout(layout1, layout3, 1, 1);
    layout_layout(layout1, layout4, 2, 1);
    layout_layout(layout1, layout5, 0, 3);
    layout_layout(layout1, layout6, 1, 3);
    layout_layout(layout1, layout7, 2, 3);
    layout_halign(layout1, 0, 0, ekCENTER);
    layout_halign(layout1, 1, 0, ekCENTER);
    layout_halign(layout1, 2, 0, ekCENTER);
    layout_halign(layout1, 0, 2, ekCENTER);
    layout_halign(layout1, 1, 2, ekCENTER);
    layout_halign(layout1, 2, 2, ekCENTER);
    layout_hmargin(layout1, 0, 10);
    layout_hmargin(layout1, 1, 10);
    layout_vmargin(layout1, 0, 5);
    layout_vmargin(layout1, 1, 10);
    layout_vmargin(layout1, 2, 5);
    cell_dbind(layout_cell(layout1, 0, 1), StructTypes, Vector, vec1);
    cell_dbind(layout_cell(layout1, 1, 1), StructTypes, Vector, vec2);
    cell_dbind(layout_cell(layout1, 2, 1), StructTypes, Vector, vec3);
    cell_dbind(layout_cell(layout1, 0, 3), StructTypes, Vector*, pvec1);
    cell_dbind(layout_cell(layout1, 1, 3), StructTypes, Vector*, pvec2);
    cell_dbind(layout_cell(layout1, 2, 3), StructTypes, Vector*, pvec3);
    return layout1;
}

/*---------------------------------------------------------------------------*/

static Layout *i_lengths_layout(void)
{
    Layout *layout = layout_create(2, 6);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Label *label5 = label_create();
    Label *label6 = label_create();
    Label *label7 = label_create();
    Label *label8 = label_create();
    Label *label9 = label_create();
    Label *label10 = label_create();
    Label *label11 = label_create();
    Label *label12 = label_create();
    label_text(label1, "length1:");
    label_text(label2, "length2:");
    label_text(label3, "length3:");
    label_text(label4, "length4:");
    label_text(label5, "length5:");
    label_text(label6, "length6:");
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_label(layout, label3, 0, 2);
    layout_label(layout, label4, 0, 3);
    layout_label(layout, label5, 0, 4);
    layout_label(layout, label6, 0, 5);
    layout_label(layout, label7, 1, 0);
    layout_label(layout, label8, 1, 1);
    layout_label(layout, label9, 1, 2);
    layout_label(layout, label10, 1, 3);
    layout_label(layout, label11, 1, 4);
    layout_label(layout, label12, 1, 5);
    label_align(label7, ekRIGHT);
    label_align(label8, ekRIGHT);
    label_align(label9, ekRIGHT);
    label_align(label10, ekRIGHT);
    label_align(label11, ekRIGHT);
    label_align(label12, ekRIGHT);
    layout_hsize(layout, 1, 40);
    layout_hmargin(layout, 0, 5);
    layout_halign(layout, 1, 0, ekJUSTIFY);
    layout_halign(layout, 1, 1, ekJUSTIFY);
    layout_halign(layout, 1, 2, ekJUSTIFY);
    layout_halign(layout, 1, 3, ekJUSTIFY);
    layout_halign(layout, 1, 4, ekJUSTIFY);
    layout_halign(layout, 1, 5, ekJUSTIFY);
    cell_dbind(layout_cell(layout, 1, 0), StructTypes, real32_t, length1);
    cell_dbind(layout_cell(layout, 1, 1), StructTypes, real32_t, length2);
    cell_dbind(layout_cell(layout, 1, 2), StructTypes, real32_t, length3);
    cell_dbind(layout_cell(layout, 1, 3), StructTypes, real32_t, length4);
    cell_dbind(layout_cell(layout, 1, 4), StructTypes, real32_t, length5);
    cell_dbind(layout_cell(layout, 1, 5), StructTypes, real32_t, length6);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_layout(void)
{
    Layout *layout1 = layout_create(2, 2);
    Layout *layout2 = i_name_layout();
    Layout *layout3 = i_vectors_layout();
    Layout *layout4 = i_lengths_layout();
    layout_layout(layout1, layout2, 0, 0);
    layout_layout(layout1, layout3, 0, 1);
    layout_layout(layout1, layout4, 1, 1);
    layout_hmargin(layout1, 0, 10);
    layout_vmargin(layout1, 0, 10);
    return layout1;
}

/*---------------------------------------------------------------------------*/

Panel* layoutbind(void)
{
    Layout *layout = NULL;
    Panel *panel = NULL;
    StructTypes *data = heap_new(StructTypes);
    data->name = str_c("Generic Object");
    data->pvec1 = heap_new(Vector);
    data->pvec2 = heap_new(Vector);
    data->pvec3 = heap_new(Vector);
    data->vec1 = i_vec_init(1.2f, 2.1f, -3.4f);
    data->vec2 = i_vec_init(-0.2f, 1.8f, 2.3f);
    data->vec3 = i_vec_init(-3.2f, 4.9f, -4.7f);
    *data->pvec1 = i_vec_init(0.9f, 7.9f, -2.0f);
    *data->pvec2 = i_vec_init(-6.9f, 2.2f, 8.6f);
    *data->pvec3 = i_vec_init(3.9f, -5.5f, 0.3f);
    data->length1 = i_vec_length(&data->vec1);
    data->length2 = i_vec_length(&data->vec2);
    data->length3 = i_vec_length(&data->vec3);
    data->length4 = i_vec_length(data->pvec1);
    data->length5 = i_vec_length(data->pvec2);
    data->length6 = i_vec_length(data->pvec3);

    dbind(Vector, real32_t, x);
    dbind(Vector, real32_t, y);
    dbind(Vector, real32_t, z);
    dbind(StructTypes, String*, name);
    dbind(StructTypes, Vector, vec1);
    dbind(StructTypes, Vector, vec2);
    dbind(StructTypes, Vector, vec3);
    dbind(StructTypes, Vector*, pvec1);
    dbind(StructTypes, Vector*, pvec2);
    dbind(StructTypes, Vector*, pvec3);
    dbind(StructTypes, real32_t, length1);
    dbind(StructTypes, real32_t, length2);
    dbind(StructTypes, real32_t, length3);
    dbind(StructTypes, real32_t, length4);
    dbind(StructTypes, real32_t, length5);
    dbind(StructTypes, real32_t, length6);
    dbind_range(Vector, real32_t, x, -5, 5);
    dbind_range(Vector, real32_t, y, -5, 5);
    dbind_range(Vector, real32_t, z, -5, 5);
    dbind_increment(Vector, real32_t, x, .1f);
    dbind_increment(Vector, real32_t, y, .1f);
    dbind_increment(Vector, real32_t, z, .1f);

    layout = i_layout();
    panel = panel_create();
    layout_dbind(layout, listener(NULL, i_OnDataChange, void), StructTypes);
    layout_dbind_obj(layout, data, StructTypes);
    panel_data(panel, &data, i_destroy_data, StructTypes);
    panel_layout(panel, layout);
    return panel;
}

11. ¡Hola Sublayout!

Ventana de interfaz con varios controles.
Figura 12: Composición de Sublayouts.
Listado 11: howto/guihello/sublayout.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Sublayouts */
    
#include "sublayout.h"
#include "guiall.h"

/*---------------------------------------------------------------------------*/

static Layout *i_updown_layout(void)
{
    Layout *layout = layout_create(2, 1);
    Label *label = label_create();
    UpDown *updown = updown_create();
    label_text(label, "UpDown");
    layout_label(layout, label, 0, 0);
    layout_updown(layout, updown, 1, 0);
    layout_hexpand(layout, 0);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_left_grid_layout(void)
{
    Layout *layout1 = layout_create(2, 4);
    Layout *layout2 = i_updown_layout();
    Label *label = label_create();
    Button *button1 = button_push();
    Button *button2 = button_check();
    Slider *slider = slider_create();
    PopUp *popup = popup_create();
    Edit *edit = edit_create();
    Progress *progress = progress_create();
    label_text(label, "Hello!, I'm a label.");
    button_text(button1, "Push Button");
    button_text(button2, "Check Button");
    popup_add_elem(popup, "Option 1", NULL);
    popup_add_elem(popup, "Option 2", NULL);
    popup_add_elem(popup, "Option 3", NULL);
    popup_add_elem(popup, "Option 4", NULL);
    progress_undefined(progress, TRUE);
    layout_label(layout1, label, 0, 0);
    layout_button(layout1, button1, 0, 1);
    layout_button(layout1, button2, 0, 2);
    layout_slider(layout1, slider, 0, 3);
    layout_popup(layout1, popup, 1, 0);
    layout_edit(layout1, edit, 1, 1);
    layout_layout(layout1, layout2, 1, 2);
    layout_progress(layout1, progress, 1, 3);
    layout_hsize(layout1, 0, 150);
    layout_hsize(layout1, 1, 150);
    layout_hmargin(layout1, 0, 5);
    layout_vmargin(layout1, 0, 5);
    layout_vmargin(layout1, 1, 5);
    layout_vmargin(layout1, 2, 5);
    return layout1;
}

/*---------------------------------------------------------------------------*/

static Layout *i_left_layout(void)
{
    Layout *layout1 = layout_create(1, 2);
    Layout *layout2 = i_left_grid_layout();
    Button *button = button_push();
    button_text(button, "Clear");
    layout_layout(layout1, layout2, 0, 0);
    layout_button(layout1, button, 0, 1);
    layout_vmargin(layout1, 0, 5);
    return layout1;
}

/*---------------------------------------------------------------------------*/

static Layout *i_top_layout(void)
{
    Layout *layout1 = layout_create(2, 1);
    Layout *layout2 = i_left_layout();
    TextView *view = textview_create();
    layout_layout(layout1, layout2, 0, 0);
    layout_textview(layout1, view, 1, 0);
    layout_hsize(layout1, 1, 230);
    layout_hmargin(layout1, 0, 5);
    return layout1;
}

/*---------------------------------------------------------------------------*/

static Layout *i_bottom_layout(void)
{
    Layout *layout = layout_create(6, 1);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Label *label5 = label_create();
    Label *label6 = label_create();
    label_text(label1, "Select 1");
    label_text(label2, "Select 2");
    label_text(label3, "Select 3");
    label_text(label4, "Select 4");
    label_text(label5, "Select 5");
    label_text(label6, "Select 6");
    label_style_over(label1, ekFUNDERLINE);
    label_style_over(label2, ekFUNDERLINE);
    label_style_over(label3, ekFUNDERLINE);
    label_style_over(label4, ekFUNDERLINE);
    label_style_over(label5, ekFUNDERLINE);
    label_style_over(label6, ekFUNDERLINE);
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 1, 0);
    layout_label(layout, label3, 2, 0);
    layout_label(layout, label4, 3, 0);
    layout_label(layout, label5, 4, 0);
    layout_label(layout, label6, 5, 0);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_main_layout(void)
{
    Layout *layout1 = layout_create(1, 2);
    Layout *layout2 = i_top_layout();
    Layout *layout3 = i_bottom_layout();
    layout_layout(layout1, layout2, 0, 0);
    layout_layout(layout1, layout3, 0, 1);
    layout_margin(layout1, 5);
    layout_vmargin(layout1, 0, 5);
    return layout1;
}

/*---------------------------------------------------------------------------*/

Panel *sublayouts(void)
{
    Panel *panel = panel_create();
    Layout *layout = i_main_layout();
    panel_layout(panel, layout);
    return panel;
}

12. ¡Hola Subpanel!

Ventana de interfaz con varios controles.
Figura 13: Subpaneles.
Listado 12: howto/guihello/subpanel.c
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Use of subpanels */

#include "subpanel.h"
#include "guiall.h"

/*---------------------------------------------------------------------------*/

Panel *subpanels(void)
{
    Panel *panel1 = panel_create();
    Panel *panel2 = panel_create();
    Layout *layout1 = layout_create(2, 2);
    Layout *layout2 = layout_create(2, 2);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Button *button = button_push();
    Slider *slider = slider_create();
    Edit *edit = edit_create();
    label_text(label1, "Main Panel");
    label_text(label2, "Subpanel");
    button_text(button, "Push Button");
    edit_text(edit, "EditBox");

    layout_label(layout2, label2, 0, 0);
    layout_button(layout2, button, 0, 1);
    layout_slider(layout2, slider, 1, 1);
    layout_hsize(layout2, 1, 150);
    layout_hmargin(layout2, 0, 10);
    layout_vmargin(layout2, 0, 10);
    layout_margin4(layout2, 5, 10, 10, 10);
    layout_skcolor(layout2, gui_label_color());
    panel_layout(panel2, layout2);

    layout_label(layout1, label1, 0, 0);
    layout_edit(layout1, edit, 1, 1);
    layout_panel(layout1, panel2, 0, 1);
    layout_hsize(layout1, 1, 100);
    layout_hmargin(layout1, 0, 10);
    layout_vmargin(layout1, 0, 10);
    layout_margin4(layout1, 5, 10, 10, 10);
    panel_layout(panel1, layout1);
    return panel1;
}

13. ¡Hola Multi-layout!

Dos disposiciones diferentes para los mismos controles.
Figura 14: Panel con dos layouts.
Listado 13: howto/guihello/multilayout.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
/* Panels with multiple layouts */
    
#include "multilayout.h"
#include "guiall.h"

/*---------------------------------------------------------------------------*/

static Panel *i_multilayout_panel(void)
{
    Panel *panel = panel_create();
    Layout *layout1 = layout_create(2, 5);
    Layout *layout2 = layout_create(1, 10);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Label *label5 = label_create();
    Edit *edit1 = edit_create();
    Edit *edit2 = edit_create();
    Edit *edit3 = edit_create();
    Edit *edit4 = edit_create();
    Edit *edit5 = edit_create();
    label_text(label1, "User Name:");
    label_text(label2, "Password:");
    label_text(label3, "Address:");
    label_text(label4, "City:");
    label_text(label5, "Phone:");
    edit_text(edit1, "Amanda Callister");
    edit_text(edit2, "aQwe56nhjJk");
    edit_text(edit3, "35, Tuam Road");
    edit_text(edit4, "Galway - Ireland");
    edit_text(edit5, "+35 654 333 000");
    edit_passmode(edit2, TRUE);

    layout_label(layout1, label1, 0, 0);
    layout_label(layout1, label2, 0, 1);
    layout_label(layout1, label3, 0, 2);
    layout_label(layout1, label4, 0, 3);
    layout_label(layout1, label5, 0, 4);
    layout_edit(layout1, edit1, 1, 0);
    layout_edit(layout1, edit2, 1, 1);
    layout_edit(layout1, edit3, 1, 2);
    layout_edit(layout1, edit4, 1, 3);
    layout_edit(layout1, edit5, 1, 4);
    layout_hsize(layout1, 1, 300);
    layout_hmargin(layout1, 0, 5);
    layout_vmargin(layout1, 0, 5);
    layout_vmargin(layout1, 1, 5);
    layout_vmargin(layout1, 2, 5);
    layout_vmargin(layout1, 3, 5);

    layout_label(layout2, label1, 0, 0);
    layout_label(layout2, label2, 0, 2);
    layout_label(layout2, label3, 0, 4);
    layout_label(layout2, label4, 0, 6);
    layout_label(layout2, label5, 0, 8);
    layout_edit(layout2, edit1, 0, 1);
    layout_edit(layout2, edit2, 0, 3);
    layout_edit(layout2, edit3, 0, 5);
    layout_edit(layout2, edit4, 0, 7);
    layout_edit(layout2, edit5, 0, 9);
    layout_hsize(layout2, 0, 200);
    layout_vmargin(layout2, 1, 5);
    layout_vmargin(layout2, 3, 5);
    layout_vmargin(layout2, 5, 5);
    layout_vmargin(layout2, 7, 5);

    panel_layout(panel, layout1);
    panel_layout(panel, layout2);
    return panel;
}

/*---------------------------------------------------------------------------*/

static void i_OnLayout(Panel *panel, Event *e)
{
    const EvButton *params = event_params(e, EvButton);
    panel_visible_layout(panel, params->index);
    panel_update(panel);
}

/*---------------------------------------------------------------------------*/

Panel *multilayouts(void)
{
    Panel *panel1 = panel_create();
    Panel *panel2 = i_multilayout_panel();
    Button *button1 = button_radio();
    Button *button2 = button_radio();
    Layout *layout1 = layout_create(1, 2);
    Layout *layout2 = layout_create(2, 1);
    button_text(button1, "Layout1");
    button_text(button2, "Layout2");
    button_state(button1, ekON);
    button_OnClick(button1, listener(panel2, i_OnLayout, Panel));
    layout_button(layout2, button1, 0, 0);
    layout_button(layout2, button2, 1, 0);
    layout_layout(layout1, layout2, 0, 0);
    layout_panel(layout1, panel2, 0, 1);
    layout_vmargin(layout1, 0, 10);
    layout_hmargin(layout2, 0, 10);
    layout_halign(layout1, 0, 0, ekLEFT);
    panel_layout(panel1, layout1);
    return panel1;
}

14. ¡Hola Scroll-Panel!

Panel con una área muy grande y barras de scroll.
Figura 15: Panel con barras de scroll.
Listado 14: howto/guihello/scrollpanel.c
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Panel with scroll */
    
#include "scrollpanel.h"
#include "guiall.h"

static const uint32_t i_ROWS = 100;

/*---------------------------------------------------------------------------*/

Panel *scrollpanel(void)
{
    Panel *panel = panel_scroll(FALSE, TRUE);
    Layout *layout = layout_create(3, i_ROWS);
    real32_t margin = panel_scroll_width(panel);
    uint32_t i = 0;
    panel_size(panel, s2df(-1, 400));
    for (i = 0; i < i_ROWS; ++i)
    {
        char_t text[128];
        Label *label = label_create();
        Edit *edit = edit_create();
        Button *button = button_push();
        bstd_sprintf(text, sizeof(text), "User %d", i + 1);
        label_text(label, text);
        bstd_sprintf(text, sizeof(text), "Name of User %d", i + 1);
        edit_text(edit, text);
        bstd_sprintf(text, sizeof(text), "Edit %d", i + 1);
        button_text(button, text);
        layout_label(layout, label, 0, i);
        layout_edit(layout, edit, 1, i);
        layout_button(layout, button, 2, i);
    }

    for (i = 0; i < i_ROWS - 1; ++i)
        layout_vmargin(layout, i, 5);

    layout_hmargin(layout, 0, 10);
    layout_hmargin(layout, 1, 10);
    layout_hsize(layout, 1, 150);
    layout_margin4(layout, 0, margin, 0, 0);
    panel_layout(panel, layout);
    return panel;
}
❮ Anterior
Siguiente ❯