colourpicker

Simple Colour Picker written in C
git clone anongit@rnpnr.xyz:colourpicker.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

Commit: f603818309bbab9e3cfec3c4ea258088f7ebf05b
Parent: 1e2b6e42c462028c4a890c2a17b19251e812ecef
Author: Randy Palamar
Date:   Fri,  9 Aug 2024 06:30:21 -0600

avoid broken raylib border calculation for colour stack

Diffstat:
Mcolourpicker.c | 16++++++++++------
Mutil.c | 6++----
2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/colourpicker.c b/colourpicker.c @@ -410,11 +410,15 @@ do_rect_button(ButtonState *btn, v2 mouse, Rect r, Color bg, f32 dt, f32 hover_s { i32 pressed_mask = do_button(btn, mouse, r, dt, hover_speed); - f32 param = lerp(1, scale_target, btn->hover_t); - Rect sr = scale_rect_centered(r, (v2){.x = param, .y = param}); + f32 param = lerp(1, scale_target, btn->hover_t); + v2 bscale = (v2){ + .x = param + RECT_BTN_BORDER_WIDTH / r.size.w, + .y = param + RECT_BTN_BORDER_WIDTH / r.size.h, + }; + Rect sr = scale_rect_centered(r, (v2){.x = param, .y = param}); + Rect sb = scale_rect_centered(r, bscale); + DrawRectangleRounded(sb.rr, SELECTOR_ROUNDNESS, 0, fade(SELECTOR_BORDER_COLOUR, fade_t)); DrawRectangleRounded(sr.rr, SELECTOR_ROUNDNESS, 0, fade(bg, fade_t)); - DrawRectangleRoundedLinesEx(sr.rr, SELECTOR_ROUNDNESS, 0, SELECTOR_BORDER_WIDTH, - fade(SELECTOR_BORDER_COLOUR, fade_t)); return pressed_mask; } @@ -592,8 +596,8 @@ do_colour_stack(ColourPickerCtx *ctx, Rect sa) ColourStackState *css = &ctx->colour_stack; /* NOTE: Small adjusment to align with mode text. TODO: Cleanup? */ - sa.pos.y += 0.025 * sa.size.h; - sa.size.h *= 0.98; + sa = scale_rect_centered(sa, (v2){.x = 1, .y = 0.98}); + sa.pos.y += 0.02 * sa.size.h; Rect r = sa; r.size.h *= 1.0 / (ARRAY_COUNT(css->items) + 3); diff --git a/util.c b/util.c @@ -100,14 +100,12 @@ enum cardinal_direction { NORTH, EAST, SOUTH, WEST }; #define SLIDER_SCALE_TARGET 1.5f #define SLIDER_TRI_SIZE (v2){.x = 6, .y = 8} -#define STACK_BORDER_COLOUR SLIDER_BORDER_COLOUR -#define STACK_BORDER_WIDTH SLIDER_BORDER_WIDTH -#define STACK_ROUNDNESS 0.3f - #define SELECTOR_BORDER_COLOUR SLIDER_BORDER_COLOUR #define SELECTOR_BORDER_WIDTH SLIDER_BORDER_WIDTH #define SELECTOR_ROUNDNESS 0.3f +#define RECT_BTN_BORDER_WIDTH (SLIDER_BORDER_WIDTH + 3.0f) + #define TEXT_HOVER_SPEED 5.0f typedef struct {