extended tiled layout with horizontal and verticl spliting for panels in slots
This commit is contained in:
parent
9e607406ba
commit
760c8d3736
25
Readme.md
25
Readme.md
|
@ -367,7 +367,6 @@ struct your_window {
|
|||
}
|
||||
|
||||
struct gui_memory memory = {...};
|
||||
struct gui_memory_status status;
|
||||
struct gui_command_buffer buffer;
|
||||
gui_buffer_init_fixed(buffer, &memory);
|
||||
|
||||
|
@ -396,7 +395,7 @@ while (1) {
|
|||
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT))
|
||||
fprintf(stdout, "button pressed!\n");
|
||||
gui_panel_hook_end(&layout, &win.hook);
|
||||
gui_buffer_end(gui_hook_output(&win.hook), buffer, &status);
|
||||
gui_buffer_end(gui_hook_output(&win.hook), buffer, NULL);
|
||||
|
||||
/* draw each panel */
|
||||
struct gui_panel_hook *iter;
|
||||
|
@ -411,11 +410,14 @@ while (1) {
|
|||
|
||||
### Tiling
|
||||
Stacked windows are only one side of the coin for panel layouts while
|
||||
a tiled layout is the other. Tiled layout divide the screen into regions in this
|
||||
case the top, left, center, right and bottom region. Each region occupies a
|
||||
certain percentage on the screen and can be filled with panels. The combination
|
||||
of regions, ratio and multiple panels per region support a rich set of vertical,
|
||||
horizontal and mixed layout.
|
||||
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.
|
||||
|
||||
```c
|
||||
struct your_window {
|
||||
|
@ -424,14 +426,13 @@ struct your_window {
|
|||
}
|
||||
|
||||
struct gui_memory memory = {...};
|
||||
struct gui_memory_status status;
|
||||
struct gui_command_buffer buffer;
|
||||
gui_buffer_init_fixed(buffer, &memory);
|
||||
|
||||
struct your_window win;
|
||||
struct gui_config config;
|
||||
struct gui_font font = {...}
|
||||
struct gui_input input = {0};
|
||||
struct your_window win;
|
||||
gui_default_config(&config);
|
||||
gui_panel_hook_init(&win.hook, 0, 0, 0, 0, 0, &config, &font);
|
||||
|
||||
|
@ -449,7 +450,7 @@ while (1) {
|
|||
gui_input_end(&input);
|
||||
|
||||
gui_layout_begin(&tiled, window_width, window_height, gui_true);
|
||||
gui_layout_slot(&tiled, GUI_SLOT_LEFT, 1);
|
||||
gui_layout_slot(&tiled, GUI_SLOT_LEFT, GUI_LAYOUT_VERTICAL, 1);
|
||||
|
||||
gui_buffer_begin(&canvas, &buffer, window_width, window_height);
|
||||
gui_panel_hook_begin_tiled(&layout, &win.hook, &tiled, GUI_SLOT_LEFT, 0, "Demo", &canvas, &input);
|
||||
|
@ -457,7 +458,7 @@ while (1) {
|
|||
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT))
|
||||
fprintf(stdout, "button pressed!\n");
|
||||
gui_panel_hook_end(&layout, &win.hook);
|
||||
gui_buffer_end(gui_hook_output(&win.hook), buffer, &status);
|
||||
gui_buffer_end(gui_hook_output(&win.hook), buffer, NULL);
|
||||
|
||||
gui_layout_end(&stack, &tiled);
|
||||
|
||||
|
@ -477,7 +478,7 @@ while (1) {
|
|||
The demo and example code can be found in the demo folder.
|
||||
There is demo code for Linux(X11), Windows(win32) and OpenGL(SDL2, freetype).
|
||||
As for now there will be no DirectX demo since I don't have experience
|
||||
programming with DirectX but you are more than welcome to provide one.
|
||||
programming using DirectX but you are more than welcome to provide one.
|
||||
|
||||
#### Why did you use ANSI C and not C99 or C++?
|
||||
Personally I stay out of all "discussions" about C vs C++ since they are totally
|
||||
|
|
|
@ -591,7 +591,7 @@ background_demo(struct demo_gui *gui, struct gui_input *input, struct gui_comman
|
|||
struct settings_window *settings = &gui->settings;
|
||||
|
||||
gui_layout_begin(&gui->layout, gui->width, gui->height, active);
|
||||
gui_layout_slot(&gui->layout, GUI_SLOT_RIGHT, 1);
|
||||
gui_layout_slot(&gui->layout, GUI_SLOT_RIGHT, GUI_LAYOUT_VERTICAL, 1);
|
||||
|
||||
gui_buffer_lock(&canvas, buffer, &sub, 0, gui->width, gui->height);
|
||||
update_settings(&gui->settings, &gui->layout, input, &canvas);
|
||||
|
|
18
gui.c
18
gui.c
|
@ -1629,10 +1629,17 @@ gui_panel_hook_begin_tiled(struct gui_panel_layout *tile, struct gui_panel_hook
|
|||
bounds.w = s->ratio.x * (gui_float)layout->width;
|
||||
bounds.h = s->ratio.y * (gui_float)layout->height;
|
||||
|
||||
panel->x = bounds.x;
|
||||
panel->w = bounds.w;
|
||||
panel->h = bounds.h / (gui_float)s->capacity;
|
||||
panel->y = bounds.y + (gui_float)index * panel->h;
|
||||
if (s->format == GUI_LAYOUT_HORIZONTAL) {
|
||||
panel->h = bounds.h;
|
||||
panel->y = bounds.y;
|
||||
panel->x = bounds.x + (gui_float)index * panel->w;
|
||||
panel->w = bounds.w / (gui_float)s->capacity;
|
||||
} else {
|
||||
panel->x = bounds.x;
|
||||
panel->w = bounds.w;
|
||||
panel->h = bounds.h / (gui_float)s->capacity;
|
||||
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);
|
||||
}
|
||||
|
@ -2929,12 +2936,13 @@ gui_layout_end(struct gui_panel_stack *stack, struct gui_layout *layout)
|
|||
|
||||
void
|
||||
gui_layout_slot(struct gui_layout *layout, enum gui_layout_slot_index slot,
|
||||
gui_size count)
|
||||
enum gui_layout_format format, gui_size count)
|
||||
{
|
||||
ASSERT(layout);
|
||||
ASSERT(count);
|
||||
ASSERT(slot >= GUI_SLOT_TOP && slot < GUI_SLOT_MAX);
|
||||
if (!layout || !count) return;
|
||||
layout->slots[slot].capacity = count;
|
||||
layout->slots[slot].format = format;
|
||||
}
|
||||
|
||||
|
|
20
gui.h
20
gui.h
|
@ -471,6 +471,11 @@ enum gui_layout_slot_index {
|
|||
GUI_SLOT_MAX
|
||||
};
|
||||
|
||||
enum gui_layout_format {
|
||||
GUI_LAYOUT_HORIZONTAL,
|
||||
GUI_LAYOUT_VERTICAL
|
||||
};
|
||||
|
||||
struct gui_layout_config {
|
||||
gui_float left;
|
||||
gui_float right;
|
||||
|
@ -484,6 +489,7 @@ struct gui_layout_slot {
|
|||
gui_size capacity;
|
||||
struct gui_vec2 ratio;
|
||||
struct gui_vec2 offset;
|
||||
enum gui_layout_format format;
|
||||
};
|
||||
|
||||
struct gui_layout {
|
||||
|
@ -652,14 +658,15 @@ void gui_panel_end(struct gui_panel_layout*, struct gui_panel*);
|
|||
#define gui_hook_panel(h) (&((h)->GUI_HOOK_PANEL_NAME))
|
||||
#define gui_hook_output(h) (&((h)->GUI_HOOK_OUTPUT_NAME))
|
||||
#define gui_panel_hook_init(hook, x, y, w, h, flags, config, font)\
|
||||
gui_panel_init(gui_hook_panel(hook), x, y, w, h, flags, config, font)
|
||||
gui_panel_init(gui_hook_panel(hook), x, y, w, h, flags, config, font)
|
||||
gui_bool gui_panel_hook_begin_stacked(struct gui_panel_layout*, struct gui_panel_hook*,
|
||||
struct gui_panel_stack*, const char*, const struct gui_canvas*, const struct gui_input*);
|
||||
struct gui_panel_stack*, const char*, const struct gui_canvas*,
|
||||
const struct gui_input*);
|
||||
gui_bool gui_panel_hook_begin_tiled(struct gui_panel_layout*, struct gui_panel_hook*,
|
||||
struct gui_layout*, enum gui_layout_slot_index, gui_size index, const char*,
|
||||
const struct gui_canvas*, const struct gui_input*);
|
||||
struct gui_layout*, enum gui_layout_slot_index, gui_size index, const char*,
|
||||
const struct gui_canvas*, const struct gui_input*);
|
||||
#define gui_panel_hook_end(layout, hook)\
|
||||
gui_panel_end((layout), gui_hook_panel(hook))
|
||||
gui_panel_end((layout), gui_hook_panel(hook))
|
||||
|
||||
/* Stack */
|
||||
#define gui_stack_begin(s) ((s)->begin)
|
||||
|
@ -673,7 +680,8 @@ void gui_stack_pop(struct gui_panel_stack*, struct gui_panel_hook*);
|
|||
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_end(struct gui_panel_stack*, struct gui_layout*);
|
||||
void gui_layout_slot(struct gui_layout*, enum gui_layout_slot_index, gui_size panel_count);
|
||||
void gui_layout_slot(struct gui_layout*, enum gui_layout_slot_index,
|
||||
enum gui_layout_format, gui_size panel_count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue