colourpicker

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

Commit: d9df8fd6f603c4af14873d8e34498c5802b66230
Parent: 049fe56c4d7ff130c48de2217192c8f3b253bcd7
Author: Randy Palamar
Date:   Mon,  5 Aug 2024 20:39:33 -0600

limit the cursor width on really big windows

Diffstat:
Mcolourpicker.c | 10++++++----
Mutil.c | 1+
2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/colourpicker.c b/colourpicker.c @@ -368,9 +368,11 @@ do_text_input(ColourPickerCtx *ctx, Rect r, Color colour) char saved_c = buf[ctx->is.cursor - buf_delta]; buf[ctx->is.cursor - buf_delta] = 0; - v2 sts = {.rv = MeasureTextEx(ctx->font, buf, ctx->font_size, 0)}; - f32 cursor_x = r.pos.x + sts.x; - f32 cursor_width = ctx->is.cursor == ctx->is.buf_len ? ctx->window_size.w * 0.03 : ctx->window_size.w * 0.01; + v2 sts = {.rv = MeasureTextEx(ctx->font, buf, ctx->font_size, 0)}; + f32 cursor_x = r.pos.x + sts.x; + f32 cursor_width; + if (ctx->is.cursor == ctx->is.buf_len) cursor_width = MIN(ctx->window_size.w * 0.03, 20); + else cursor_width = MIN(ctx->window_size.w * 0.01, 6); buf[ctx->is.cursor - buf_delta] = saved_c; @@ -529,7 +531,7 @@ do_slider(ColourPickerCtx *ctx, Rect r, i32 label_idx, v2 relative_origin) } } - DrawRectangleRoundedLinesEx(sr.rr, SLIDER_ROUNDNESS, 0, 4 * SLIDER_BORDER_WIDTH, ctx->bg); + DrawRectangleRoundedLinesEx(sr.rr, SLIDER_ROUNDNESS, 0, 4.85 * SLIDER_BORDER_WIDTH, ctx->bg); DrawRectangleRoundedLinesEx(sr.rr, SLIDER_ROUNDNESS, 0, SLIDER_BORDER_WIDTH, SLIDER_BORDER_COLOUR); diff --git a/util.c b/util.c @@ -192,6 +192,7 @@ typedef struct { #define ARRAY_COUNT(a) (sizeof(a) / sizeof(*a)) #define ABS(x) ((x) < 0 ? (-x) : (x)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)) #define CLAMP01(a) CLAMP(a, 0, 1)