示例#1
0
文件: demo.c 项目: island-org/gui
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");
        }
    }
}
示例#2
0
文件: demo.c 项目: island-org/gui
static void
combobox_panel(struct gui_panel_layout *panel, struct show_window *demo)
{
    gui_int i = 0;
    static const char *options[] = {"easy", "normal", "hard", "hell", "doom", "godlike"};
    gui_panel_row(panel, 30, 3);
    for (i = 0; i < (gui_int)LEN(options); i++) {
        if (gui_panel_option(panel, options[i], demo->combo_selection == i))
            demo->combo_selection = i;
    }
}
示例#3
0
文件: demo.c 项目: serge-rgb/gui
/* -----------------------------------------------------------------
 *  RUN
 * ----------------------------------------------------------------- */
static void
run_demo(struct demo_gui *gui)
{
    struct gui_panel_layout layout;
    struct state *state = &gui->state;
    struct gui_panel_layout tab;
    struct gui_config *config = &gui->config;

    /* first panel */
    gui_panel_begin(&layout, &gui->panel);
    {
        /* header */
        gui->running = !gui_panel_header(&layout, "Demo",
            GUI_CLOSEABLE|GUI_MINIMIZABLE, GUI_CLOSEABLE, GUI_HEADER_RIGHT);

        /* menubar */
        gui_panel_menubar_begin(&layout);
        {
            gui_int sel;
            gui_panel_row_begin(&layout, GUI_STATIC, 25, 2);
            {
                gui_panel_row_push(&layout, config->font.width(config->font.userdata, "__FILE__", 8));
                sel = gui_panel_menu(&layout, "FILE", file_items, LEN(file_items), 25, 100,
                    &state->file_open, gui_vec2(0,0));
                switch (sel) {
                case MENU_FILE_OPEN:
                    fprintf(stdout, "[Menu:File] open clicked!\n"); break;
                case MENU_FILE_CLOSE:
                    fprintf(stdout, "[Menu:File] close clicked!\n"); break;
                case MENU_FILE_QUIT:
                    fprintf(stdout, "[Menu:File] quit clicked!\n"); break;
                case GUI_NONE:
                default: break;
                }

                gui_panel_row_push(&layout, config->font.width(config->font.userdata, "__EDIT__", 8));
                sel = gui_panel_menu(&layout, "EDIT", edit_items, LEN(edit_items), 25, 100,
                    &state->edit_open, gui_vec2(0,0));
                switch (sel) {
                case MENU_EDIT_COPY:
                    fprintf(stdout, "[Menu:Edit] copy clicked!\n"); break;
                case MENU_EDIT_CUT:
                    fprintf(stdout, "[Menu:Edit] cut clicked!\n"); break;
                case MENU_EDIT_DELETE:
                    fprintf(stdout, "[Menu:Edit] delete clicked!\n"); break;
                case MENU_EDIT_PASTE:
                    fprintf(stdout, "[Menu:Edit] paste clicked!\n"); break;
                case GUI_NONE:
                default: break;
                }
            }
            gui_panel_row_end(&layout);
        }
        gui_panel_menubar_end(&layout);

        /* panel style configuration  */
        if (gui_panel_layout_push(&layout, GUI_LAYOUT_TAB, "Style", &state->config_tab))
        {
            if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Options", &state->flag_tab)) {
                update_flags(&layout);
                gui_panel_layout_pop(&layout);
            }
            if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Properties", &state->style_tab)) {
                properties_tab(&layout, config);
                gui_panel_layout_pop(&layout);
            }
            if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Rounding", &state->round_tab)) {
                round_tab(&layout, config);
                gui_panel_layout_pop(&layout);
            }
            if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Color", &state->color_tab)) {
                color_tab(&layout, state, config);
                gui_panel_layout_pop(&layout);
            }
            gui_panel_layout_pop(&layout);
        }

        /* widgets examples */
        if (gui_panel_layout_push(&layout, GUI_LAYOUT_TAB, "Widgets", &state->widget_tab)) {
            widget_panel(&layout, state);
            gui_panel_layout_pop(&layout);
        }

        /* popup panel */
        if (state->popup) {
            gui_panel_popup_begin(&layout, &tab, GUI_POPUP_STATIC, gui_rect(20, 100, 220, 150), gui_vec2(0,0));
            {
                if (gui_panel_header(&tab, "Popup", GUI_CLOSEABLE, GUI_CLOSEABLE, GUI_HEADER_LEFT)) {
                    gui_panel_popup_close(&tab);
                    state->popup = gui_false;
                }
                gui_panel_row_dynamic(&tab, 30, 1);
                gui_panel_label(&tab, "Are you sure you want to exit?", GUI_TEXT_LEFT);
                gui_panel_row_dynamic(&tab, 30, 4);
                gui_panel_spacing(&tab, 1);
                if (gui_panel_button_text(&tab, "Yes", GUI_BUTTON_DEFAULT)) {
                    gui_panel_popup_close(&tab);
                    state->popup = gui_false;
                }
                if (gui_panel_button_text(&tab, "No", GUI_BUTTON_DEFAULT)) {
                    gui_panel_popup_close(&tab);
                    state->popup = gui_false;
                }
            }
            gui_panel_popup_end(&layout, &tab);
        }

        {
            /* shelf + graphes  */
            static const char *shelfs[] = {"Histogram", "Lines"};
            gui_panel_row_dynamic(&layout, 180, 1);
            state->shelf_selection = gui_panel_shelf_begin(&layout, &tab, shelfs,
                LEN(shelfs), state->shelf_selection, state->shelf);
            graph_panel(&tab, state->shelf_selection);
            state->shelf = gui_panel_shelf_end(&layout, &tab);
        }

        /* tables */
        gui_panel_row_dynamic(&layout, 180, 1);
        gui_panel_group_begin(&layout, &tab, "Table", state->table);
        table_panel(&tab);
        state->table = gui_panel_group_end(&layout, &tab);

        {
            /* tree */
            struct gui_tree tree;
            gui_panel_row_dynamic(&layout, 250, 1);
            gui_panel_tree_begin(&layout, &tree, "Tree", 20, state->tree);
            upload_tree(&state->test, &tree, &state->test.root);
            state->tree = gui_panel_tree_end(&layout, &tree);
        }
    }
    gui_panel_end(&layout, &gui->panel);

    /* second panel */
    gui_panel_begin(&layout, &gui->sub);
    {
        enum {EASY, HARD};
        gui_panel_header(&layout, "Show", GUI_CLOSEABLE, 0, GUI_HEADER_LEFT);
        gui_panel_row_static(&layout, 30, 80, 1);
        if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT)) {
            /* event handling */
        }
        gui_panel_row_dynamic(&layout, 30, 2);
        if (gui_panel_option(&layout, "easy", state->op == EASY)) state->op = EASY;
        if (gui_panel_option(&layout, "hard", state->op == HARD)) state->op = HARD;
    }
    gui_panel_end(&layout, &gui->sub);
}
示例#4
0
文件: demo.c 项目: serge-rgb/gui
/* -----------------------------------------------------------------
 *  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);
    }
}