remove trailing whitespace
This commit is contained in:
parent
fab6fd33d2
commit
9f13d5a39e
@ -6,7 +6,7 @@
|
||||
#define SZ_INT(x) x.size.i
|
||||
|
||||
static const ug_style_t default_style = {
|
||||
.color = {
|
||||
.color = {
|
||||
.bg = RGB_FORMAT(0x131313),
|
||||
.fg = RGB_FORMAT(0xffffff),
|
||||
},
|
||||
|
26
test/main.c
26
test/main.c
@ -24,7 +24,7 @@ int main(void)
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
|
||||
SDL_EnableScreenSaver();
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
SDL_EventState(SDL_DROPTEXT, SDL_ENABLE);
|
||||
|
||||
SDL_GetDesktopDisplayMode(0, &dm);
|
||||
@ -37,9 +37,9 @@ int main(void)
|
||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
||||
#endif
|
||||
|
||||
w = SDL_CreateWindow("test",
|
||||
w = SDL_CreateWindow("test",
|
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
dm.w*0.8, dm.h*0.8,
|
||||
dm.w*0.8, dm.h*0.8,
|
||||
SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI |
|
||||
SDL_WINDOW_OPENGL );
|
||||
|
||||
@ -53,7 +53,7 @@ int main(void)
|
||||
SDL_GL_GetDrawableSize(w, &dsize.w, &dsize.h);
|
||||
float scale = 1.0;
|
||||
scale = ((float)(size.w+size.h)/2)/((float)(dsize.w+dsize.h)/2);
|
||||
|
||||
|
||||
float dpi;
|
||||
int idx;
|
||||
idx = SDL_GetWindowDisplayIndex(w);
|
||||
@ -72,13 +72,13 @@ int main(void)
|
||||
SDL_Event event;
|
||||
|
||||
char button_map[] = {
|
||||
[SDL_BUTTON_LEFT & 0xff] = UG_BTN_LEFT,
|
||||
[SDL_BUTTON_MIDDLE & 0xff] = UG_BTN_MIDDLE,
|
||||
[SDL_BUTTON_RIGHT & 0xff] = UG_BTN_RIGHT,
|
||||
[SDL_BUTTON_X1 & 0xff] = UG_BTN_4,
|
||||
[SDL_BUTTON_X2 & 0xff] = UG_BTN_5,
|
||||
[SDL_BUTTON_LEFT & 0xff] = UG_BTN_LEFT,
|
||||
[SDL_BUTTON_MIDDLE & 0xff] = UG_BTN_MIDDLE,
|
||||
[SDL_BUTTON_RIGHT & 0xff] = UG_BTN_RIGHT,
|
||||
[SDL_BUTTON_X1 & 0xff] = UG_BTN_4,
|
||||
[SDL_BUTTON_X2 & 0xff] = UG_BTN_5,
|
||||
};
|
||||
|
||||
|
||||
do {
|
||||
SDL_WaitEvent(&event);
|
||||
|
||||
@ -192,7 +192,7 @@ int main(void)
|
||||
//}
|
||||
|
||||
ug_container_floating(ctx, "stupid name", (ug_div_t){.x=SIZE_PX(0), .y=SIZE_PX(0), .w=SIZE_PX(100), .h=SIZE_MM(75.0)});
|
||||
ug_element_button(ctx, "float", "", (ug_div_t){SQUARE(SIZE_MM(5))});
|
||||
ug_element_button(ctx, "float", "X", (ug_div_t){SQUARE(SIZE_MM(5))});
|
||||
//ug_container_floating(ctx, "floating windoooooooow", (ug_div_t){.x=SIZE_PX(100), .y=SIZE_PX(0), .w=SIZE_PX(100), .h=SIZE_MM(75.0)});
|
||||
|
||||
//ug_container_sidebar(ctx, "Right Sidebar", (ug_size_t)SIZE_PX(300), UG_SIDE_RIGHT);
|
||||
@ -207,7 +207,7 @@ int main(void)
|
||||
// printf("No space!\n");
|
||||
|
||||
ug_layout_row(ctx);
|
||||
|
||||
|
||||
ug_layout_column(ctx);
|
||||
ug_element_button(ctx, "button 1", "hey", (ug_div_t){SQUARE(SIZE_MM(10))});
|
||||
//ug_element_button(ctx, "button 2", "lol", (ug_div_t){SQUARE(SIZE_MM(10))});
|
||||
@ -218,7 +218,7 @@ int main(void)
|
||||
ug_element_button(ctx, "button 5", "lmao", (ug_div_t){SQUARE(SIZE_MM(10))});
|
||||
//ug_element_textbtn(ctx, "text button 1", "foo", (ug_div_t){.w = 0, .h = SIZE_PX(30)});
|
||||
//ug_element_button(ctx, "button 6", "", (ug_div_t){SQUARE(SIZE_MM(10)),.x=SIZE_PX(-10)});
|
||||
|
||||
|
||||
ug_container_body(ctx, "fill body");
|
||||
|
||||
ug_frame_end(ctx);
|
||||
|
82
ugui.c
82
ugui.c
@ -125,7 +125,7 @@ static ug_id_t hash(const void *data, unsigned int size)
|
||||
hash += hash << 3;
|
||||
hash ^= hash >> 11;
|
||||
hash += hash << 15;
|
||||
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ static void push_rect_command(ug_ctx_t *ctx, const ug_rect_t *rect, ug_color_t c
|
||||
|
||||
|
||||
// pushes a text command to the render command stack, str is a pointer to a valid
|
||||
// string offered by the user, it must be valid at least until rendering is done
|
||||
// string offered by the user, it must be valid at least until rendering is done
|
||||
static void push_text_command(ug_ctx_t *ctx, ug_vec2_t pos, int size, ug_color_t color, const char *str)
|
||||
{
|
||||
ug_cmd_t *c;
|
||||
@ -294,7 +294,7 @@ int ug_ctx_set_displayinfo(ug_ctx_t *ctx, float scale, float ppi)
|
||||
TEST_CTX(ctx);
|
||||
if (scale <= 0 || ppi < 20.0)
|
||||
return -1;
|
||||
|
||||
|
||||
ctx->last_ppi = ctx->ppi;
|
||||
ctx->last_ppm = ctx->ppd;
|
||||
ctx->last_ppd = ctx->ppm;
|
||||
@ -302,7 +302,7 @@ int ug_ctx_set_displayinfo(ug_ctx_t *ctx, float scale, float ppi)
|
||||
ctx->ppm = PPI_PPM(scale, ppi);
|
||||
ctx->ppd = PPI_PPM(scale, ppi);
|
||||
ctx->ppi = ppi;
|
||||
|
||||
|
||||
update_style_cache(ctx);
|
||||
|
||||
return 0;
|
||||
@ -314,7 +314,7 @@ int ug_ctx_set_drawableregion(ug_ctx_t *ctx, ug_vec2_t size)
|
||||
TEST_CTX(ctx);
|
||||
if (size.w <= 0 || size.h <= 0)
|
||||
return -1;
|
||||
|
||||
|
||||
ctx->size.w = size.w;
|
||||
ctx->size.h = size.h;
|
||||
|
||||
@ -331,7 +331,7 @@ int ug_ctx_set_style(ug_ctx_t *ctx, const ug_style_t *style)
|
||||
|
||||
ctx->style = style;
|
||||
update_style_cache(ctx);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ int ug_ctx_set_style(ug_ctx_t *ctx, const ug_style_t *style)
|
||||
/*
|
||||
* Container style: rca stands for absolute rectangle, it delimits the total
|
||||
* drawable area, as such it does not include borders
|
||||
*
|
||||
*
|
||||
* rca v Border Top v
|
||||
* +-v--------------------------------------------------------+
|
||||
* | +------------------------------------------------------+ |
|
||||
@ -379,7 +379,7 @@ int ug_ctx_set_style(ug_ctx_t *ctx, const ug_style_t *style)
|
||||
* | | .................................................... | |
|
||||
* | +------------------------------------------------------+ |
|
||||
* +----------------------------------------------------------+
|
||||
* ^ Border Bottom ^
|
||||
* ^ Border Bottom ^
|
||||
*/
|
||||
|
||||
|
||||
@ -430,13 +430,13 @@ static void sort_containers(ug_ctx_t *ctx)
|
||||
|
||||
ug_container_t *s = ctx->cnt_stack.items;
|
||||
ug_container_t c = *cnt;
|
||||
|
||||
|
||||
if (ctx->active_cnt != c.id)
|
||||
for (; y > 0 && TEST(s[y-1].flags, UG_CNT_FLOATING); y--);
|
||||
|
||||
if (i >= y)
|
||||
continue;
|
||||
|
||||
|
||||
memmove(&s[i], &s[i+1], (y - i) * sizeof(ug_container_t));
|
||||
s[y-1] = c;
|
||||
}
|
||||
@ -503,7 +503,7 @@ static int position_container(ug_ctx_t *ctx, ug_container_t *cnt)
|
||||
else rca->x = L_MARGIN(c, 0);
|
||||
if (rect->y < 0) rca->y = B_MARGIN(c, 0) - B_MARGIN((*rca), -1);
|
||||
else rca->y = T_MARGIN(c, 0);
|
||||
|
||||
|
||||
// if the container is fixed than update the available space in
|
||||
// the context
|
||||
if (rect->w) {
|
||||
@ -545,13 +545,13 @@ static int handle_container(ug_ctx_t *ctx, ug_container_t *cnt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// mouse pressed handle resize, for simplicity containers can only
|
||||
// mouse pressed handle resize, for simplicity containers can only
|
||||
// be resized from the bottom and right border
|
||||
// TODO: change return value to indicate this case
|
||||
if (!MOUSEHELD(ctx, UG_BTN_LEFT) ||
|
||||
!TEST(cnt->flags, (RESIZEALL | UG_CNT_MOVABLE)))
|
||||
return 1;
|
||||
|
||||
|
||||
ug_rect_t *rect, *rca;
|
||||
rect = &cnt->rect;
|
||||
rca = &cnt->rca;
|
||||
@ -563,7 +563,7 @@ static int handle_container(ug_ctx_t *ctx, ug_container_t *cnt)
|
||||
|
||||
ug_vec2_t mpos = ctx->mouse.pos;
|
||||
ug_rect_t clip;
|
||||
|
||||
|
||||
// handle movable windows
|
||||
if (TEST(cnt->flags, UG_CNT_MOVABLE)) {
|
||||
clip = (ug_rect_t){
|
||||
@ -636,7 +636,7 @@ static int handle_container(ug_ctx_t *ctx, ug_container_t *cnt)
|
||||
if (rca->w - ctx->mouse.delta.x >= 10) {
|
||||
rca->w -= ctx->mouse.delta.x;
|
||||
rca->x += ctx->mouse.delta.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -680,7 +680,7 @@ static int handle_container(ug_ctx_t *ctx, ug_container_t *cnt)
|
||||
}
|
||||
}
|
||||
|
||||
// if we were not resized but we are still active it means we are doing
|
||||
// if we were not resized but we are still active it means we are doing
|
||||
// something to the contained elements, as such set state to none
|
||||
if (STATEIS(cnt, 0))
|
||||
cnt->flags |= CNT_STATE_NONE;
|
||||
@ -708,7 +708,7 @@ static void draw_container(ug_ctx_t *ctx, ug_container_t *cnt, const char *text)
|
||||
rect = cnt->rca;
|
||||
EXPAND(rect, b);
|
||||
push_rect_command(ctx, &rect, s->color.bg);
|
||||
|
||||
|
||||
// push outline
|
||||
if (TEST(cnt->flags, UG_CNT_RESIZE_LEFT)) {
|
||||
rect = cnt->rca;
|
||||
@ -765,14 +765,14 @@ static void draw_container(ug_ctx_t *ctx, ug_container_t *cnt, const char *text)
|
||||
// a floating container can be placed anywhere and can be resized, acts like a
|
||||
// window inside another window
|
||||
int ug_container_floating(ug_ctx_t *ctx, const char *name, ug_div_t div)
|
||||
{
|
||||
{
|
||||
TEST_CTX(ctx);
|
||||
TEST_STR(name);
|
||||
// TODO: verify div
|
||||
|
||||
ug_id_t id = hash(name, strlen(name));
|
||||
ug_container_t *cnt = get_container(ctx, id);
|
||||
|
||||
|
||||
// maybe the name address was changed so always overwrite it
|
||||
cnt->name = name;
|
||||
if (cnt->id) {
|
||||
@ -789,7 +789,7 @@ int ug_container_floating(ug_ctx_t *ctx, const char *name, ug_div_t div)
|
||||
DELETE_FROM_STACK(ctx->cnt_stack, cnt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Select current conatiner
|
||||
ctx->selected_cnt = id;
|
||||
|
||||
@ -805,7 +805,7 @@ int ug_container_popup(ug_ctx_t *ctx, const char *name, ug_div_t div)
|
||||
|
||||
ug_id_t id = hash(name, strlen(name));
|
||||
ug_container_t *cnt = get_container(ctx, id);
|
||||
|
||||
|
||||
// maybe the name address was changed so always overwrite it
|
||||
cnt->name = name;
|
||||
if (cnt->id) {
|
||||
@ -821,7 +821,7 @@ int ug_container_popup(ug_ctx_t *ctx, const char *name, ug_div_t div)
|
||||
DELETE_FROM_STACK(ctx->cnt_stack, cnt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Select current conatiner
|
||||
ctx->selected_cnt = id;
|
||||
|
||||
@ -855,7 +855,7 @@ int ug_container_sidebar(ug_ctx_t *ctx, const char *name, ug_size_t size, int si
|
||||
cnt->flags |= UG_CNT_RESIZE_BOTTOM;
|
||||
rect.h = size_to_px(ctx, size);
|
||||
break;
|
||||
case UG_SIDE_RIGHT:
|
||||
case UG_SIDE_RIGHT:
|
||||
cnt->flags |= UG_CNT_RESIZE_LEFT;
|
||||
rect.x = -1;
|
||||
rect.w = size_to_px(ctx, size);
|
||||
@ -873,7 +873,7 @@ int ug_container_sidebar(ug_ctx_t *ctx, const char *name, ug_size_t size, int si
|
||||
DELETE_FROM_STACK(ctx->cnt_stack, cnt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Select current conatiner
|
||||
ctx->selected_cnt = id;
|
||||
|
||||
@ -887,7 +887,7 @@ int ug_container_menu_bar(ug_ctx_t *ctx, const char *name, ug_size_t height)
|
||||
|
||||
ug_id_t id = hash(name, strlen(name));
|
||||
ug_container_t *cnt = get_container(ctx, id);
|
||||
|
||||
|
||||
// maybe the name address was changed so always overwrite it
|
||||
cnt->name = name;
|
||||
if (cnt->id) {
|
||||
@ -906,7 +906,7 @@ int ug_container_menu_bar(ug_ctx_t *ctx, const char *name, ug_size_t height)
|
||||
DELETE_FROM_STACK(ctx->cnt_stack, cnt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Select current conatiner
|
||||
ctx->selected_cnt = id;
|
||||
|
||||
@ -921,7 +921,7 @@ int ug_container_body(ug_ctx_t *ctx, const char *name)
|
||||
|
||||
ug_id_t id = hash(name, strlen(name));
|
||||
ug_container_t *cnt = get_container(ctx, id);
|
||||
|
||||
|
||||
// maybe the name address was changed so always overwrite it
|
||||
cnt->name = name;
|
||||
if (cnt->id) {
|
||||
@ -936,7 +936,7 @@ int ug_container_body(ug_ctx_t *ctx, const char *name)
|
||||
DELETE_FROM_STACK(ctx->cnt_stack, cnt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Select current conatiner
|
||||
ctx->selected_cnt = id;
|
||||
|
||||
@ -944,7 +944,7 @@ int ug_container_body(ug_ctx_t *ctx, const char *name)
|
||||
}
|
||||
|
||||
|
||||
// TODO: return an error indicating that no container exists with that name
|
||||
// TODO: return an error indicating that no container exists with that name
|
||||
int ug_container_remove(ug_ctx_t *ctx, const char *name)
|
||||
{
|
||||
TEST_CTX(ctx);
|
||||
@ -961,7 +961,7 @@ int ug_container_remove(ug_ctx_t *ctx, const char *name)
|
||||
}
|
||||
|
||||
|
||||
ug_rect_t ug_container_get_rect(ug_ctx_t *ctx, const char *name)
|
||||
ug_rect_t ug_container_get_rect(ug_ctx_t *ctx, const char *name)
|
||||
{
|
||||
ug_rect_t r = {0};
|
||||
if(!ctx)
|
||||
@ -992,7 +992,7 @@ int ug_frame_begin(ug_ctx_t *ctx)
|
||||
// update mouse delta
|
||||
ctx->mouse.delta.x = ctx->mouse.pos.x - ctx->mouse.last_pos.x;
|
||||
ctx->mouse.delta.y = ctx->mouse.pos.y - ctx->mouse.last_pos.y;
|
||||
|
||||
|
||||
// clear command stack
|
||||
RESET_STACK(ctx->cmd_stack);
|
||||
|
||||
@ -1122,10 +1122,10 @@ int ug_frame_end(ug_ctx_t *ctx)
|
||||
* | |
|
||||
* | |
|
||||
* +--------------------------------------------------------+
|
||||
*
|
||||
*
|
||||
* Element Style:
|
||||
*
|
||||
* rca margin
|
||||
*
|
||||
* rca margin
|
||||
* +-v--------------+<--->+----------------+
|
||||
* | +------------+ | | +------------+ |
|
||||
* | | | | | | | |
|
||||
@ -1254,11 +1254,11 @@ static int position_element(ug_ctx_t *ctx, ug_container_t *cnt, ug_element_t *el
|
||||
int m = SZ_INT(s->margin);
|
||||
int cx, cy, cw, ch;
|
||||
int eb = 0;
|
||||
|
||||
|
||||
switch (elem->type) {
|
||||
case UG_ELEM_BUTTON: eb = SZ_INT(s->btn.border); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: this does not work
|
||||
cw = MAX(cnt->rca.w - cnt->space.w, 0);
|
||||
@ -1274,7 +1274,7 @@ static int position_element(ug_ctx_t *ctx, ug_container_t *cnt, ug_element_t *el
|
||||
// handle relative sizes
|
||||
if (rect->w == 0) rca->w = cw - 2*eb;
|
||||
if (rect->h == 0) rca->h = ch - 2*eb;
|
||||
// for elements x and y are offsets
|
||||
// for elements x and y are offsets
|
||||
rca->x = cx + rect->x + eb + m;
|
||||
rca->y = cy + rect->y + eb + m;
|
||||
|
||||
@ -1285,7 +1285,7 @@ static int position_element(ug_ctx_t *ctx, ug_container_t *cnt, ug_element_t *el
|
||||
|
||||
elem->flags &= ~(ELEM_CLIPPED);
|
||||
if (crop_rect(rca, &cnt->rca))
|
||||
elem->flags |= ELEM_CLIPPED;
|
||||
elem->flags |= ELEM_CLIPPED;
|
||||
|
||||
if (TEST(cnt->flags, CNT_LAYOUT_COLUMN)) {
|
||||
cnt->c_orig.y = B_MARGIN((*rca), 0) + eb;
|
||||
@ -1297,13 +1297,13 @@ static int position_element(ug_ctx_t *ctx, ug_container_t *cnt, ug_element_t *el
|
||||
cnt->c_orig.x = L_MARGIN((*rca), 0) + eb;
|
||||
cnt->c_orig.y = B_MARGIN((*rca), 0) + eb;
|
||||
}
|
||||
|
||||
|
||||
// expand used space
|
||||
if (R_MARGIN(cnt->space, 0) < R_MARGIN((*rca), -eb))
|
||||
cnt->space.w = R_MARGIN((*rca), -eb) - L_MARGIN(cnt->space, 0);
|
||||
if (B_MARGIN(cnt->space, 0) < B_MARGIN((*rca), -eb))
|
||||
cnt->space.h = B_MARGIN((*rca), -eb) - T_MARGIN(cnt->space, 0);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1378,7 +1378,7 @@ void draw_elements(ug_ctx_t *ctx, ug_container_t *cnt)
|
||||
push_rect_command(ctx, &r, col);
|
||||
}
|
||||
if (draw_txt) {
|
||||
push_text_command(ctx,
|
||||
push_text_command(ctx,
|
||||
(ug_vec2_t){
|
||||
.x = e->rca.x+eb,
|
||||
.y = e->rca.y+eb+e->rca.h/2
|
||||
|
10
ugui.h
10
ugui.h
@ -11,7 +11,7 @@
|
||||
#define SQUARE(x) .w = x, .h = x
|
||||
|
||||
// basic types
|
||||
typedef unsigned int ug_id_t;
|
||||
typedef unsigned int ug_id_t;
|
||||
typedef struct { union {int x, w;}; union {int y, h;}; } ug_vec2_t;
|
||||
typedef struct { unsigned char a, b, g, r; } ug_color_t;
|
||||
typedef struct { int x, y, w, h; } ug_rect_t;
|
||||
@ -19,7 +19,7 @@ typedef struct { union {int i; float f;} size; int unit; } ug_size_t;
|
||||
// div has information about the phisical dimension
|
||||
typedef struct { ug_size_t x, y, w, h;} ug_div_t;
|
||||
|
||||
typedef enum {
|
||||
typedef enum {
|
||||
UG_UNIT_PX = 0,
|
||||
UG_UNIT_MM,
|
||||
UG_UNIT_PT,
|
||||
@ -46,7 +46,7 @@ enum {
|
||||
UG_ELEM_CHECK, // checkbox
|
||||
UG_ELEM_RADIO, // radio button
|
||||
UG_ELEM_TOGGLE, // toggle button
|
||||
UG_ELEM_LABEL, // simple text
|
||||
UG_ELEM_LABEL, // simple text
|
||||
UG_ELEM_UPDOWN, // text with two buttons up and down
|
||||
UG_ELEM_TEXTINPUT, // text input box
|
||||
UG_ELEM_TEXTBOX, // text surrounded by a box
|
||||
@ -185,7 +185,7 @@ typedef struct {
|
||||
ug_id_t active_cnt, last_active_cnt;
|
||||
// id of the selected container, used for layout
|
||||
// NOTE: since the stacks can be relocated with realloc it is better not
|
||||
// to use a pointer here, even tough it would be better for efficiency
|
||||
// to use a pointer here, even tough it would be better for efficiency
|
||||
ug_id_t selected_cnt;
|
||||
// count the frames for fun
|
||||
unsigned long int frame;
|
||||
@ -248,7 +248,7 @@ int ug_container_remove(ug_ctx_t *ctx, const char *name);
|
||||
ug_rect_t ug_container_get_rect(ug_ctx_t *ctx, const char *name);
|
||||
|
||||
// layouting, the following functions define how different ui elements are placed
|
||||
// inside the selected container. A new element is aligned respective to the
|
||||
// inside the selected container. A new element is aligned respective to the
|
||||
// previous element and/or to the container, particularly elements can be placed
|
||||
// in a row or a column.
|
||||
int ug_layout_row(ug_ctx_t *ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user