Storage: better presentation

This commit is contained in:
2023-09-30 18:28:35 +02:00
parent 138655191b
commit 85d57e9749
3 changed files with 99 additions and 19 deletions

View File

@@ -356,6 +356,71 @@ bool gui_slider(Rect r, f32 min, f32 max, f32 *value)
return gui_slider(&global_gui_state.default_context, r, min, max, value);
}
bool gui_slider_text(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value, const char *text)
{
Gui_Id widget_id = gui_id_from_pointer(ctx, value);
bool behaviour = gui_button_behaviuor(ctx, widget_id, r);
if(ctx->active == widget_id)
{
f32 pointer_ratio = (ctx->input.pointer_position.x - r.position.x) / r.size.x;
*value = clamp(0.0f, 1.0f, pointer_ratio) * (max - min) + min;
}
// Colors
v4 button_color = ctx->style.button_color;
v4 text_color = ctx->style.button_text_color;
{
f64 delta_t = (ctx->current_frame_time - ctx->hot_start_time);
f32 interpolation = sin(10 * delta_t) * 0.5 + 0.5;
if(ctx->hot == widget_id)
{
button_color = lerp(ctx->style.button_color, ctx->style.button_color_hovered, interpolation);
text_color = lerp(ctx->style.button_text_color, ctx->style.button_text_color_hovered, interpolation);
}
if(ctx->active == widget_id)
{
button_color = lerp(ctx->style.button_color_hovered, ctx->style.button_color_pressed, interpolation * 0.4 + 0.6);
text_color = lerp(ctx->style.button_text_color_hovered, ctx->style.button_text_color_pressed, interpolation * 0.4 + 0.6);
}
}
// Draw
f32 border = 2;
f32 radius = ctx->style.button_radius;
// Draw background
v4 background_color = ctx->style.button_color;
r_2d_immediate_rounded_rectangle(r, radius, background_color); // Background
// Draw fill
f32 ratio = (*value - min) / (max - min);
Rect fill_r = r;
fill_r.position += v2{border, border};
fill_r.size = v2{maximum(0, fill_r.size.x - 2*border), maximum(0, fill_r.size.y - 2*border)};
f32 fill_radius = maximum(0, radius - border);
fill_r.size.x = fill_r.size.x * ratio;
r_2d_immediate_rounded_rectangle(fill_r, fill_radius, ctx->style.slider_fill_color);
// Draw border
v4 border_color = ctx->style.button_color_pressed;
Rect border_r = r;
border_r.position += v2{border, border} * 0.5;
border_r.size = v2{maximum(0, border_r.size.x - border), maximum(0, border_r.size.y - border)};
f32 border_radius = maximum(0, radius - border*0.5);
r_2d_immediate_rounded_rectangle_outline(border_r, border_radius, border_color, border);
// Draw value text
gui_button_draw_inner_text(ctx, r, text, text_color);
return behaviour || ctx->active == widget_id;
}
bool gui_slider_text(Rect r, f32 min, f32 max, f32 *value, const char *text)
{
return gui_slider_text(&global_gui_state.default_context, r, min, max, value, text);
}
// Images
bool gui_image(Gui_Context *ctx, Rect r, r_texture *texture)

View File

@@ -155,6 +155,9 @@ bool gui_button(Rect r, const char *text);
bool gui_slider(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value);
bool gui_slider(Rect r, f32 min, f32 max, f32 *value);
bool gui_slider_text(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value, const char *text);
bool gui_slider_text(Rect r, f32 min, f32 max, f32 *value, const char *text);
// Checkbox
// Option buttons
// Combo box