[ui] remove the need to pass a default style to ui_frame()

This commit is contained in:
Martin Fouilleul 2023-03-07 19:44:22 +01:00
parent 2466241b1e
commit c551135933
3 changed files with 16 additions and 6 deletions

View File

@ -249,16 +249,16 @@ int main()
.layout.margin.x = 10, .layout.margin.x = 10,
.layout.margin.y = 10, .layout.margin.y = 10,
.bgColor = {0.9, 0.9, 0.9, 1}, .bgColor = {0.9, 0.9, 0.9, 1},
.color = {0, 0, 0, 1},
.borderSize = 2, .borderSize = 2,
.borderColor = {0, 0, 1, 1}, .borderColor = {0, 0, 1, 1},
.color = {0, 0, 0, 1},
.font = font, .font = font,
.fontSize = 32}; .fontSize = 32};
ui_flags defaultFlags = UI_FLAG_DRAW_BORDER; ui_flags defaultFlags = UI_FLAG_DRAW_BORDER;
ui_box* root = 0; ui_box* root = 0;
ui_frame(800, 610, defaultStyle) ui_frame(800, 610)
{ {
root = ui_box_top(); root = ui_box_top();
@ -272,7 +272,16 @@ int main()
&(ui_style){.fontSize = 36}, &(ui_style){.fontSize = 36},
UI_STYLE_FONT_SIZE); UI_STYLE_FONT_SIZE);
ui_style_next(ui_pattern_all(), &defaultStyle, UI_STYLE_BORDER_SIZE|UI_STYLE_BORDER_COLOR|UI_STYLE_SIZE_X|UI_STYLE_SIZE_Y|UI_STYLE_LAYOUT); ui_style_next(ui_pattern_all(),
&defaultStyle,
UI_STYLE_FONT
|UI_STYLE_FONT_SIZE
|UI_STYLE_COLOR
|UI_STYLE_BORDER_SIZE
|UI_STYLE_BORDER_COLOR
|UI_STYLE_SIZE_X
|UI_STYLE_SIZE_Y
|UI_STYLE_LAYOUT);
ui_container("a", defaultFlags) ui_container("a", defaultFlags)
{ {

View File

@ -1326,7 +1326,7 @@ void ui_draw()
// frame begin/end // frame begin/end
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void ui_begin_frame(u32 width, u32 height, ui_style defaultStyle) void ui_begin_frame(u32 width, u32 height)
{ {
ui_context* ui = ui_get_context(); ui_context* ui = ui_get_context();
@ -1342,6 +1342,7 @@ void ui_begin_frame(u32 width, u32 height, ui_style defaultStyle)
ui->clipStack = 0; ui->clipStack = 0;
ui->z = 0; ui->z = 0;
ui_style defaultStyle = {0};
defaultStyle.size.s[UI_AXIS_X] = (ui_size){UI_SIZE_PIXELS, width, 0}; defaultStyle.size.s[UI_AXIS_X] = (ui_size){UI_SIZE_PIXELS, width, 0};
defaultStyle.size.s[UI_AXIS_Y] = (ui_size){UI_SIZE_PIXELS, height, 0}; defaultStyle.size.s[UI_AXIS_Y] = (ui_size){UI_SIZE_PIXELS, height, 0};

View File

@ -313,11 +313,11 @@ void ui_init(void);
ui_context* ui_get_context(void); ui_context* ui_get_context(void);
void ui_set_context(ui_context* context); void ui_set_context(ui_context* context);
void ui_begin_frame(u32 width, u32 height, ui_style defaultStyle); void ui_begin_frame(u32 width, u32 height);
void ui_end_frame(void); void ui_end_frame(void);
void ui_draw(void); void ui_draw(void);
#define ui_frame(width, height, defaultStyle) defer_loop(ui_begin_frame(width, height, defaultStyle), ui_end_frame()) #define ui_frame(width, height) defer_loop(ui_begin_frame(width, height), ui_end_frame())
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// Box keys // Box keys