converted if/elese to switch + fixed some typos
This commit is contained in:
parent
a3a25eb0c5
commit
322bb21b9c
@ -27,12 +27,12 @@ for a as pure functional as possible set of widgets functions without
|
||||
any kind of internal state, with the tradeoff off of a lot of boilerplate code.
|
||||
Second the panel layer for a static grouping of widgets into a panel with a reduced need for
|
||||
a lot of the boilerplate code but takes away some freedom of widget placing and
|
||||
introduces the state of the pannel.
|
||||
introduces the state of the panel.
|
||||
Finally there is the context layer which represent the complete window and
|
||||
enables moveable, scaleable and overlapping panels, but needs complete control
|
||||
over the panel management and therefore needs the most amount of internal state.
|
||||
Each higher level of astraction uses the lower level(s) internally to build
|
||||
on but offers a little bit of a different API.
|
||||
Each higher level of abstraction uses the lower level(s) internally to build
|
||||
on but offers a little bit different API.
|
||||
|
||||
## Configuration
|
||||
The gui toolkit provides a number of different attributes that can be
|
||||
@ -42,7 +42,7 @@ for each and every widget the higher layers provide you with a set of
|
||||
attributes in the `gui_config` structure. The structure either needs to be
|
||||
filled by the user or can be setup with some default values by the function
|
||||
`gui_default_config`. Modification on the fly to the `gui_config` is in
|
||||
in true immedate mode fashion possible and supported.
|
||||
true immedate mode fashion possible and supported.
|
||||
|
||||
## FAQ
|
||||
#### Where is Widget X?
|
||||
|
25
demo/xlib.c
25
demo/xlib.c
@ -366,40 +366,51 @@ execute(XSurface *surf, const struct gui_command_list *list)
|
||||
if (!list->count) return;
|
||||
iter = list->begin;
|
||||
while (iter != list->end) {
|
||||
if (iter->type == GUI_COMMAND_CLIP) {
|
||||
switch (iter->type) {
|
||||
case GUI_COMMAND_NOP: break;
|
||||
case GUI_COMMAND_CLIP: {
|
||||
const struct gui_command_clip *clip = (const struct gui_command_clip*)iter;
|
||||
surface_scissor(surf, (int)clip->x, (int)clip->y,
|
||||
(unsigned int)clip->w, (unsigned int)clip->h);
|
||||
} else if (iter->type == GUI_COMMAND_LINE) {
|
||||
} break;
|
||||
case GUI_COMMAND_LINE: {
|
||||
const struct gui_command_line *line = (const struct gui_command_line*)iter;
|
||||
const unsigned long color = color_from_byte(line->color);
|
||||
surface_draw_line(surf, (int)line->from.x, (int)line->from.y,
|
||||
(int)line->to.x, (int)line->to.y, color);
|
||||
} else if (iter->type == GUI_COMMAND_RECT) {
|
||||
} break;
|
||||
case GUI_COMMAND_RECT: {
|
||||
const struct gui_command_rect *rect = (const struct gui_command_rect*)iter;
|
||||
const unsigned long color = color_from_byte(rect->color);
|
||||
surface_draw_rect(surf, (int)rect->x, (int)rect->y,
|
||||
(unsigned int)rect->w, (unsigned int)rect->h, color);
|
||||
} else if (iter->type == GUI_COMMAND_CIRCLE) {
|
||||
} break;
|
||||
case GUI_COMMAND_CIRCLE: {
|
||||
const struct gui_command_circle *circle = (const struct gui_command_circle*)iter;
|
||||
const unsigned long color = color_from_byte(circle->color);
|
||||
surface_draw_circle(surf, (int)circle->x, (int)circle->y,
|
||||
(unsigned int)circle->radius, color);
|
||||
} else if (iter->type == GUI_COMMAND_BITMAP) {
|
||||
} break;
|
||||
case GUI_COMMAND_BITMAP: {
|
||||
const struct gui_command_bitmap *bitmap = (const struct gui_command_bitmap*)iter;
|
||||
} else if (iter->type == GUI_COMMAND_TRIANGLE) {
|
||||
} break;
|
||||
case GUI_COMMAND_TRIANGLE: {
|
||||
const struct gui_command_triangle *triangle = (const struct gui_command_triangle*)iter;
|
||||
const unsigned long color = color_from_byte(triangle->color);
|
||||
surface_draw_triangle(surf, (int)triangle->pnt[0].x, (int)triangle->pnt[0].y,
|
||||
(int)triangle->pnt[1].x, (int)triangle->pnt[1].y, (int)triangle->pnt[2].x,
|
||||
(int)triangle->pnt[2].y, color);
|
||||
} else if (iter->type == GUI_COMMAND_TEXT) {
|
||||
} break;
|
||||
case GUI_COMMAND_TEXT: {
|
||||
const struct gui_command_text *text = (const struct gui_command_text*)iter;
|
||||
const unsigned long bg = color_from_byte(text->background);
|
||||
const unsigned long fg = color_from_byte(text->foreground);
|
||||
surface_draw_text(surf, text->font, (int)text->x, (int)text->y,
|
||||
(unsigned int)text->w, (unsigned int)text->h,
|
||||
(const char*)text->string, (unsigned int)text->length, bg, fg);
|
||||
} break;
|
||||
case GUI_COMMAND_MAX: break;
|
||||
default: break;
|
||||
}
|
||||
iter = iter->next;
|
||||
}
|
||||
|
27
gui.c
27
gui.c
@ -124,17 +124,15 @@ itos(char *buffer, gui_int num)
|
||||
return len;
|
||||
}
|
||||
|
||||
static struct gui_rect
|
||||
unify(const struct gui_rect *a, const struct gui_rect *b)
|
||||
static void
|
||||
unify(struct gui_rect *clip, const struct gui_rect *a, const struct gui_rect *b)
|
||||
{
|
||||
struct gui_rect clip;
|
||||
clip.x = MAX(a->x, b->x);
|
||||
clip.y = MAX(a->y, b->y);
|
||||
clip.w = MIN(a->x + a->w, b->x + b->w) - clip.x;
|
||||
clip.h = MIN(a->y + a->h, b->y + b->h) - clip.y;
|
||||
clip.w = MAX(0, clip.w);
|
||||
clip.h = MAX(0, clip.h);
|
||||
return clip;
|
||||
clip->x = MAX(a->x, b->x);
|
||||
clip->y = MAX(a->y, b->y);
|
||||
clip->w = MIN(a->x + a->w, b->x + b->w) - clip->x;
|
||||
clip->h = MIN(a->y + a->h, b->y + b->h) - clip->y;
|
||||
clip->w = MAX(0, clip->w);
|
||||
clip->h = MAX(0, clip->h);
|
||||
}
|
||||
|
||||
static gui_size
|
||||
@ -396,7 +394,7 @@ gui_buffer_push_clip(struct gui_command_buffer *buffer, const struct gui_rect *r
|
||||
|
||||
cmd = gui_buffer_push(buffer, GUI_COMMAND_CLIP, sizeof(*cmd));
|
||||
if (!cmd) return gui_false;
|
||||
clip = unify(rect, (!buffer->clip_size) ? &null_rect : &buffer->clips[buffer->clip_size-1]);
|
||||
unify(&clip, rect, (!buffer->clip_size) ? &null_rect : &buffer->clips[buffer->clip_size-1]);
|
||||
buffer->clips[buffer->clip_size] = clip;
|
||||
buffer->clip_size++;
|
||||
cmd->x = clip.x;
|
||||
@ -693,7 +691,6 @@ gui_widget_button_icon(struct gui_command_buffer *buffer, struct gui_button* but
|
||||
gui_bool pressed;
|
||||
struct gui_image image;
|
||||
struct gui_color col;
|
||||
const struct gui_color color = {255,255,255,255};
|
||||
|
||||
assert(buffer);
|
||||
assert(button);
|
||||
@ -2523,9 +2520,11 @@ gui_begin_panel(struct gui_context *ctx, struct gui_panel *panel,
|
||||
|
||||
incursor = INBOX(in->mouse_prev.x,in->mouse_prev.y,scaler_x, scaler_y, scaler_w, scaler_h);
|
||||
if (in->mouse_down && incursor) {
|
||||
gui_float min_x = config->panel_min_size.x;
|
||||
gui_float min_y = config->panel_min_size.y;
|
||||
cpanel->x = CLAMP(0, cpanel->x + in->mouse_delta.x, ctx->width - cpanel->w);
|
||||
cpanel->w = CLAMP(0, cpanel->w - in->mouse_delta.x, ctx->width - cpanel->x);
|
||||
cpanel->h = CLAMP(0, cpanel->h + in->mouse_delta.y, ctx->height - cpanel->y);
|
||||
cpanel->w = CLAMP(min_x, cpanel->w - in->mouse_delta.x, ctx->width - cpanel->x);
|
||||
cpanel->h = CLAMP(min_y, cpanel->h + in->mouse_delta.y, ctx->height - cpanel->y);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user