change layout state from boolean to enum

This commit is contained in:
vurtun 2015-05-23 21:09:38 +02:00
parent b6216ca078
commit 4f13eecbcb
4 changed files with 18 additions and 30 deletions

View File

@ -420,10 +420,7 @@ a tiled layout is the other. Tiled layouts divide the screen into regions called
slots in this case the top, left, center, right and bottom slot. Each slot occupies a
certain percentage on the screen and can be filled with panels either
horizontally or vertically. The combination of slots, ratio and multiple panels
per slots support a rich set of vertical, horizontal and mixed layouts. Biggest
disadvantage of tiled layouts are the percentage based dividing of space since the
right formating works best for a fixed size destination screen space. So the
target application lies in fullscreen tools and editors.
per slots support a rich set of vertical, horizontal and mixed layouts.
```c
struct your_window {
@ -455,7 +452,7 @@ while (1) {
/* record input */
gui_input_end(&input);
gui_layout_begin(&tiled, window_width, window_height, gui_true);
gui_layout_begin(&tiled, window_width, window_height, GUI_LAYOUT_ACTIVE);
gui_layout_slot(&tiled, GUI_SLOT_LEFT, GUI_LAYOUT_VERTICAL, 1);
gui_buffer_begin(&canvas, &buffer, window_width, window_height);

View File

@ -68,24 +68,6 @@ struct font {
const struct font_glyph *fallback;
};
struct demo {
gui_char in_buf[MAX_BUFFER];
gui_size in_len;
gui_bool in_act;
gui_bool check;
gui_int option;
gui_float slider;
gui_size prog;
gui_int spinner;
gui_bool spin_act;
gui_size item_cur;
gui_size cur;
gui_bool tab_min;
gui_float group_off;
gui_float shelf_off;
gui_bool toggle;
};
static void
die(const char *fmt, ...)
{
@ -574,7 +556,7 @@ main(int argc, char *argv[])
glContext = SDL_GL_CreateContext(win);
SDL_GetWindowSize(win, &win_width, &win_height);
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glfont = font_new(font_path, 10, 12, 255, FONT_ATLAS_DIM_256);
glfont = font_new(font_path, 10, 10, 255, FONT_ATLAS_DIM_256);
/* GUI */
memset(&in, 0, sizeof in);

12
gui.c
View File

@ -323,9 +323,12 @@ gui_text(const struct gui_canvas *canvas, gui_float x, gui_float y, gui_float w,
ASSERT(text);
if (!text) return;
text_width = font->width(font->userdata, (const gui_char*)string, len);
/* calculate y position + height */
label_y = y + text->padding.y;
label_h = MAX(0, h - 2 * text->padding.y);
/* calculate text x position and width */
text_width = font->width(font->userdata, (const gui_char*)string, len);
if (align == GUI_TEXT_LEFT) {
label_x = x + text->padding.x;
label_w = MAX(0, w - 2 * text->padding.x);
@ -339,6 +342,7 @@ gui_text(const struct gui_canvas *canvas, gui_float x, gui_float y, gui_float w,
label_w = (gui_float)text_width + 2 * text->padding.x;
} else return;
/* draw background + text */
canvas->draw_rect(canvas->userdata, x, y, w, h, text->background);
canvas->draw_text(canvas->userdata, label_x, label_y, label_w, label_h,
(const gui_char*)string, len, font, text->background, text->foreground);
@ -1776,7 +1780,7 @@ gui_panel_hook_begin_tiled(struct gui_panel_layout *tile, struct gui_panel_hook
panel->y = bounds.y + (gui_float)index * panel->h;
}
gui_stack_push(&layout->stack, hook);
return gui_panel_begin(tile, panel, title, canvas, (layout->active) ? in : NULL);
return gui_panel_begin(tile, panel, title, canvas, (layout->state) ? in : NULL);
}
void
@ -3147,13 +3151,13 @@ gui_layout_init(struct gui_layout *layout, const struct gui_layout_config *confi
void
gui_layout_begin(struct gui_layout *layout, gui_size width, gui_size height,
gui_bool active)
enum gui_layout_state state)
{
ASSERT(layout);
if (!layout) return;
layout->width = width;
layout->height = height;
layout->active = active;
layout->state = state;
}
void

9
gui.h
View File

@ -495,6 +495,11 @@ struct gui_panel_stack {
/* Layout */
enum gui_layout_state {
GUI_LAYOUT_INACTIVE,
GUI_LAYOUT_ACTIVE
};
enum gui_layout_slot_index {
GUI_SLOT_TOP,
GUI_SLOT_BOTTOM,
@ -526,9 +531,9 @@ struct gui_layout_slot {
};
struct gui_layout {
gui_bool active;
gui_flags flags;
gui_size width, height;
enum gui_layout_state state;
struct gui_panel_stack stack;
struct gui_layout_slot slots[GUI_SLOT_MAX];
};
@ -727,7 +732,7 @@ void gui_stack_pop(struct gui_panel_stack*, struct gui_panel_hook*);
/* Layout */
void gui_layout_init(struct gui_layout*, const struct gui_layout_config*);
void gui_layout_begin(struct gui_layout*, gui_size width, gui_size height, gui_bool active);
void gui_layout_begin(struct gui_layout*, gui_size width, gui_size height, enum gui_layout_state);
void gui_layout_end(struct gui_panel_stack*, struct gui_layout*);
void gui_layout_slot(struct gui_layout*, enum gui_layout_slot_index,
enum gui_layout_format, gui_size panel_count);