From 373243d1389a078d0988fe93dfe74430bdae7004 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Fri, 13 Dec 2024 14:42:15 +0100 Subject: [PATCH] fix rect roundness --- src/main.c3 | 15 ++++++++------- src/ugui_impl.c3 | 2 +- src/ugui_slider.c3 | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.c3 b/src/main.c3 index 67eb227..49876a3 100644 --- a/src/main.c3 +++ b/src/main.c3 @@ -27,7 +27,7 @@ fn int main(String[] args) { ugui::Ctx ui; 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 height = 450; @@ -46,7 +46,7 @@ fn int main(String[] args) // Main loop while (!rl::window_should_close()) { clock.mark(); - + /* Start Input Handling */ if (rl::is_window_resized()) { width = (short)rl::get_screen_width(); @@ -94,7 +94,7 @@ fn int main(String[] args) io::printfn("slider: %f", e.slider.value); } - ui.text_unbounded("text1", "Ciao Mamma\n Sono a Casa")!!; + ui.text_unbounded("text1", "Ciao Mamma\nSono a Casa")!!; |}; ui.div_end()!!; @@ -146,9 +146,10 @@ fn int main(String[] args) .height = cmd.rect.rect.h, .width = cmd.rect.rect.w, }; - // TODO: find a way to do real pixel-perfec rounding - float round = cmd.rect.radius ? 0.2 : 0; - rl::draw_rectangle_rounded(r, round, 2, c); + float rad = cmd.rect.radius; + // for some weird-ass reason the straight forward inverse formula does not work + 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: rl::unload_image(font_atlas); font_atlas.data = cmd.update_atlas.raw_buffer; @@ -173,7 +174,7 @@ fn int main(String[] args) .x = cmd.sprite.rect.x, .y = cmd.sprite.rect.y, }; - + rl::draw_texture_rec(font_texture, source, position, rl::WHITE); //rl::draw_rectangle(cmd.sprite.rect.x, // cmd.sprite.rect.y, diff --git a/src/ugui_impl.c3 b/src/ugui_impl.c3 index 736877e..be172c1 100644 --- a/src/ugui_impl.c3 +++ b/src/ugui_impl.c3 @@ -56,7 +56,7 @@ fn void! Ctx.init(&ctx) ctx.style.margin = Rect{2, 2, 2, 2}; ctx.style.border = Rect{2, 2, 2, 2}; 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.fgcolor = uint_to_rgba(0xfbf1c7ff); ctx.style.brcolor = uint_to_rgba(0xd79921ff); diff --git a/src/ugui_slider.c3 b/src/ugui_slider.c3 index a32ffc5..ddabc4e 100644 --- a/src/ugui_slider.c3 +++ b/src/ugui_slider.c3 @@ -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 handle_color = uint_to_rgba(0x0ff000ff); ctx.push_rect(c_elem.bounds, bg_color)!;