Browse Source

Add DrawTextEx convenience function

master
Kenneth Bruen 9 months ago
parent
commit
b5df9b480d
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 37
      src/raylib.zig

37
src/raylib.zig

@ -36,17 +36,28 @@ pub fn DrawAndMeasureText(
.height = 10, .height = 10,
}; };
} }
pub fn DrawTextEx(
font: rl.Font,
text: [*c]const u8,
pos_x: f32,
pos_y: f32,
font_size: f32,
spacing: f32,
color: rl.Color,
) void {
rl.DrawTextEx(font, text, rl.Vector2{ .x = pos_x, .y = pos_y }, font_size, spacing, color);
}
pub fn DrawAndMeasureTextEx( pub fn DrawAndMeasureTextEx(
font: rl.Font, font: rl.Font,
text: [*c]const u8, text: [*c]const u8,
pos_x: f32, pos_x: f32,
pos_y: f32, pos_y: f32,
font_size: f32, font_size: f32,
spacing: f32, spacing: f32,
color: rl.Color, color: rl.Color,
) rl.Vector2 { ) rl.Vector2 {
rl.DrawTextEx(font, text, rl.Vector2 { .x = pos_x, .y = pos_y }, font_size, spacing, color); rl.DrawTextEx(font, text, rl.Vector2{ .x = pos_x, .y = pos_y }, font_size, spacing, color);
return rl.MeasureTextEx(font, text, font_size, spacing); return rl.MeasureTextEx(font, text, font_size, spacing);
} }
pub fn DrawRightAlignedText( pub fn DrawRightAlignedText(
text: [*c]const u8, text: [*c]const u8,
@ -55,8 +66,8 @@ pub fn DrawRightAlignedText(
font_size: c_int, font_size: c_int,
color: rl.Color, color: rl.Color,
) void { ) void {
const width = rl.MeasureText(text, font_size); const width = rl.MeasureText(text, font_size);
rl.DrawText(text, pos_x - width, pos_y, font_size, color); rl.DrawText(text, pos_x - width, pos_y, font_size, color);
} }
pub fn DrawRightAlignedTextEx( pub fn DrawRightAlignedTextEx(
font: rl.Font, font: rl.Font,
@ -67,8 +78,8 @@ pub fn DrawRightAlignedTextEx(
spacing: f32, spacing: f32,
color: rl.Color, color: rl.Color,
) void { ) void {
const width = rl.MeasureTextEx(font, text, font_size, spacing).x; const width = rl.MeasureTextEx(font, text, font_size, spacing).x;
rl.DrawTextEx(font, text, .{ .x = pos_x - width, .y = pos_y }, font_size, spacing, color); rl.DrawTextEx(font, text, .{ .x = pos_x - width, .y = pos_y }, font_size, spacing, color);
} }
pub fn GetKeyPressed() ?c_int { pub fn GetKeyPressed() ?c_int {
const result = rl.GetKeyPressed(); const result = rl.GetKeyPressed();

Loading…
Cancel
Save