Beispiel #1
0
static void
widget_panel(struct gui_panel_layout *panel, struct show_window *demo)
{
    const char *items[] = {"Fist", "Pistol", "Shotgun", "Railgun", "BFG"};
    gui_panel_row(panel, 30, 1);
    gui_panel_label(panel, "text left", GUI_TEXT_LEFT);
    gui_panel_label(panel, "text center", GUI_TEXT_CENTERED);
    gui_panel_label(panel, "text right", GUI_TEXT_RIGHT);
    if (gui_panel_button_text(panel, "button", GUI_BUTTON_DEFAULT))
        fprintf(stdout, "button pressed!\n");
    if (gui_panel_button_text_triangle(panel, GUI_RIGHT, "next", GUI_TEXT_LEFT, GUI_BUTTON_DEFAULT))
        fprintf(stdout, "right triangle button pressed!\n");
    if (gui_panel_button_text_triangle(panel,GUI_LEFT,"previous",GUI_TEXT_RIGHT,GUI_BUTTON_DEFAULT))
        fprintf(stdout, "left triangle button pressed!\n");
    demo->toggle = gui_panel_button_toggle(panel, "toggle", demo->toggle);
    demo->checkbox = gui_panel_check(panel, "checkbox", demo->checkbox);

    gui_panel_row(panel, 30, 2);
    if (gui_panel_option(panel, "option 0", demo->option == 0)) demo->option = 0;
    if (gui_panel_option(panel, "option 1", demo->option == 1)) demo->option = 1;

    {
        char buffer[MAX_BUFFER];
        const gui_float ratio[] = {0.8f, 0.2f};
        gui_panel_row_templated(panel, 30, 2, ratio);
        demo->slider = gui_panel_slider(panel, 0, demo->slider, 10, 1.0f);
        sprintf(buffer, "%.2f", demo->slider);
        gui_panel_label(panel, buffer, GUI_TEXT_LEFT);
        demo->progressbar = gui_panel_progress(panel, demo->progressbar, 100, gui_true);
        sprintf(buffer, "%lu", demo->progressbar);
        gui_panel_label(panel, buffer, GUI_TEXT_LEFT);
    }

    gui_panel_row(panel, 30, 1);
    demo->item_current = gui_panel_selector(panel, items, LEN(items), demo->item_current);
    demo->spinner = gui_panel_spinner(panel, 0, demo->spinner, 250, 10, &demo->spinner_active);

    {
        const gui_float ratio[] = {0.7f, 0.3f};
        gui_panel_row_templated(panel, 30, 2, ratio);
        demo->input_length = gui_panel_edit(panel, demo->input_buffer, demo->input_length,
            MAX_BUFFER, &demo->input_active, GUI_INPUT_DEFAULT);
        if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) {
            demo->input_length = 0;
            fprintf(stdout, "command executed!\n");
        }
    }
}
Beispiel #2
0
/* -----------------------------------------------------------------
 *  WIDGETS
 * ----------------------------------------------------------------- */
static void
widget_panel(struct gui_panel_layout *panel, struct state *demo)
{
    /* Labels */
    gui_panel_row_dynamic(panel, 30, 1);
    demo->scaleable = gui_panel_check(panel, "Scaleable Layout", demo->scaleable);
    if (!demo->scaleable)
        gui_panel_row_static(panel, 30, 150, 1);
    gui_panel_label(panel, "text left", GUI_TEXT_LEFT);
    gui_panel_label(panel, "text center", GUI_TEXT_CENTERED);
    gui_panel_label(panel, "text right", GUI_TEXT_RIGHT);

    /* Buttons */
    if (gui_panel_button_text(panel, "button", GUI_BUTTON_DEFAULT))
        demo->popup = gui_true;
    if (gui_panel_button_text_triangle(panel, GUI_RIGHT, "next", GUI_TEXT_LEFT, GUI_BUTTON_DEFAULT))
        fprintf(stdout, "right triangle button pressed!\n");
    if (gui_panel_button_text_triangle(panel,GUI_LEFT,"previous",GUI_TEXT_RIGHT,GUI_BUTTON_DEFAULT))
        fprintf(stdout, "left triangle button pressed!\n");
    demo->toggle = gui_panel_button_toggle(panel, "toggle", demo->toggle);

    /* checkbox + radio buttons */
    demo->checkbox = gui_panel_check(panel, "checkbox", demo->checkbox);
    if (!demo->scaleable)
        gui_panel_row_static(panel, 30, 75, 2);
    else  gui_panel_row_dynamic(panel, 30, 2);
    if (gui_panel_option(panel, "option 0", demo->option == 0))
        demo->option = 0;
    if (gui_panel_option(panel, "option 1", demo->option == 1))
        demo->option = 1;

    {
        /* retain mode custom row layout */
        const gui_float ratio[] = {0.8f, 0.2f};
        const gui_float pixel[] = {150.0f, 30.0f};
        enum gui_panel_row_layout_format fmt = (demo->scaleable) ? GUI_DYNAMIC : GUI_STATIC;
        gui_panel_row(panel, fmt, 30, 2, (fmt == GUI_DYNAMIC) ? ratio: pixel);
        demo->slider = gui_panel_slider(panel, 0, demo->slider, 10, 1.0f);
        gui_panel_labelf(panel, GUI_TEXT_LEFT, "%.2f", demo->slider);
        demo->progressbar = gui_panel_progress(panel, demo->progressbar, 100, gui_true);
        gui_panel_labelf(panel, GUI_TEXT_LEFT, "%lu", demo->progressbar);
    }

    /* item selection  */
    if (!demo->scaleable) gui_panel_row_static(panel, 30, 150, 1);
    else gui_panel_row_dynamic(panel, 30, 1);
    demo->item_current = gui_panel_selector(panel, weapons, LEN(weapons), demo->item_current);

    combo_box(panel, &demo->combo, weapons, LEN(weapons));
    prog_combo_box(panel, demo->prog_values, LEN(demo->prog_values), &demo->progcom);
    color_combo_box(panel, &demo->colcom);
    check_combo_box(panel, demo->check_values, LEN(demo->check_values), &demo->checkcom);
    demo->spinner = gui_panel_spinner_int(panel, 0, demo->spinner, 250, 10, &demo->spinner_active);

    {
        /* immediate mode custom row layout */
        enum gui_panel_row_layout_format fmt = (demo->scaleable) ? GUI_DYNAMIC : GUI_STATIC;
        gui_panel_row_begin(panel, fmt, 30, 2);
        {
            gui_panel_row_push(panel,(fmt == GUI_DYNAMIC) ? 0.7f : 100);
            gui_panel_editbox(panel, &demo->edit);
            gui_panel_row_push(panel, (fmt == GUI_DYNAMIC) ? 0.3f : 80);
            if (gui_panel_button_text(panel, "submit", GUI_BUTTON_DEFAULT)) {
                gui_edit_box_clear(&demo->edit);
                fprintf(stdout, "command executed!\n");
            }
        }
        gui_panel_row_end(panel);
    }
}