rewrite2
Alessandro Mauri 11 months ago
parent 305df93182
commit 97295df516
  1. 38
      ugui.c

@ -150,8 +150,13 @@ struct _UgCtx {
int width, height; int width, height;
} size; } size;
struct { struct { // css box model
UgPoint margin; UgRect padding;
UgRect border;
UgRect margin;
UgColor bgcolor; // background color
UgColor fgcolor; // foreground color
UgColor bcolor; // border color
} style; } style;
// input structure, it describes the events received between frames // input structure, it describes the events received between frames
@ -316,7 +321,13 @@ int ug_init(UgCtx *ctx)
ctx->div_using = 0; ctx->div_using = 0;
// TODO: add style config // TODO: add style config
ctx->style.margin = (UgPoint) {2, 2}; ctx->style.margin = (UgRect) {1, 1, 1, 1};
ctx->style.padding = (UgRect) {0};
ctx->style.border = (UgRect) {0};
ctx->style.bgcolor = (UgColor) {0};
ctx->style.fgcolor = (UgColor) {0};
ctx->style.bcolor = (UgColor) {0};
return 0; return 0;
} }
@ -585,15 +596,28 @@ UgRect position_element(UgCtx *ctx, UgElem *parent, UgRect rect, int style)
}; };
// if using the style then apply margins // if using the style then apply margins
// FIXME: this does not work
if (style && parent->div.layout != DIV_LAYOUT_FLOATING) { if (style && parent->div.layout != DIV_LAYOUT_FLOATING) {
elem_rect.x += ctx->style.margin.x; elem_rect.x += ctx->style.margin.x;
elem_rect.y += ctx->style.margin.y; elem_rect.y += ctx->style.margin.y;
parent->div.origin_r.x += ctx->style.margin.x; // total keep-out borders
// parent->div.origin_r.y += ctx->style.margin.y; UgRect margin_tot = {
.x = ctx->style.padding.x + ctx->style.border.x +
ctx->style.margin.x,
.y = ctx->style.padding.y + ctx->style.border.y +
ctx->style.margin.y,
.w = ctx->style.padding.w + ctx->style.border.x +
ctx->style.margin.w,
.h = ctx->style.padding.h + ctx->style.border.x +
ctx->style.margin.h,
};
parent->div.origin_r.x += margin_tot.x + margin_tot.w;
// parent->div.origin_r.y += margin_tot.h;
// parent->div.origin_c.x += ctx->style.margin.x; // parent->div.origin_c.x += margin_tot.w;
parent->div.origin_c.y += ctx->style.margin.y; parent->div.origin_c.y += margin_tot.y + margin_tot.h;
} }
/* /*

Loading…
Cancel
Save