Tooltip functionality

This commit is contained in:
Synthasmagoria 2026-08-27 12:26:38 +02:00
commit 2a302f7b1d
4 changed files with 62 additions and 11 deletions

View file

@ -22,7 +22,7 @@ write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (succ
}
/// ### RAYLIB DRAWING UTILS ### ///
measure_text :: proc(text: cstring, style: FontStyle) -> v2 {
@require_results measure_text :: proc(text: cstring, style: FontStyle) -> v2 {
return rl.MeasureTextEx(style.font, text, style.size, style.spacing)
}
@ -30,20 +30,42 @@ draw_text :: proc(text: cstring, position: v2, style: FontStyle, color: rl.Color
rl.DrawTextEx(style.font, text, position, style.size, style.spacing, color)
}
TextHalign :: enum {
draw_multiline_text_centered :: proc(text: cstring, position: v2, style: FontStyle, color: rl.Color, temp_allocator := context.temp_allocator) {
size := measure_text(text, style)
split := strings.split(strings.clone_from_cstring(text), "\n", temp_allocator)
for line, i in split {
line := strings.clone_to_cstring(line, temp_allocator)
line_size := measure_text(line, style)
offset := v2{(size.x - line_size.x) * 0.5, line_size.y * f32(i)}
draw_text(line, position + offset, style, color)
}
}
JustificationHalign :: enum {
Left,
Middle,
Right,
}
TextValign :: enum {
JustificationValign :: enum {
Top,
Center,
Bottom,
}
draw_text_aligned :: proc(text: cstring, position: v2, style: FontStyle, halign: TextHalign, valign: TextValign, color: rl.Color) {
JustificationAlign :: enum {
Shallow,
Middle,
Deep,
}
draw_text_aligned :: proc(text: cstring, position: v2, style: FontStyle, halign: JustificationHalign, valign: JustificationValign, color: rl.Color) {
size := measure_text(text, style)
draw_text(text, justify_2d(position, size, halign, valign), style, color)
}
@require_results justify_2d :: proc(position: v2, size: v2, halign: JustificationHalign, valign: JustificationValign) -> v2 {
position := position
switch halign {
case .Left:
@ -55,10 +77,10 @@ draw_text_aligned :: proc(text: cstring, position: v2, style: FontStyle, halign:
case .Center: position.y -= size.y / 2.0
case .Bottom: position.y -= size.y
}
draw_text(text, position, style, color)
return position
}
draw_float_aligned :: proc(value: f32, position: v2, style: FontStyle, halign: TextHalign, valign: TextValign, color: rl.Color) {
draw_float_aligned :: proc(value: f32, position: v2, style: FontStyle, halign: JustificationHalign, valign: JustificationValign, color: rl.Color) {
fractional := fract(value)
text: cstring
if fractional == 0.0 {