Add hover on select text

main
En Yi 2025-01-18 10:23:23 +08:00
parent 15162c64e8
commit 1e584c1dc3
3 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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();
}