added layout time
This commit is contained in:
61
src/main.zig
61
src/main.zig
@@ -2,7 +2,7 @@ const std = @import("std");
|
||||
const rl = @import("rl");
|
||||
const bmb = @import("pandas_ui_lib");
|
||||
|
||||
fn getTextWidth(string: []const u8, font: rl.Font) i32 {
|
||||
fn getTextWidth(string: []const u8, font: rl.Font) f32 {
|
||||
var width: c_int = 0;
|
||||
for (string) |char| {
|
||||
width +=
|
||||
@@ -11,13 +11,13 @@ fn getTextWidth(string: []const u8, font: rl.Font) i32 {
|
||||
}
|
||||
|
||||
const s = @as([:0]const u8, @ptrCast(string));
|
||||
return @as(bmb.Real, @intCast(rl.measureText(s, @as(i32, @intCast(font.baseSize)))));
|
||||
return @as(bmb.Real, @floatFromInt(rl.measureText(s, font.baseSize)));
|
||||
}
|
||||
|
||||
fn getTextheight(string: []const u8, font: rl.Font) i32 {
|
||||
fn getTextheight(string: []const u8, font: rl.Font) f32 {
|
||||
_ = string;
|
||||
// std.debug.print("font.baseSize : {}\n", .{font.baseSize});
|
||||
return @as(bmb.Real, @intCast(font.baseSize));
|
||||
return @as(bmb.Real, @floatFromInt(font.baseSize));
|
||||
}
|
||||
|
||||
const TextType = bmb.TextType(rl.Font, getTextWidth, getTextheight);
|
||||
@@ -44,25 +44,32 @@ fn sideBar() UI.Node {
|
||||
}
|
||||
|
||||
fn button() UI.Node {
|
||||
return UI.Element(.{
|
||||
.name = "button",
|
||||
.rect = .{
|
||||
.h = 20,
|
||||
.w = 60,
|
||||
return UI.ElementWborder(
|
||||
.{ .bottom = 5, .left = 10, .right = 20, .top = 30 },
|
||||
.{
|
||||
.b = 30,
|
||||
},
|
||||
.style = .{
|
||||
.background_colour = .{
|
||||
.g = 255,
|
||||
.{
|
||||
.name = "button",
|
||||
.rect = .{
|
||||
.h = 20,
|
||||
.w = 60,
|
||||
},
|
||||
.style = .{
|
||||
.background_colour = .{
|
||||
.g = 255,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 1920;
|
||||
const screenHeight = 1080;
|
||||
const screenWidth = 1200;
|
||||
const screenHeight = 700;
|
||||
var timer = try std.time.Timer.start();
|
||||
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
defer rl.closeWindow(); // Close window and OpenGL context
|
||||
@@ -71,6 +78,7 @@ pub fn main() anyerror!void {
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
std.debug.print("bmb version :{s}\n", .{bmb.VERSON});
|
||||
std.debug.print("raylib time : {}\n", .{@divTrunc(timer.lap(), std.time.ns_per_ms)});
|
||||
|
||||
const child = &[_]UI.Node{
|
||||
sideBar(),
|
||||
@@ -83,7 +91,7 @@ pub fn main() anyerror!void {
|
||||
.padding = .{
|
||||
.bottom = 10,
|
||||
.left = 10,
|
||||
.right = 10,
|
||||
.right = 10.4,
|
||||
.top = 10,
|
||||
},
|
||||
},
|
||||
@@ -279,6 +287,7 @@ pub fn main() anyerror!void {
|
||||
},
|
||||
}),
|
||||
button(),
|
||||
button(),
|
||||
};
|
||||
|
||||
const root = UI.Element(.{
|
||||
@@ -311,6 +320,7 @@ pub fn main() anyerror!void {
|
||||
const sized = try UI.resolveSizing(al.allocator(), root);
|
||||
// UI.printTree(sized);
|
||||
const commands = try UI.getRenderCommands(sized, al.allocator());
|
||||
std.debug.print("layout time : {}\n", .{@divTrunc(timer.lap(), std.time.ns_per_ms)});
|
||||
|
||||
// Main game loop
|
||||
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
|
||||
@@ -331,12 +341,12 @@ pub fn main() anyerror!void {
|
||||
if (r.rounding) |rounding| {
|
||||
rl.drawRectangleRounded(
|
||||
rl.Rectangle.init(
|
||||
@as(f32, @floatFromInt(r.pos.x)),
|
||||
@as(f32, @floatFromInt(r.pos.y)),
|
||||
@as(f32, @floatFromInt(r.rect.w)),
|
||||
@as(f32, @floatFromInt(r.rect.h)),
|
||||
r.pos.x,
|
||||
r.pos.y,
|
||||
r.rect.w,
|
||||
r.rect.h,
|
||||
),
|
||||
@as(f32, @floatFromInt(rounding)) / 100.0,
|
||||
rounding / 100.0,
|
||||
10,
|
||||
rl.Color.init(
|
||||
r.colour.r,
|
||||
@@ -346,7 +356,12 @@ pub fn main() anyerror!void {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
rl.drawRectangle(r.pos.x, r.pos.y, r.rect.w, r.rect.h, rl.Color.init(
|
||||
rl.drawRectangleRec(rl.Rectangle.init(
|
||||
r.pos.x,
|
||||
r.pos.y,
|
||||
r.rect.w,
|
||||
r.rect.h,
|
||||
), rl.Color.init(
|
||||
r.colour.r,
|
||||
r.colour.g,
|
||||
r.colour.b,
|
||||
@@ -356,7 +371,7 @@ pub fn main() anyerror!void {
|
||||
},
|
||||
.text => |t| {
|
||||
const string = @as([:0]const u8, @ptrCast(t.text.string));
|
||||
rl.drawText(string, t.pos.x, t.pos.y, t.text.getTextHeight(), rl.Color.init(
|
||||
rl.drawText(string, @as(i32, @intFromFloat(t.pos.x)), @as(i32, @intFromFloat(t.pos.y)), @as(i32, @intFromFloat(t.text.getTextHeight())), rl.Color.init(
|
||||
t.text.colour.r,
|
||||
t.text.colour.g,
|
||||
t.text.colour.b,
|
||||
|
||||
Reference in New Issue
Block a user