From 1e584c1dc3bddcd2a0570cec773a78ed459be4e1 Mon Sep 17 00:00:00 2001 From: En Yi Date: Sat, 18 Jan 2025 10:23:23 +0800 Subject: [PATCH] Add hover on select text --- engine/gui.c | 8 ++++++++ engine/gui.h | 1 + scenes/menu_scene.c | 13 +++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/engine/gui.c b/engine/gui.c index 6b60b17..97343a9 100644 --- a/engine/gui.c +++ b/engine/gui.c @@ -374,6 +374,14 @@ void UI_button(const UIComp_t* comp, const char* text) } +void hover_text(const UIComp_t* comp, Font font, const char* text, Vector2 pos, int font_size, int spacing, Color colour) { + if (comp->state == STATE_FOCUSED) { + DrawTextEx(font, text, pos, font_size, spacing, Fade(colour, 0.1)); + pos.y -= font_size >> 2; + } + DrawTextEx(font, text, pos, font_size, spacing, colour); +} + // Slider control with pro parameters // NOTE: Other GuiSlider*() controls use this one diff --git a/engine/gui.h b/engine/gui.h index f07ee86..039bfdf 100644 --- a/engine/gui.h +++ b/engine/gui.h @@ -46,4 +46,5 @@ static inline void ScrollAreaRenderBegin(VertScrollArea_t* scroll) void UI_button(const UIComp_t* bbox, const char* text); float UI_slider(const UIComp_t* comp, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); float UI_vert_slider(const UIComp_t* comp, const char *textTop, const char *textBottom, float* value, float minValue, float maxValue); +void hover_text(const UIComp_t* comp, Font font, const char* text, Vector2 pos, int font_size, int spacing, Color colour); #endif diff --git a/scenes/menu_scene.c b/scenes/menu_scene.c index 9624ce6..a34675c 100644 --- a/scenes/menu_scene.c +++ b/scenes/menu_scene.c @@ -16,10 +16,10 @@ static void menu_scene_render_func(Scene_t* scene) ClearBackground(RAYWHITE); draw_sprite(spr, 0, (Vector2){0, 0}, 0, false); draw_sprite(title_spr, 0, (Vector2){32, 10}, 0, false); - Vector2 title_sz = MeasureTextEx(*menu_font, "Bunny's Spelunking Adventure", 56, 0); + Vector2 font_sz = MeasureTextEx(*menu_font, "Bunny's Spelunking Adventure", 56, 0); Vector2 title_pos = { - .x = (render_rec.width - title_sz.x) / 2, - .y = 32 + (title_spr->frame_size.y - title_sz.y) / 2 + .x = (render_rec.width - font_sz.x) / 2, + .y = 32 + (title_spr->frame_size.y - font_sz.y) / 2 }; DrawTextEx(*menu_font, "Bunny's Spelunking Adventure", title_pos, 56, 0, BLACK); @@ -38,7 +38,12 @@ static void menu_scene_render_func(Scene_t* scene) ) ); draw_sprite(title_select, 0, pos, 0, false); - UI_button(data->buttons + i, OPTIONS[i]); + font_sz = MeasureTextEx(*menu_font, OPTIONS[i], 32, 6); + Vector2 title_pos = { + .x = pos.x + (title_select->frame_size.x - font_sz.x) / 2, + .y = pos.y + (title_spr->frame_size.y) / 2 - font_sz.y + }; + hover_text(data->buttons + i, *menu_font, OPTIONS[i], title_pos, 32, 6, BLACK); } EndTextureMode(); }