papyrus compiles
This commit is contained in:
parent
cd27fcdb76
commit
1916c46e14
|
|
@ -87,6 +87,7 @@ pub const createNameRegistry = p2.createNameRegistry;
|
||||||
pub const destroyNameRegistry = p2.destroyNameRegistry;
|
pub const destroyNameRegistry = p2.destroyNameRegistry;
|
||||||
pub const setNameRegistry = p2.setNameRegistry;
|
pub const setNameRegistry = p2.setNameRegistry;
|
||||||
pub const NameRegistry = p2.NameRegistry;
|
pub const NameRegistry = p2.NameRegistry;
|
||||||
|
pub const NameInvalid = p2.NameInvalid;
|
||||||
|
|
||||||
pub const MergedSpans = p2.MergedSpans;
|
pub const MergedSpans = p2.MergedSpans;
|
||||||
pub const Span = p2.Span;
|
pub const Span = p2.Span;
|
||||||
|
|
@ -97,6 +98,7 @@ pub const math = @import("math.zig");
|
||||||
pub const Mat = math.Mat;
|
pub const Mat = math.Mat;
|
||||||
pub const Transform = math.Transform;
|
pub const Transform = math.Transform;
|
||||||
pub const Quat = math.Quat;
|
pub const Quat = math.Quat;
|
||||||
|
pub const Vector2i = math.Vector2i;
|
||||||
pub const Vectorf = math.Vectorf;
|
pub const Vectorf = math.Vectorf;
|
||||||
pub const Vector = math.Vector;
|
pub const Vector = math.Vector;
|
||||||
pub const Vector4 = math.Vector4;
|
pub const Vector4 = math.Vector4;
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,11 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
const test_step = b.step("test", "run unit tests for net");
|
const test_step = b.step("test", "run unit tests for net");
|
||||||
const tests = b.addTest(.{
|
const tests = b.addTest(.{
|
||||||
.target = target,
|
.root_module = b.createModule(.{
|
||||||
.optimize = optimize,
|
.target = target,
|
||||||
.root_source_file = b.path("tests/tests.zig"),
|
.optimize = optimize,
|
||||||
|
.root_source_file = b.path("tests/tests.zig"),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
tests.root_module.addImport("net", mod);
|
tests.root_module.addImport("net", mod);
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,5 @@
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
|
.fingerprint = 0xf2ea15fffd5f7fbc,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,12 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
// Creates a step for unit testing.
|
// Creates a step for unit testing.
|
||||||
const main_tests = b.addTest(.{
|
const main_tests = b.addTest(.{
|
||||||
.root_source_file = b.path("tests/testing.zig"),
|
.root_module = b.createModule(.{
|
||||||
.target = target,
|
.root_source_file = b.path("tests/testing.zig"),
|
||||||
.optimize = optimize,
|
.target = target,
|
||||||
.link_libc = true,
|
.optimize = optimize,
|
||||||
|
.link_libc = true,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
main_tests.root_module.addImport("core", core_dep.module("core"));
|
main_tests.root_module.addImport("core", core_dep.module("core"));
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,9 @@ pub fn render(self: *@This()) !void {
|
||||||
var timer = try std.time.Timer.start();
|
var timer = try std.time.Timer.start();
|
||||||
const tstart = timer.read();
|
const tstart = timer.read();
|
||||||
|
|
||||||
var drawList = papyrus.DrawList.init(self.ui.allocator);
|
var drawList: papyrus.DrawList = .{};
|
||||||
try self.ui.makeDrawList(&drawList, &self.arena);
|
try self.ui.makeDrawList(self.allocator, &drawList, &self.arena);
|
||||||
defer drawList.deinit();
|
defer drawList.deinit(self.allocator);
|
||||||
|
|
||||||
const tend = timer.read();
|
const tend = timer.read();
|
||||||
const duration = (@as(f64, @floatFromInt(tend - tstart)) / 1000);
|
const duration = (@as(f64, @floatFromInt(tend - tstart)) / 1000);
|
||||||
|
|
@ -266,10 +266,9 @@ pub const BmpWriter = struct {
|
||||||
cwd.makePath("Saved") catch unreachable;
|
cwd.makePath("Saved") catch unreachable;
|
||||||
var logFile = try cwd.createFile(outFile, .{});
|
var logFile = try cwd.createFile(outFile, .{});
|
||||||
defer logFile.close();
|
defer logFile.close();
|
||||||
var writer = logFile.writer();
|
try logFile.writeAll(std.mem.asBytes(&header));
|
||||||
try writer.writeAll(std.mem.asBytes(&header));
|
try logFile.writeAll(std.mem.asBytes(&info));
|
||||||
try writer.writeAll(std.mem.asBytes(&info));
|
try logFile.writeAll(self.pixelBuffer);
|
||||||
try writer.writeAll(self.pixelBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *@This()) void {
|
pub fn deinit(self: *@This()) void {
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,14 @@ ctx: *Context,
|
||||||
node: NodeHandle,
|
node: NodeHandle,
|
||||||
n: *const papyrus.Node,
|
n: *const papyrus.Node,
|
||||||
drawList: *DrawList,
|
drawList: *DrawList,
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
parentInfo: LayoutInfo,
|
parentInfo: LayoutInfo,
|
||||||
resolvedSize: Vector2f = .{},
|
resolvedSize: Vector2f = .{},
|
||||||
resolvedPos: Vector2f = .{},
|
resolvedPos: Vector2f = .{},
|
||||||
|
|
||||||
const papyrus = @import("papyrus.zig");
|
const papyrus = @import("papyrus.zig");
|
||||||
const core = @import("core");
|
const core = @import("core");
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
const Context = papyrus.Context;
|
const Context = papyrus.Context;
|
||||||
const LayoutInfo = papyrus.LayoutInfo;
|
const LayoutInfo = papyrus.LayoutInfo;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig").c;
|
||||||
|
|
||||||
const core = @import("core");
|
const core = @import("core");
|
||||||
const Vector2i = core.Vector2i;
|
const Vector2i = core.Vector2i;
|
||||||
const Vector2f = core.Vector2f;
|
const Vector2f = core.Vector2f;
|
||||||
const Name = core.Name;
|
const Name = core.Name;
|
||||||
|
|
||||||
|
const loadFileAlloc = utils.loadFileAlloc;
|
||||||
|
|
||||||
const colors = core.colors;
|
const colors = core.colors;
|
||||||
const ColorRGBA8 = colors.ColorRGBA8;
|
const ColorRGBA8 = colors.ColorRGBA8;
|
||||||
const Color = colors.Color;
|
const Color = colors.Color;
|
||||||
|
|
@ -13,7 +15,6 @@ const Color = colors.Color;
|
||||||
const LocText = @import("localization.zig").LocText;
|
const LocText = @import("localization.zig").LocText;
|
||||||
|
|
||||||
const utils = @import("utils.zig");
|
const utils = @import("utils.zig");
|
||||||
const loadFileAlloc = utils.loadFileAlloc;
|
|
||||||
const BmpWriter = @import("BmpRenderer.zig").BmpWriter;
|
const BmpWriter = @import("BmpRenderer.zig").BmpWriter;
|
||||||
|
|
||||||
name: Name,
|
name: Name,
|
||||||
|
|
@ -84,7 +85,7 @@ pub const FontAtlas = struct {
|
||||||
const rv = try initEmbeddedFont(allocator, bytes, fontSize, opts);
|
const rv = try initEmbeddedFont(allocator, bytes, fontSize, opts);
|
||||||
core.engine_log("[Fontcache] creating font cache for {s} font", .{fontName});
|
core.engine_log("[Fontcache] creating font cache for {s} font", .{fontName});
|
||||||
|
|
||||||
var cachedFontArchive = std.ArrayList(u8).init(allocator);
|
var cachedFontArchive = std.io.Writer.Allocating.init(allocator);
|
||||||
defer cachedFontArchive.deinit();
|
defer cachedFontArchive.deinit();
|
||||||
try rv.saveToArchive(&cachedFontArchive);
|
try rv.saveToArchive(&cachedFontArchive);
|
||||||
|
|
||||||
|
|
@ -93,12 +94,16 @@ pub const FontAtlas = struct {
|
||||||
const file = try std.fs.cwd().createFile(cacheFile, .{});
|
const file = try std.fs.cwd().createFile(cacheFile, .{});
|
||||||
defer file.close();
|
defer file.close();
|
||||||
|
|
||||||
try file.writeAll(cachedFontArchive.items);
|
var list = cachedFontArchive.toArrayList();
|
||||||
|
defer list.deinit(allocator);
|
||||||
|
|
||||||
|
try file.writeAll(list.items);
|
||||||
return rv;
|
return rv;
|
||||||
};
|
};
|
||||||
|
|
||||||
core.engine_log("[Fontcache] loading font cache for {s} font", .{fontName});
|
core.engine_log("[Fontcache] loading font cache for {s} font", .{fontName});
|
||||||
const archiveBytes = try loadFileAlloc(cacheFile, 8, allocator);
|
|
||||||
|
const archiveBytes = try utils.loadFileAlloc(cacheFile, .@"8", allocator); //(cacheFile, 8, allocator);
|
||||||
defer allocator.free(archiveBytes);
|
defer allocator.free(archiveBytes);
|
||||||
|
|
||||||
var rv = try initFromArchive(allocator, archiveBytes);
|
var rv = try initFromArchive(allocator, archiveBytes);
|
||||||
|
|
@ -149,7 +154,7 @@ pub const FontAtlas = struct {
|
||||||
var self = @This(){
|
var self = @This(){
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.filePath = file,
|
.filePath = file,
|
||||||
.fileContent = try loadFileAlloc(file, 8, allocator),
|
.fileContent = try loadFileAlloc(file, .@"8", allocator),
|
||||||
.atlasBuffer = null,
|
.atlasBuffer = null,
|
||||||
.fontSize = fontSize,
|
.fontSize = fontSize,
|
||||||
.isSDF = true,
|
.isSDF = true,
|
||||||
|
|
@ -182,7 +187,7 @@ pub const FontAtlas = struct {
|
||||||
var self = @This(){
|
var self = @This(){
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.filePath = file,
|
.filePath = file,
|
||||||
.fileContent = try loadFileAlloc(file, 8, allocator),
|
.fileContent = try loadFileAlloc(file, .@"8", allocator),
|
||||||
.atlasBuffer = null,
|
.atlasBuffer = null,
|
||||||
.fontSize = fontSize,
|
.fontSize = fontSize,
|
||||||
.isMonospace = opts.isMonospace,
|
.isMonospace = opts.isMonospace,
|
||||||
|
|
@ -211,27 +216,26 @@ pub const FontAtlas = struct {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn saveToArchive(self: @This(), out: *std.ArrayList(u8)) !void {
|
pub fn saveToArchive(self: @This(), o: *std.io.Writer.Allocating) !void {
|
||||||
var writer = out.writer();
|
const writer = &o.writer;
|
||||||
|
|
||||||
try writer.writeInt(u8, @intFromBool(self.isSDF), .little); // isSDF
|
try writer.writeInt(u8, @intFromBool(self.isSDF), .little); // isSDF
|
||||||
try writer.writeInt(u32, @bitCast(self.fontSize), .little); // fontSize: f32 = 0,
|
try writer.writeInt(u32, @bitCast(self.fontSize), .little); // fontSize: f32 = 0,
|
||||||
try writer.writeStruct(self.atlasSize); // atlasSize: Vector2i = .{},
|
try writer.writeStruct(self.atlasSize, .little); // atlasSize: Vector2i = .{},
|
||||||
try writer.writeStruct(self.glyphMax); // glyphMax: Vector2i = .{},
|
try writer.writeStruct(self.glyphMax, .little); // glyphMax: Vector2i = .{},
|
||||||
try writer.writeInt(i32, self.glyphStride, .little); // glyphStride: i32 = 0,
|
try writer.writeInt(i32, self.glyphStride, .little); // glyphStride: i32 = 0,
|
||||||
try writer.writeInt(u32, @bitCast(self.scale), .little); // scale: f32 = 0,
|
try writer.writeInt(u32, @bitCast(self.scale), .little); // scale: f32 = 0,
|
||||||
try writer.writeInt(u32, @bitCast(self.lineSize), .little); // lineSize: f32 = 0,
|
try writer.writeInt(u32, @bitCast(self.lineSize), .little); // lineSize: f32 = 0,
|
||||||
try writer.writeInt(u8, @intFromBool(self.isMonospace), .little); // isMonospace: bool = false,
|
try writer.writeInt(u8, @intFromBool(self.isMonospace), .little); // isMonospace: bool = false,
|
||||||
for (self.glyphMetrics) |x| { // glyphMetrics: [256]Vector2i = undefined,
|
for (self.glyphMetrics) |x| { // glyphMetrics: [256]Vector2i = undefined,
|
||||||
try writer.writeStruct(x);
|
try writer.writeStruct(x, .little);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (self.glyphBox0) |x| { // glyphBox0: [256]Vector2i = undefined,
|
for (self.glyphBox0) |x| { // glyphBox0: [256]Vector2i = undefined,
|
||||||
try writer.writeStruct(x);
|
try writer.writeStruct(x, .little);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (self.glyphBox1) |x| { // glyphBox1: [256]Vector2i = undefined,
|
for (self.glyphBox1) |x| { // glyphBox1: [256]Vector2i = undefined,
|
||||||
try writer.writeStruct(x);
|
try writer.writeStruct(x, .little);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (self.hasGlyph) |x| { // hasGlyph: [256]bool = undefined,
|
for (self.hasGlyph) |x| { // hasGlyph: [256]bool = undefined,
|
||||||
|
|
@ -240,13 +244,13 @@ pub const FontAtlas = struct {
|
||||||
|
|
||||||
for (self.meshes) |x| { // meshes: [256][4]Vector2f = undefined,
|
for (self.meshes) |x| { // meshes: [256][4]Vector2f = undefined,
|
||||||
for (x) |y| {
|
for (x) |y| {
|
||||||
try writer.writeStruct(y);
|
try writer.writeStruct(y, .little);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (self.glyphCoordinates) |x| { // glyphCoordinates: [256][2]Vector2f = undefined,
|
for (self.glyphCoordinates) |x| { // glyphCoordinates: [256][2]Vector2f = undefined,
|
||||||
for (x) |y| {
|
for (x) |y| {
|
||||||
try writer.writeStruct(y);
|
try writer.writeStruct(y, .little);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,13 +66,14 @@ pub fn deinit(self: *@This()) void {
|
||||||
|
|
||||||
pub fn addMousePickInfo(
|
pub fn addMousePickInfo(
|
||||||
self: @This(),
|
self: @This(),
|
||||||
|
drawListAllocator: std.mem.Allocator,
|
||||||
papyrusCtx: *const Context,
|
papyrusCtx: *const Context,
|
||||||
drawList: *papyrus.DrawList,
|
drawList: *papyrus.DrawList,
|
||||||
) !void {
|
) !void {
|
||||||
const selected_node = self.selected_node orelse return;
|
const selected_node = self.selected_node orelse return;
|
||||||
const layoutInfo = papyrusCtx._displayLayout.items[selected_node.index];
|
const layoutInfo = papyrusCtx._displayLayout.items[selected_node.index];
|
||||||
|
|
||||||
try drawList.append(.{
|
try drawList.append(drawListAllocator, .{
|
||||||
.node = .{},
|
.node = .{},
|
||||||
.primitive = .{
|
.primitive = .{
|
||||||
.Rect = .{
|
.Rect = .{
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
pub usingnamespace @cImport({
|
pub const c = @cImport({
|
||||||
@cInclude("stb_ttf.h");
|
@cInclude("stb_ttf.h");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -478,13 +478,13 @@ pub const Context = struct {
|
||||||
.defaultBitmapFont = ctx.fontCache.defaultBitmapFont,
|
.defaultBitmapFont = ctx.fontCache.defaultBitmapFont,
|
||||||
|
|
||||||
.textEntry = try TextEntrySystem.create(self, allocator),
|
.textEntry = try TextEntrySystem.create(self, allocator),
|
||||||
._drawOrder = DrawOrderList.init(allocator),
|
._drawOrder = .{},
|
||||||
._layout = .{},
|
._layout = .{},
|
||||||
._layoutNodes = .{},
|
._layoutNodes = .{},
|
||||||
._horizontalLayout = .{},
|
._horizontalLayout = .{},
|
||||||
.debugText = std.ArrayList(DebugLogTextEntry).init(allocator),
|
.debugText = .{},
|
||||||
|
.rootNodes = .{},
|
||||||
.mousePick = Layout.init(allocator),
|
.mousePick = Layout.init(allocator),
|
||||||
.rootNodes = std.ArrayList(NodeHandle).init(allocator),
|
|
||||||
.stringArena = std.heap.ArenaAllocator.init(allocator),
|
.stringArena = std.heap.ArenaAllocator.init(allocator),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -503,7 +503,7 @@ pub const Context = struct {
|
||||||
pub fn pushDebugTextSlice(self: *@This(), slice: []const u8, _color: ?Color) !void {
|
pub fn pushDebugTextSlice(self: *@This(), slice: []const u8, _color: ?Color) !void {
|
||||||
const color = if (_color == null) Color.Yellow else _color.?;
|
const color = if (_color == null) Color.Yellow else _color.?;
|
||||||
if (self.debugText.items.len < debugTextMax) {
|
if (self.debugText.items.len < debugTextMax) {
|
||||||
try self.debugText.append(.{
|
try self.debugText.append(self.allocator, .{
|
||||||
.text = self.stringArena.allocator().dupe(slice) catch "",
|
.text = self.stringArena.allocator().dupe(slice) catch "",
|
||||||
.color = color,
|
.color = color,
|
||||||
});
|
});
|
||||||
|
|
@ -514,7 +514,7 @@ pub const Context = struct {
|
||||||
const color = if (_color == null) Color.Yellow else _color.?;
|
const color = if (_color == null) Color.Yellow else _color.?;
|
||||||
|
|
||||||
if (self.debugText.items.len < debugTextMax) {
|
if (self.debugText.items.len < debugTextMax) {
|
||||||
try self.debugText.append(.{
|
try self.debugText.append(self.allocator, .{
|
||||||
.text = std.fmt.allocPrint(self.stringArena.allocator(), fmt, args) catch "",
|
.text = std.fmt.allocPrint(self.stringArena.allocator(), fmt, args) catch "",
|
||||||
.color = color,
|
.color = color,
|
||||||
});
|
});
|
||||||
|
|
@ -538,7 +538,7 @@ pub const Context = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.rootNodes.deinit();
|
self.rootNodes.deinit(self.allocator);
|
||||||
|
|
||||||
self.mousePick.deinit();
|
self.mousePick.deinit();
|
||||||
|
|
||||||
|
|
@ -546,7 +546,7 @@ pub const Context = struct {
|
||||||
|
|
||||||
self.nodes.deinit();
|
self.nodes.deinit();
|
||||||
self.events.deinit();
|
self.events.deinit();
|
||||||
self._drawOrder.deinit();
|
self._drawOrder.deinit(self.allocator);
|
||||||
self._layout.deinit(self.allocator);
|
self._layout.deinit(self.allocator);
|
||||||
self._layoutNodes.deinit(self.allocator);
|
self._layoutNodes.deinit(self.allocator);
|
||||||
|
|
||||||
|
|
@ -558,7 +558,7 @@ pub const Context = struct {
|
||||||
for (self.debugText.items) |text| {
|
for (self.debugText.items) |text| {
|
||||||
_ = text;
|
_ = text;
|
||||||
}
|
}
|
||||||
self.debugText.deinit();
|
self.debugText.deinit(self.allocator);
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -722,7 +722,8 @@ pub const Context = struct {
|
||||||
|
|
||||||
pub fn addTextEntry_experimental(self: *@This(), parent: NodeHandle, text: ?[]const u8) !NodeHandle {
|
pub fn addTextEntry_experimental(self: *@This(), parent: NodeHandle, text: ?[]const u8) !NodeHandle {
|
||||||
var textProperty = NodeProperty_TextEntry{
|
var textProperty = NodeProperty_TextEntry{
|
||||||
.editText = std.ArrayList(u8).init(self.allocator),
|
.editText = .{},
|
||||||
|
.allcator = self.allocator,
|
||||||
.font = self.defaultFont,
|
.font = self.defaultFont,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -780,8 +781,8 @@ pub const Context = struct {
|
||||||
|
|
||||||
try assertf(node.index != 0, "removeFromParent CANNOT be called on the root node", .{});
|
try assertf(node.index != 0, "removeFromParent CANNOT be called on the root node", .{});
|
||||||
|
|
||||||
var killList = std.ArrayList(NodeHandle).init(self.allocator);
|
var killList = std.ArrayList(NodeHandle){};
|
||||||
defer killList.deinit();
|
defer killList.deinit(self.allocator);
|
||||||
self.walkNodesToRemove(node, &killList) catch {
|
self.walkNodesToRemove(node, &killList) catch {
|
||||||
for (killList.items) |n| {
|
for (killList.items) |n| {
|
||||||
_ = n;
|
_ = n;
|
||||||
|
|
@ -818,7 +819,7 @@ pub const Context = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walkNodesToRemove(self: @This(), root: NodeHandle, killList: *std.ArrayList(NodeHandle)) !void {
|
fn walkNodesToRemove(self: @This(), root: NodeHandle, killList: *std.ArrayList(NodeHandle)) !void {
|
||||||
try killList.append(root);
|
try killList.append(self.allocator, root);
|
||||||
|
|
||||||
var next = self.getRead(root).child;
|
var next = self.getRead(root).child;
|
||||||
|
|
||||||
|
|
@ -837,7 +838,7 @@ pub const Context = struct {
|
||||||
if (self.getRead(next).state != .Visible) {
|
if (self.getRead(next).state != .Visible) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try list.append(next);
|
try list.append(self.allocator, next);
|
||||||
try self.assembleDrawOrderListForNode(next, list);
|
try self.assembleDrawOrderListForNode(next, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -850,7 +851,7 @@ pub const Context = struct {
|
||||||
if (self.getRead(next).state != .Visible) {
|
if (self.getRead(next).state != .Visible) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try self.rootNodes.append(next);
|
try self.rootNodes.append(self.allocator, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
const SortFunc = struct {
|
const SortFunc = struct {
|
||||||
|
|
@ -867,7 +868,7 @@ pub const Context = struct {
|
||||||
);
|
);
|
||||||
|
|
||||||
for (self.rootNodes.items) |rootNode| {
|
for (self.rootNodes.items) |rootNode| {
|
||||||
try list.append(rootNode);
|
try list.append(self.allocator, rootNode);
|
||||||
try self.assembleDrawOrderListForNode(rootNode, list);
|
try self.assembleDrawOrderListForNode(rootNode, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1016,7 +1017,7 @@ pub const Context = struct {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn makeDrawList(self: *@This(), drawList: *DrawList, stringArena: *std.heap.ArenaAllocator) !void {
|
pub fn makeDrawList(self: *@This(), drawlistAllocator: std.mem.Allocator, drawList: *DrawList, stringArena: *std.heap.ArenaAllocator) !void {
|
||||||
_ = stringArena.reset(.retain_capacity);
|
_ = stringArena.reset(.retain_capacity);
|
||||||
|
|
||||||
// do not re allocate these, instead use a preallocated pool
|
// do not re allocate these, instead use a preallocated pool
|
||||||
|
|
@ -1050,6 +1051,7 @@ pub const Context = struct {
|
||||||
|
|
||||||
var dlb = DrawListBuilder{
|
var dlb = DrawListBuilder{
|
||||||
.ctx = self,
|
.ctx = self,
|
||||||
|
.allocator = drawlistAllocator,
|
||||||
.node = node,
|
.node = node,
|
||||||
.drawList = drawList,
|
.drawList = drawList,
|
||||||
.n = n,
|
.n = n,
|
||||||
|
|
@ -1093,7 +1095,7 @@ pub const Context = struct {
|
||||||
if (panel.hasTitle) {
|
if (panel.hasTitle) {
|
||||||
|
|
||||||
// draw the main image.
|
// draw the main image.
|
||||||
try drawList.append(.{ .node = node, .primitive = .{
|
try drawList.append(drawlistAllocator, .{ .node = node, .primitive = .{
|
||||||
.Rect = .{
|
.Rect = .{
|
||||||
.tl = dlb.resolvedPos.add(.{ .y = panel.titleSize }),
|
.tl = dlb.resolvedPos.add(.{ .y = panel.titleSize }),
|
||||||
.size = dlb.resolvedSize.sub(.{ .y = panel.titleSize }),
|
.size = dlb.resolvedSize.sub(.{ .y = panel.titleSize }),
|
||||||
|
|
@ -1108,7 +1110,7 @@ pub const Context = struct {
|
||||||
} });
|
} });
|
||||||
|
|
||||||
// draw the title bar
|
// draw the title bar
|
||||||
try drawList.append(.{ .node = node, .primitive = .{
|
try drawList.append(drawlistAllocator, .{ .node = node, .primitive = .{
|
||||||
.Rect = .{
|
.Rect = .{
|
||||||
.tl = dlb.resolvedPos,
|
.tl = dlb.resolvedPos,
|
||||||
.size = .{ .x = dlb.resolvedSize.x, .y = panel.titleSize },
|
.size = .{ .x = dlb.resolvedSize.x, .y = panel.titleSize },
|
||||||
|
|
@ -1121,7 +1123,7 @@ pub const Context = struct {
|
||||||
},
|
},
|
||||||
} });
|
} });
|
||||||
|
|
||||||
try drawList.append(.{
|
try drawList.append(drawlistAllocator, .{
|
||||||
.node = node,
|
.node = node,
|
||||||
.primitive = .{
|
.primitive = .{
|
||||||
.Text = .{
|
.Text = .{
|
||||||
|
|
@ -1149,7 +1151,7 @@ pub const Context = struct {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// draw the main image
|
// draw the main image
|
||||||
try drawList.append(.{ .node = node, .primitive = .{
|
try drawList.append(drawlistAllocator, .{ .node = node, .primitive = .{
|
||||||
.Rect = .{
|
.Rect = .{
|
||||||
.tl = dlb.resolvedPos,
|
.tl = dlb.resolvedPos,
|
||||||
.size = dlb.resolvedSize,
|
.size = dlb.resolvedSize,
|
||||||
|
|
@ -1174,7 +1176,7 @@ pub const Context = struct {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.DisplayText => |txt| {
|
.DisplayText => |txt| {
|
||||||
try drawList.append(.{
|
try drawList.append(drawlistAllocator, .{
|
||||||
.node = node,
|
.node = node,
|
||||||
.primitive = .{
|
.primitive = .{
|
||||||
.Text = .{
|
.Text = .{
|
||||||
|
|
@ -1212,11 +1214,11 @@ pub const Context = struct {
|
||||||
|
|
||||||
if (self.debugEnabled) {
|
if (self.debugEnabled) {
|
||||||
if (self.drawDebug) {
|
if (self.drawDebug) {
|
||||||
try self.addDebugInfo(drawList);
|
try self.addDebugInfo(drawlistAllocator, drawList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.debugMousePick) {
|
if (self.debugMousePick) {
|
||||||
try self.mousePick.addMousePickInfo(self, drawList);
|
try self.mousePick.addMousePickInfo(drawlistAllocator, self, drawList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (self.debugLogText.items.len) {
|
// if (self.debugLogText.items.len) {
|
||||||
|
|
@ -1227,7 +1229,7 @@ pub const Context = struct {
|
||||||
for (0..drawList.items.len) |i| {
|
for (0..drawList.items.len) |i| {
|
||||||
switch (drawList.items[i].primitive) {
|
switch (drawList.items[i].primitive) {
|
||||||
.Text => |*text| {
|
.Text => |*text| {
|
||||||
text.text.utf8 = try core.dupeString(stringArena.allocator(), text.text.utf8);
|
text.text.utf8 = try stringArena.allocator().dupe(u8, text.text.utf8);
|
||||||
},
|
},
|
||||||
.Rect => {},
|
.Rect => {},
|
||||||
}
|
}
|
||||||
|
|
@ -1261,7 +1263,7 @@ pub const Context = struct {
|
||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
fn addDebugInfo(self: @This(), drawList: *DrawList) !void {
|
fn addDebugInfo(self: @This(), drawlistAllocator: std.mem.Allocator, drawList: *DrawList) !void {
|
||||||
const defaultHeight = self.debugFontSize;
|
const defaultHeight = self.debugFontSize;
|
||||||
const yOffsetPerLine: f32 = defaultHeight + 1;
|
const yOffsetPerLine: f32 = defaultHeight + 1;
|
||||||
const sizePerLine: f32 = yOffsetPerLine + (yOffsetPerLine / 4);
|
const sizePerLine: f32 = yOffsetPerLine + (yOffsetPerLine / 4);
|
||||||
|
|
@ -1270,7 +1272,7 @@ pub const Context = struct {
|
||||||
|
|
||||||
const fontHandle = self.fontCache.defaultMonoFont.atlas.fontHandle;
|
const fontHandle = self.fontCache.defaultMonoFont.atlas.fontHandle;
|
||||||
|
|
||||||
try drawList.append(.{
|
try drawList.append(drawlistAllocator, .{
|
||||||
.node = .{},
|
.node = .{},
|
||||||
.primitive = .{
|
.primitive = .{
|
||||||
.Rect = .{
|
.Rect = .{
|
||||||
|
|
@ -1307,7 +1309,7 @@ pub const Context = struct {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try drawList.append(.{
|
try drawList.append(drawlistAllocator, .{
|
||||||
.node = .{ .index = @intCast(i) },
|
.node = .{ .index = @intCast(i) },
|
||||||
.primitive = .{
|
.primitive = .{
|
||||||
.Text = .{
|
.Text = .{
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ pub fn addToDrawList(dlb: DrawListBuilder) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
try drawlist.append(
|
try drawlist.append(
|
||||||
|
dlb.allocator,
|
||||||
.{ .node = dlb.node, .primitive = .{ .Rect = .{
|
.{ .node = dlb.node, .primitive = .{ .Rect = .{
|
||||||
.tl = dlb.resolvedPos,
|
.tl = dlb.resolvedPos,
|
||||||
.size = dlb.resolvedSize,
|
.size = dlb.resolvedSize,
|
||||||
|
|
@ -81,7 +82,7 @@ pub fn addToDrawList(dlb: DrawListBuilder) !void {
|
||||||
} } },
|
} } },
|
||||||
);
|
);
|
||||||
|
|
||||||
try drawlist.append(.{
|
try drawlist.append(dlb.allocator, .{
|
||||||
.node = dlb.node,
|
.node = dlb.node,
|
||||||
.primitive = .{
|
.primitive = .{
|
||||||
.Text = .{
|
.Text = .{
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ entryState: TextEntryState = .Normal,
|
||||||
entryStubPosition: u32 = 0,
|
entryStubPosition: u32 = 0,
|
||||||
textEntryStyle: TextEntryStyle = .{},
|
textEntryStyle: TextEntryStyle = .{},
|
||||||
editText: std.ArrayList(u8),
|
editText: std.ArrayList(u8),
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
enterSendsNewline: bool = true,
|
enterSendsNewline: bool = true,
|
||||||
|
|
||||||
pub const TextEntryStyle = struct {
|
pub const TextEntryStyle = struct {
|
||||||
|
|
@ -57,7 +58,7 @@ pub fn addToDrawList(dlb: DrawListBuilder) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. draw the main rect for Text.
|
// 1. draw the main rect for Text.
|
||||||
try drawlist.append(.{
|
try drawlist.append(dlb.allocator, .{
|
||||||
.node = dlb.node,
|
.node = dlb.node,
|
||||||
.primitive = .{ .Rect = .{
|
.primitive = .{ .Rect = .{
|
||||||
.tl = dlb.resolvedPos,
|
.tl = dlb.resolvedPos,
|
||||||
|
|
@ -68,7 +69,7 @@ pub fn addToDrawList(dlb: DrawListBuilder) !void {
|
||||||
} },
|
} },
|
||||||
});
|
});
|
||||||
|
|
||||||
try drawlist.append(.{
|
try drawlist.append(dlb.allocator, .{
|
||||||
.node = dlb.node,
|
.node = dlb.node,
|
||||||
.primitive = .{
|
.primitive = .{
|
||||||
.Text = .{
|
.Text = .{
|
||||||
|
|
@ -120,7 +121,7 @@ pub fn addToDrawList(dlb: DrawListBuilder) !void {
|
||||||
const geo = hr.characterGeo;
|
const geo = hr.characterGeo;
|
||||||
const width: f32 = 2.0;
|
const width: f32 = 2.0;
|
||||||
|
|
||||||
try drawlist.append(.{
|
try drawlist.append(dlb.allocator, .{
|
||||||
.node = dlb.node,
|
.node = dlb.node,
|
||||||
.primitive = .{
|
.primitive = .{
|
||||||
.Rect = .{
|
.Rect = .{
|
||||||
|
|
@ -138,7 +139,7 @@ pub fn addToDrawList(dlb: DrawListBuilder) !void {
|
||||||
|
|
||||||
pub fn tearDown(ctx: *papyrus.Context, node: papyrus.NodeHandle) void {
|
pub fn tearDown(ctx: *papyrus.Context, node: papyrus.NodeHandle) void {
|
||||||
var textEntry = ctx.getTextEntry(node);
|
var textEntry = ctx.getTextEntry(node);
|
||||||
textEntry.editText.deinit();
|
textEntry.editText.deinit(textEntry.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======
|
// ======
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ const core = @import("core");
|
||||||
const Name = core.Name;
|
const Name = core.Name;
|
||||||
const MakeName = core.Name;
|
const MakeName = core.Name;
|
||||||
|
|
||||||
pub fn loadFileAlloc(filename: []const u8, comptime alignment: usize, allocator: std.mem.Allocator) ![]u8 {
|
pub fn loadFileAlloc(filename: []const u8, comptime alignment: std.mem.Alignment, allocator: std.mem.Allocator) ![]u8 {
|
||||||
var file = try std.fs.cwd().openFile(filename, .{});
|
var file = try std.fs.cwd().openFile(filename, .{});
|
||||||
const filesize = (try file.stat()).size;
|
const filesize = (try file.stat()).size;
|
||||||
const buffer: []u8 = try allocator.alignedAlloc(u8, alignment, filesize);
|
const buffer: []u8 = try allocator.alignedAlloc(u8, alignment, filesize);
|
||||||
try file.reader().readNoEof(buffer);
|
_ = try file.readAll(buffer);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,15 +38,14 @@ pub const FileLog = struct {
|
||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator, fileName: []const u8) !@This() {
|
pub fn init(allocator: std.mem.Allocator, fileName: []const u8) !@This() {
|
||||||
return .{
|
return .{
|
||||||
.buffer = std.ArrayList(u8).init(allocator),
|
.buffer = .{},
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.fileName = try dupeString(allocator, fileName),
|
.fileName = try dupeString(allocator, fileName),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(self: *@This(), comptime fmt: []const u8, args: anytype) !void {
|
pub fn write(self: *@This(), comptime fmt: []const u8, args: anytype) !void {
|
||||||
var writer = self.buffer.writer();
|
try self.buffer.print(self.allocator, fmt, args);
|
||||||
try writer.print(fmt, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn writeOut(self: @This()) !void {
|
pub fn writeOut(self: @This()) !void {
|
||||||
|
|
@ -59,7 +58,7 @@ pub const FileLog = struct {
|
||||||
|
|
||||||
pub fn deinit(self: *@This()) void {
|
pub fn deinit(self: *@This()) void {
|
||||||
self.allocator.free(self.fileName);
|
self.allocator.free(self.fileName);
|
||||||
self.buffer.deinit();
|
self.buffer.deinit(self.allocator);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ test "sdf texture generation" {
|
||||||
const allocator = std.testing.allocator;
|
const allocator = std.testing.allocator;
|
||||||
var font: c.stbtt_fontinfo = undefined;
|
var font: c.stbtt_fontinfo = undefined;
|
||||||
|
|
||||||
const fileContent = try utils.loadFileAlloc("fonts/FiraMono-Medium.ttf", 8, allocator);
|
const fileContent = try utils.loadFileAlloc("fonts/FiraMono-Medium.ttf", .@"8", allocator);
|
||||||
defer allocator.free(fileContent);
|
defer allocator.free(fileContent);
|
||||||
|
|
||||||
_ = c.stbtt_InitFont(&font, fileContent.ptr, c.stbtt_GetFontOffsetForIndex(fileContent.ptr, 0));
|
_ = c.stbtt_InitFont(&font, fileContent.ptr, c.stbtt_GetFontOffsetForIndex(fileContent.ptr, 0));
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,11 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
// ========== tests ==========
|
// ========== tests ==========
|
||||||
const tests = b.addTest(.{
|
const tests = b.addTest(.{
|
||||||
.target = target,
|
.root_module = b.createModule(.{
|
||||||
.optimize = optimize,
|
.target = target,
|
||||||
.root_source_file = b.path("tests/tests.zig"),
|
.optimize = optimize,
|
||||||
|
.root_source_file = b.path("tests/tests.zig"),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
const test_step = b.step("test", "run unit tests for ui");
|
const test_step = b.step("test", "run unit tests for ui");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ pub fn build(b: *std.Build) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
|
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
|
||||||
|
_ = static_build;
|
||||||
|
|
||||||
const mod = b.addModule("zgltf", .{
|
const mod = b.addModule("zgltf", .{
|
||||||
.root_source_file = b.path("src/zgltf.zig"),
|
.root_source_file = b.path("src/zgltf.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue