Skip to content

Commit

Permalink
theme: Set titlebar color when theme is set
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Dec 12, 2024
1 parent 58ce65f commit a5619f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
21 changes: 5 additions & 16 deletions src/Pixi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ pub fn init(app: *App, core: *Core, app_mod: mach.Mod(App)) !void {
//core.setSizeLimit(.{ .min = .{ .width = @divTrunc(state.settings.initial_window_width, 2), .height = @divTrunc(state.settings.initial_window_height, 2) }, .max = .{ .width = null, .height = null } });
}

fn lateInit(app: *App, core: *Core) !void {
var window = core.windows.getValue(app.window);
defer core.windows.setValue(app.window, window);
fn lateInit(pixi: *App, core: *Core) !void {
const window = core.windows.getValue(pixi.window);
//defer core.windows.setValue(app.window, window);

state.device = window.device;
state.queue = window.queue;
Expand Down Expand Up @@ -259,17 +259,7 @@ fn lateInit(app: *App, core: *Core) !void {
state.fonts.fa_small_solid = io.fonts.?.addFontFromFileTTF(assets.root ++ "fonts/fa-solid-900.ttf", 10 * scale_factor, &fa_config, @ptrCast(ranges.ptr)).?;
state.fonts.fa_small_regular = io.fonts.?.addFontFromFileTTF(assets.root ++ "fonts/fa-regular-400.ttf", 10 * scale_factor, &fa_config, @ptrCast(ranges.ptr)).?;

state.theme.init();

window.color = .{ .transparent = .{
.color = .{
.r = state.theme.foreground.value[0],
.g = state.theme.foreground.value[1],
.b = state.theme.foreground.value[2],
.a = 1.0,
},
.titlebar = true,
} };
state.theme.init(core, pixi);
}

pub fn tick(app: *App, core: *Core) !void {
Expand Down Expand Up @@ -354,7 +344,6 @@ pub fn tick(app: *App, core: *Core) !void {
_ = imgui_mach.processEvent(event);
}
var window = core.windows.getValue(app.window);
defer core.windows.setValue(app.window, window);
state.swap_chain = window.swap_chain;

try imgui_mach.newFrame();
Expand All @@ -364,7 +353,7 @@ pub fn tick(app: *App, core: *Core) !void {

try input.process();

state.theme.set();
state.theme.set(core, app);

//imgui.showDemoWindow(null);

Expand Down
34 changes: 22 additions & 12 deletions src/editor/theme.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const builtin = @import("builtin");
const core = @import("mach").core;
const pixi = @import("../Pixi.zig");
const Color = pixi.math.Color;
const mach = @import("mach");
const Pixi = @import("../Pixi.zig");
const Color = Pixi.math.Color;

const imgui = @import("zig-imgui");

Expand Down Expand Up @@ -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) void {
pub fn init(self: Self, core: *mach.Core, pixi: *Pixi) void {
var style = imgui.getStyle();
style.window_border_size = 1.0;
style.window_rounding = 8.0;
Expand All @@ -54,11 +54,11 @@ pub fn init(self: Self) void {
style.hover_delay_normal = 0.5;
style.hover_delay_short = 0.25;
style.popup_rounding = 8.0;
style.separator_text_align = .{ .x = pixi.state.settings.explorer_title_align, .y = 0.5 };
style.separator_text_align = .{ .x = Pixi.state.settings.explorer_title_align, .y = 0.5 };
style.separator_text_border_size = 1.0;
style.separator_text_padding = .{ .x = 20.0, .y = 10.0 };

style.scaleAllSizes(pixi.content_scale[0]);
//style.scaleAllSizes(Pixi.content_scale[0]);

const bg = self.background.toImguiVec4();
const fg = self.foreground.toImguiVec4();
Expand Down Expand Up @@ -98,9 +98,12 @@ pub fn init(self: Self) void {
style.colors[imgui.Col_ButtonHovered] = hover_secondary;
style.colors[imgui.Col_ButtonActive] = highlight_secondary;
style.colors[imgui.Col_ModalWindowDimBg] = modal_dim;

// Set the window decoration color to match
core.windows.set(pixi.window, .decoration_color, .{ .r = fg.x, .g = fg.y, .b = fg.z, .a = fg.w });
}

pub fn set(self: *Self) void {
pub fn set(self: *Self, core: *mach.Core, pixi: *Pixi) void {
const bg = self.background.toImguiVec4();
const fg = self.foreground.toImguiVec4();
const text = self.text.toImguiVec4();
Expand Down Expand Up @@ -139,28 +142,35 @@ pub fn set(self: *Self) void {
imgui.pushStyleColorImVec4(imgui.Col_ButtonHovered, hover_secondary);
imgui.pushStyleColorImVec4(imgui.Col_ButtonActive, highlight_secondary);
imgui.pushStyleColorImVec4(imgui.Col_ModalWindowDimBg, modal_dim);

// Set the window decoration color to match
if (core.windows.get(pixi.window, .decoration_color)) |color| {
if (color.r == fg.x and color.g == fg.y and color.b == fg.z and color.a == fg.w)
return;
}
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 {
const base_name = std.fs.path.basename(file);
const ext = std.fs.path.extension(file);

if (std.mem.eql(u8, ext, ".json")) {
const read_opt: ?[]const u8 = pixi.fs.read(pixi.state.allocator, file) catch null;
const read_opt: ?[]const u8 = Pixi.fs.read(Pixi.state.allocator, file) catch null;
if (read_opt) |read| {
defer pixi.state.allocator.free(read);
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(Self, Pixi.state.allocator, read, options);
defer parsed.deinit();

var out = parsed.value;
out.name = try pixi.state.allocator.dupeZ(u8, base_name);
out.name = try Pixi.state.allocator.dupeZ(u8, base_name);
return out;
}
}
return Self{
.name = try pixi.state.allocator.dupeZ(u8, "pixi_dark.json"),
.name = try Pixi.state.allocator.dupeZ(u8, "pixi_dark.json"),
};
}

Expand Down

0 comments on commit a5619f8

Please sign in to comment.