updated to 0.16.0 and new text size func
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
const std = @import("std");
|
||||
const rl = @import("rl");
|
||||
const shoots = @import("root.zig");
|
||||
const shoots = @import("shoots");
|
||||
|
||||
fn getTextWidth(string: []const u8, font: rl.Font) shoots.Real {
|
||||
var width: c_int = 0;
|
||||
for (string) |char| {
|
||||
width +=
|
||||
@as(c_int, @intFromFloat(font.recs[char - 32].width)) +
|
||||
font.glyphs[char - 32].offsetX;
|
||||
}
|
||||
fn getTextSize(string: []const u8, font: rl.Font, max_width: ?shoots.Real) shoots.Rect {
|
||||
_ = max_width;
|
||||
|
||||
const s = @as([:0]const u8, @ptrCast(string));
|
||||
return @as(shoots.Real, @floatFromInt(rl.measureText(s, font.baseSize)));
|
||||
const text_size = rl.measureTextEx(
|
||||
font,
|
||||
@as([:0]const u8, @ptrCast(string)),
|
||||
@floatFromInt(font.baseSize),
|
||||
@floatFromInt(1),
|
||||
);
|
||||
|
||||
return shoots.Rect{
|
||||
.h = @as(shoots.Real, text_size.y),
|
||||
.w = @as(shoots.Real, text_size.x),
|
||||
};
|
||||
}
|
||||
|
||||
fn getTextheight(string: []const u8, font: rl.Font) shoots.Real {
|
||||
_ = string;
|
||||
// std.debug.print("font.baseSize : {}\n", .{font.baseSize});
|
||||
return @as(shoots.Real, @floatFromInt(font.baseSize));
|
||||
}
|
||||
|
||||
const TextType = shoots.TextType(rl.Font, getTextWidth, getTextheight);
|
||||
const TextType = shoots.TextType(rl.Font, getTextSize);
|
||||
const TextureType = shoots.TextureType(rl.Texture2D);
|
||||
|
||||
const UI = shoots.Shoots(TextType, TextureType);
|
||||
@@ -99,12 +97,14 @@ inline fn button() UI.Node {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
pub fn main(init: std.process.Init) anyerror!void {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 1200;
|
||||
const screenHeight = 700;
|
||||
var timer = try std.time.Timer.start();
|
||||
|
||||
const io = init.io;
|
||||
const start = std.Io.Clock.awake.now(io);
|
||||
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
defer rl.closeWindow(); // Close window and OpenGL context
|
||||
@@ -115,7 +115,7 @@ pub fn main() anyerror!void {
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
std.debug.print("shoots version :{s}\n", .{shoots.VERSION});
|
||||
std.debug.print("raylib time : {}\n", .{@divTrunc(timer.lap(), std.time.ns_per_ms)});
|
||||
std.debug.print("raylib time : {}ms\n", .{start.untilNow(io, .awake).toMilliseconds()});
|
||||
|
||||
var scroll_offset: shoots.Pos = .{};
|
||||
|
||||
@@ -144,9 +144,12 @@ pub fn main() anyerror!void {
|
||||
),
|
||||
UI.Txt(
|
||||
UI.Text.init(
|
||||
"hello world again",
|
||||
"hello world again \n this is a new line",
|
||||
try rl.getFontDefault(),
|
||||
.{},
|
||||
.{
|
||||
.b = 255,
|
||||
.r = 255,
|
||||
},
|
||||
).setBackground(.{
|
||||
.a = 255,
|
||||
.g = 255,
|
||||
@@ -358,8 +361,6 @@ pub fn main() anyerror!void {
|
||||
}),
|
||||
};
|
||||
|
||||
// root.Shoots(root.TextType(raylib.Font,(function 'getTextWidth'),(function 'getTextheight')),root.TextureType(raylib.Texture)).NodeTypes
|
||||
// root.Shoots(root.TextType(raylib.Font,(function 'getTextWidth'),(function 'getTextheight')),root.TextureType(raylib.Texture)).Node
|
||||
const root = UI.Element(.{
|
||||
.name = "root",
|
||||
.pos = .{
|
||||
@@ -402,7 +403,8 @@ pub fn main() anyerror!void {
|
||||
rl.beginDrawing();
|
||||
defer rl.endDrawing();
|
||||
// std.debug.print("starting layout\n", .{});
|
||||
_ = timer.lap();
|
||||
var start_time = std.Io.Timestamp.now(init.io, std.Io.Clock.awake);
|
||||
|
||||
var sized = try UI.resolveSizing(al.allocator(), root);
|
||||
|
||||
const mouse_pos = rl.getMousePosition();
|
||||
@@ -423,9 +425,7 @@ pub fn main() anyerror!void {
|
||||
|
||||
const commands = try UI.getRenderCommands(sized, al.allocator());
|
||||
// std.debug.print("{f}\n", .{sized});
|
||||
std.debug.print("layout time : {}ms\n", .{
|
||||
@as(f32, @floatFromInt(timer.lap())) / @as(f32, @floatFromInt(std.time.ns_per_ms)),
|
||||
});
|
||||
std.debug.print("layout time : {}ns\n", .{start_time.untilNow(io, .awake).toNanoseconds()});
|
||||
|
||||
for (commands.items) |command| {
|
||||
// std.debug.print("command : {any}\n", .{command});
|
||||
@@ -469,7 +469,7 @@ pub fn main() anyerror!void {
|
||||
string,
|
||||
@as(i32, @intFromFloat(t.pos.x)),
|
||||
@as(i32, @intFromFloat(t.pos.y)),
|
||||
@as(i32, @intFromFloat(t.text.getTextHeight())),
|
||||
@as(i32, t.text.font.baseSize),
|
||||
rl.Color.init(
|
||||
t.text.colour.r,
|
||||
t.text.colour.g,
|
||||
@@ -504,7 +504,7 @@ pub fn main() anyerror!void {
|
||||
// clip.rect.h,
|
||||
// ), .blue);
|
||||
},
|
||||
.clip_end => |_| {
|
||||
.clip_end => {
|
||||
rl.endScissorMode();
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user