diff --git a/src/Recents.zig b/src/Recents.zig index c21fac8..59f9966 100644 --- a/src/Recents.zig +++ b/src/Recents.zig @@ -1,12 +1,12 @@ const std = @import("std"); const Pixi = @import("Pixi.zig"); -const Self = @This(); +const Recents = @This(); folders: std.ArrayList([:0]const u8), exports: std.ArrayList([:0]const u8), -pub fn init(allocator: std.mem.Allocator) !Self { +pub fn init(allocator: std.mem.Allocator) !Recents { var folders = std.ArrayList([:0]const u8).init(allocator); var exports = std.ArrayList([:0]const u8).init(allocator); @@ -36,78 +36,78 @@ pub fn init(allocator: std.mem.Allocator) !Self { return .{ .folders = folders, .exports = exports }; } -pub fn indexOfFolder(self: *Self, path: [:0]const u8) ?usize { - if (self.folders.items.len == 0) return null; +pub fn indexOfFolder(recents: *Recents, path: [:0]const u8) ?usize { + if (recents.folders.items.len == 0) return null; - for (self.folders.items, 0..) |folder, i| { + for (recents.folders.items, 0..) |folder, i| { if (std.mem.eql(u8, folder, path)) return i; } return null; } -pub fn indexOfExport(self: *Self, path: [:0]const u8) ?usize { - if (self.exports.items.len == 0) return null; +pub fn indexOfExport(recents: *Recents, path: [:0]const u8) ?usize { + if (recents.exports.items.len == 0) return null; - for (self.exports.items, 0..) |exp, i| { + for (recents.exports.items, 0..) |exp, i| { if (std.mem.eql(u8, exp, path)) return i; } return null; } -pub fn appendFolder(self: *Self, path: [:0]const u8) !void { - if (self.indexOfFolder(path)) |index| { +pub fn appendFolder(recents: *Recents, path: [:0]const u8) !void { + if (recents.indexOfFolder(path)) |index| { Pixi.state.allocator.free(path); - const folder = self.folders.swapRemove(index); - try self.folders.append(folder); + const folder = recents.folders.swapRemove(index); + try recents.folders.append(folder); } else { - if (self.folders.items.len >= Pixi.state.settings.max_recents) { - const folder = self.folders.swapRemove(0); + if (recents.folders.items.len >= Pixi.state.settings.max_recents) { + const folder = recents.folders.swapRemove(0); Pixi.state.allocator.free(folder); } - try self.folders.append(path); + try recents.folders.append(path); } } -pub fn appendExport(self: *Self, path: [:0]const u8) !void { - if (self.indexOfExport(path)) |index| { - const exp = self.exports.swapRemove(index); - try self.exports.append(exp); +pub fn appendExport(recents: *Recents, path: [:0]const u8) !void { + if (recents.indexOfExport(path)) |index| { + const exp = recents.exports.swapRemove(index); + try recents.exports.append(exp); } else { - if (self.exports.items.len >= Pixi.state.settings.max_recents) { - const exp = self.folders.swapRemove(0); + if (recents.exports.items.len >= Pixi.state.settings.max_recents) { + const exp = recents.folders.swapRemove(0); Pixi.state.allocator.free(exp); } - try self.exports.append(path); + try recents.exports.append(path); } } -pub fn save(self: *Self) !void { +pub fn save(recents: *Recents) !void { var handle = try std.fs.cwd().createFile("recents.json", .{}); defer handle.close(); const out_stream = handle.writer(); const options = std.json.StringifyOptions{}; - try std.json.stringify(RecentsJson{ .folders = self.folders.items, .exports = self.exports.items }, options, out_stream); + try std.json.stringify(RecentsJson{ .folders = recents.folders.items, .exports = recents.exports.items }, options, out_stream); } -pub fn deinit(self: *Self) void { - for (self.folders.items) |folder| { +pub fn deinit(recents: *Recents) void { + for (recents.folders.items) |folder| { Pixi.state.allocator.free(folder); } - for (self.exports.items) |exp| { + for (recents.exports.items) |exp| { Pixi.state.allocator.free(exp); } - self.folders.clearAndFree(); - self.folders.deinit(); + recents.folders.clearAndFree(); + recents.folders.deinit(); - self.exports.clearAndFree(); - self.exports.deinit(); + recents.exports.clearAndFree(); + recents.exports.deinit(); } const RecentsJson = struct { diff --git a/src/Settings.zig b/src/Settings.zig index f10e4b8..2a1df22 100644 --- a/src/Settings.zig +++ b/src/Settings.zig @@ -4,7 +4,7 @@ const std = @import("std"); pub const settings_filename = "settings.json"; -const Self = @This(); +const Settings = @This(); //get the path to the settings file fn getSettingsPath(allocator: std.mem.Allocator) ![]const u8 { @@ -17,7 +17,7 @@ fn getSettingsPath(allocator: std.mem.Allocator) ![]const u8 { } ///Reads in default settings or reads from the settings file -pub fn init(allocator: std.mem.Allocator) !Self { +pub fn init(allocator: std.mem.Allocator) !Settings { const path = try getSettingsPath(allocator); defer allocator.free(path); @@ -31,7 +31,7 @@ pub fn init(allocator: std.mem.Allocator) !Self { const parsed_settings = std.json.parseFromSlice(@This(), allocator, str, .{}) catch null; if (parsed_settings) |settings| { - var s: Self = settings.value; + var s: Settings = settings.value; s.theme = try allocator.dupeZ(u8, s.theme); return s; } diff --git a/src/editor/Editor.zig b/src/editor/Editor.zig index 844d7ec..5a90f34 100644 --- a/src/editor/Editor.zig +++ b/src/editor/Editor.zig @@ -9,7 +9,7 @@ const nfd = @import("nfd"); const imgui = @import("zig-imgui"); const zmath = @import("zmath"); -pub const Theme = @import("theme.zig"); +pub const Theme = @import("theme_temp.zig"); pub const Editor = @This(); diff --git a/src/editor/theme.zig b/src/editor/theme_temp.zig similarity index 83% rename from src/editor/theme.zig rename to src/editor/theme_temp.zig index 908ff02..143031a 100644 --- a/src/editor/theme.zig +++ b/src/editor/theme_temp.zig @@ -6,7 +6,7 @@ const Color = Pixi.math.Color; const imgui = @import("zig-imgui"); -const Self = @This(); +const Theme = @This(); name: [:0]const u8, @@ -32,7 +32,7 @@ checkerboard_secondary: Color = Color.initBytes(100, 100, 100, 255), modal_dim: Color = Color.initBytes(0, 0, 0, 48), -pub fn init(self: Self, core: *mach.Core, pixi: *Pixi) void { +pub fn init(theme: *Theme, core: *mach.Core, pixi: *Pixi) void { var style = imgui.getStyle(); style.window_border_size = 1.0; style.window_rounding = 8.0; @@ -60,15 +60,15 @@ pub fn init(self: Self, core: *mach.Core, pixi: *Pixi) void { //style.scaleAllSizes(Pixi.content_scale[0]); - const bg = self.background.toImguiVec4(); - const fg = self.foreground.toImguiVec4(); - const text = self.text.toImguiVec4(); - const bg_text = self.text_background.toImguiVec4(); - const highlight_primary = self.highlight_primary.toImguiVec4(); - const hover_primary = self.hover_primary.toImguiVec4(); - const highlight_secondary = self.highlight_secondary.toImguiVec4(); - const hover_secondary = self.hover_secondary.toImguiVec4(); - const modal_dim = self.modal_dim.toImguiVec4(); + const bg = theme.background.toImguiVec4(); + const fg = theme.foreground.toImguiVec4(); + const text = theme.text.toImguiVec4(); + const bg_text = theme.text_background.toImguiVec4(); + const highlight_primary = theme.highlight_primary.toImguiVec4(); + const hover_primary = theme.hover_primary.toImguiVec4(); + const highlight_secondary = theme.highlight_secondary.toImguiVec4(); + const hover_secondary = theme.hover_secondary.toImguiVec4(); + const modal_dim = theme.modal_dim.toImguiVec4(); style.colors[imgui.Col_WindowBg] = bg; style.colors[imgui.Col_Border] = fg; @@ -103,16 +103,16 @@ pub fn init(self: Self, core: *mach.Core, pixi: *Pixi) void { core.windows.set(pixi.window, .decoration_color, .{ .r = fg.x, .g = fg.y, .b = fg.z, .a = fg.w }); } -pub fn push(self: *Self, core: *mach.Core, pixi: *Pixi) void { - const bg = self.background.toImguiVec4(); - const fg = self.foreground.toImguiVec4(); - const text = self.text.toImguiVec4(); - const bg_text = self.text_background.toImguiVec4(); - const highlight_primary = self.highlight_primary.toImguiVec4(); - const hover_primary = self.hover_primary.toImguiVec4(); - const highlight_secondary = self.highlight_secondary.toImguiVec4(); - const hover_secondary = self.hover_secondary.toImguiVec4(); - const modal_dim = self.modal_dim.toImguiVec4(); +pub fn push(theme: *Theme, core: *mach.Core, pixi: *Pixi) void { + const bg = theme.background.toImguiVec4(); + const fg = theme.foreground.toImguiVec4(); + const text = theme.text.toImguiVec4(); + const bg_text = theme.text_background.toImguiVec4(); + const highlight_primary = theme.highlight_primary.toImguiVec4(); + const hover_primary = theme.hover_primary.toImguiVec4(); + const highlight_secondary = theme.highlight_secondary.toImguiVec4(); + const hover_secondary = theme.hover_secondary.toImguiVec4(); + const modal_dim = theme.modal_dim.toImguiVec4(); imgui.pushStyleColorImVec4(imgui.Col_WindowBg, bg); imgui.pushStyleColorImVec4(imgui.Col_Border, fg); @@ -151,7 +151,7 @@ pub fn push(self: *Self, core: *mach.Core, pixi: *Pixi) void { core.windows.set(pixi.window, .decoration_color, .{ .r = fg.x, .g = fg.y, .b = fg.z, .a = fg.w }); } -pub fn loadFromFile(file: [:0]const u8) !Self { +pub fn loadFromFile(file: [:0]const u8) !Theme { const base_name = std.fs.path.basename(file); const ext = std.fs.path.extension(file); @@ -161,7 +161,7 @@ pub fn loadFromFile(file: [:0]const u8) !Self { defer Pixi.state.allocator.free(read); const options = std.json.ParseOptions{ .duplicate_field_behavior = .use_first, .ignore_unknown_fields = true }; - const parsed = try std.json.parseFromSlice(Self, Pixi.state.allocator, read, options); + const parsed = try std.json.parseFromSlice(Theme, Pixi.state.allocator, read, options); defer parsed.deinit(); var out = parsed.value; @@ -169,23 +169,23 @@ pub fn loadFromFile(file: [:0]const u8) !Self { return out; } } - return Self{ + return Theme{ .name = try Pixi.state.allocator.dupeZ(u8, "pixi_dark.json"), }; } -pub fn save(self: Self, path: [:0]const u8) !void { +pub fn save(theme: Theme, path: [:0]const u8) !void { var handle = try std.fs.cwd().createFile(path, .{}); defer handle.close(); const out_stream = handle.writer(); const options = std.json.StringifyOptions{}; - try std.json.stringify(self, options, out_stream); + try std.json.stringify(theme, options, out_stream); } -pub fn pop(self: Self) void { - _ = self; +pub fn pop(theme: Theme) void { + _ = theme; imgui.popStyleColorEx(28); }