Add panel toggling via tab
This commit is contained in:
parent
d8bc9ac927
commit
3f9e33feaf
2 changed files with 15 additions and 1 deletions
|
|
@ -444,4 +444,9 @@ fn handleInput(entities: *sandbox.Entities, rng: *std.Random, paused: *bool) voi
|
||||||
if (rl.isKeyPressed(.space)) {
|
if (rl.isKeyPressed(.space)) {
|
||||||
paused.* = !paused.*;
|
paused.* = !paused.*;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toggle ui: tab
|
||||||
|
if (rl.isKeyPressed(.tab)) {
|
||||||
|
ui.show_ui = !ui.show_ui;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/ui.zig
11
src/ui.zig
|
|
@ -21,11 +21,19 @@ pub const dim_text_color = rl.Color.gray;
|
||||||
pub const highlight_color = rl.Color.yellow;
|
pub const highlight_color = rl.Color.yellow;
|
||||||
pub const box_bg = rl.Color{ .r = 0, .g = 0, .b = 0, .a = 200 };
|
pub const box_bg = rl.Color{ .r = 0, .g = 0, .b = 0, .a = 200 };
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// state
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
pub var show_ui: bool = true;
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// drawing functions
|
// drawing functions
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
pub fn drawMetrics(entities: *const sandbox.Entities, update_us: i64, render_us: i64, paused: bool, font: rl.Font) void {
|
pub fn drawMetrics(entities: *const sandbox.Entities, update_us: i64, render_us: i64, paused: bool, font: rl.Font) void {
|
||||||
|
if (!show_ui) return;
|
||||||
|
|
||||||
var buf: [256]u8 = undefined;
|
var buf: [256]u8 = undefined;
|
||||||
|
|
||||||
// fps box (above metrics)
|
// fps box (above metrics)
|
||||||
|
|
@ -75,7 +83,7 @@ pub fn drawMetrics(entities: *const sandbox.Entities, update_us: i64, render_us:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drawControls(font: rl.Font, metrics_bottom: i32) void {
|
fn drawControls(font: rl.Font, metrics_bottom: i32) void {
|
||||||
const ctrl_box_height: i32 = @intFromFloat(small_line_height * 4 + box_padding * 2);
|
const ctrl_box_height: i32 = @intFromFloat(small_line_height * 5 + box_padding * 2);
|
||||||
const ctrl_box_y: i32 = metrics_bottom + 5;
|
const ctrl_box_y: i32 = metrics_bottom + 5;
|
||||||
rl.drawRectangle(5, ctrl_box_y, 175, ctrl_box_height, box_bg);
|
rl.drawRectangle(5, ctrl_box_y, 175, ctrl_box_height, box_bg);
|
||||||
|
|
||||||
|
|
@ -86,6 +94,7 @@ fn drawControls(font: rl.Font, metrics_bottom: i32) void {
|
||||||
"shift +/-: 50k",
|
"shift +/-: 50k",
|
||||||
"space: pause",
|
"space: pause",
|
||||||
"r: reset",
|
"r: reset",
|
||||||
|
"tab: toggle ui",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (controls) |text| {
|
for (controls) |text| {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue