fix rect roundness

font_atlas
Alessandro Mauri 2 weeks ago
parent 3070fac9f5
commit 373243d138
  1. 9
      src/main.c3
  2. 2
      src/ugui_impl.c3
  3. 2
      src/ugui_slider.c3

@ -27,7 +27,7 @@ fn int main(String[] args)
{ {
ugui::Ctx ui; ugui::Ctx ui;
ui.init()!!; ui.init()!!;
ui.font.load("/usr/share/fonts/TTF/FreeSans.ttf", 16, scale: 1.5)!!; ui.font.load("/usr/share/fonts/TTF/Hack-Regular.ttf", 16, scale: 1.5)!!;
short width = 800; short width = 800;
short height = 450; short height = 450;
@ -146,9 +146,10 @@ fn int main(String[] args)
.height = cmd.rect.rect.h, .height = cmd.rect.rect.h,
.width = cmd.rect.rect.w, .width = cmd.rect.rect.w,
}; };
// TODO: find a way to do real pixel-perfec rounding float rad = cmd.rect.radius;
float round = cmd.rect.radius ? 0.2 : 0; // for some weird-ass reason the straight forward inverse formula does not work
rl::draw_rectangle_rounded(r, round, 2, c); float roundness = r.width > r.height ? (2.1*rad)/r.height : (2.1*rad)/r.width;
rl::draw_rectangle_rounded(r, roundness, 0, c);
case ugui::CmdType.CMD_UPDATE_ATLAS: case ugui::CmdType.CMD_UPDATE_ATLAS:
rl::unload_image(font_atlas); rl::unload_image(font_atlas);
font_atlas.data = cmd.update_atlas.raw_buffer; font_atlas.data = cmd.update_atlas.raw_buffer;

@ -56,7 +56,7 @@ fn void! Ctx.init(&ctx)
ctx.style.margin = Rect{2, 2, 2, 2}; ctx.style.margin = Rect{2, 2, 2, 2};
ctx.style.border = Rect{2, 2, 2, 2}; ctx.style.border = Rect{2, 2, 2, 2};
ctx.style.padding = Rect{1, 1, 1, 1}; ctx.style.padding = Rect{1, 1, 1, 1};
ctx.style.radius = 4; ctx.style.radius = 5;
ctx.style.bgcolor = uint_to_rgba(0x282828ff); ctx.style.bgcolor = uint_to_rgba(0x282828ff);
ctx.style.fgcolor = uint_to_rgba(0xfbf1c7ff); ctx.style.fgcolor = uint_to_rgba(0xfbf1c7ff);
ctx.style.brcolor = uint_to_rgba(0xd79921ff); ctx.style.brcolor = uint_to_rgba(0xd79921ff);

@ -98,7 +98,7 @@ fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size)
} }
} }
// Draw the button // Draw the slider background and handle
Color bg_color = uint_to_rgba(0x0000ffff); Color bg_color = uint_to_rgba(0x0000ffff);
Color handle_color = uint_to_rgba(0x0ff000ff); Color handle_color = uint_to_rgba(0x0ff000ff);
ctx.push_rect(c_elem.bounds, bg_color)!; ctx.push_rect(c_elem.bounds, bg_color)!;

Loading…
Cancel
Save