feat: support rendering theme colors with alpha components
This commit is contained in:
parent
3b28286c91
commit
0a43fa853f
9 changed files with 127 additions and 48 deletions
|
@ -960,7 +960,7 @@ pub const Editor = struct {
|
|||
var cell = self.plane.cell_init();
|
||||
_ = self.plane.at_cursor_cell(&cell) catch return;
|
||||
cell.set_style(.{ .fs = .undercurl });
|
||||
if (style.fg) |ul_col| cell.set_under_color(ul_col);
|
||||
if (style.fg) |ul_col| cell.set_under_color(ul_col.color);
|
||||
_ = self.plane.putc(&cell) catch {};
|
||||
}
|
||||
|
||||
|
|
|
@ -161,10 +161,10 @@ pub fn render_linear(self: *Self, theme: *const Widget.Theme) void {
|
|||
while (rows > 0) : (rows -= 1) {
|
||||
if (linenum > self.lines) return;
|
||||
if (linenum == self.line + 1) {
|
||||
self.plane.set_base_style(" ", theme.editor_gutter_active);
|
||||
self.plane.set_style(theme.editor_gutter_active);
|
||||
self.plane.on_styles(style.bold);
|
||||
} else {
|
||||
self.plane.set_base_style(" ", theme.editor_gutter);
|
||||
self.plane.set_style(theme.editor_gutter);
|
||||
self.plane.off_styles(style.bold);
|
||||
}
|
||||
_ = self.plane.print_aligned_right(@intCast(pos), "{s}", .{std.fmt.bufPrintZ(&buf, "{d} ", .{linenum}) catch return}) catch {};
|
||||
|
@ -187,7 +187,7 @@ pub fn render_relative(self: *Self, theme: *const Widget.Theme) void {
|
|||
var buf: [31:0]u8 = undefined;
|
||||
while (rows > 0) : (rows -= 1) {
|
||||
if (pos > self.lines - @as(u32, @intCast(row))) return;
|
||||
self.plane.set_base_style(" ", if (linenum == 0) theme.editor_gutter_active else theme.editor_gutter);
|
||||
self.plane.set_style(if (linenum == 0) theme.editor_gutter_active else theme.editor_gutter);
|
||||
const val = @abs(if (linenum == 0) line else linenum);
|
||||
const fmt = std.fmt.bufPrintZ(&buf, "{d} ", .{val}) catch return;
|
||||
_ = self.plane.print_aligned_right(@intCast(pos), "{s}", .{if (fmt.len > 6) "==> " else fmt}) catch {};
|
||||
|
|
|
@ -157,9 +157,15 @@ fn show_color(self: *Self, tag: []const u8, c_: ?Widget.Theme.Color) void {
|
|||
if (c_) |c| {
|
||||
_ = self.plane.print(" {s}:", .{tag}) catch return;
|
||||
self.plane.set_bg_rgb(c) catch {};
|
||||
self.plane.set_fg_rgb(color.max_contrast(c, theme.panel.fg orelse 0xFFFFFF, theme.panel.bg orelse 0x000000)) catch {};
|
||||
_ = self.plane.print("#{x}", .{c}) catch return;
|
||||
self.plane.set_fg_rgb(.{ .color = color.max_contrast(
|
||||
c.color,
|
||||
(theme.panel.fg orelse Widget.Theme.Color{ .color = 0xFFFFFF }).color,
|
||||
(theme.panel.bg orelse Widget.Theme.Color{ .color = 0x000000 }).color,
|
||||
) }) catch {};
|
||||
_ = self.plane.print("#{x}", .{c.color}) catch return;
|
||||
self.reset_style();
|
||||
if (c.alpha != 0xff)
|
||||
_ = self.plane.print(" ɑ{x}", .{c.alpha}) catch return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,9 @@ pub fn render(_: *void, self: *Button.State(void), theme: *const Widget.Theme) b
|
|||
}
|
||||
|
||||
fn render_separator(self: *Button.State(void), theme: *const Widget.Theme) void {
|
||||
if (theme.statusbar_hover.bg) |bg| self.plane.set_fg_rgb(bg) catch {};
|
||||
if (theme.statusbar.bg) |bg| self.plane.set_bg_rgb(bg) catch {};
|
||||
const statusbar_bg = theme.statusbar.bg orelse theme.editor.bg.?;
|
||||
if (theme.statusbar_hover.bg) |bg| self.plane.set_fg_rgb_alpha(statusbar_bg, bg) catch {};
|
||||
if (theme.statusbar.bg) |bg| self.plane.set_bg_rgb_alpha(statusbar_bg, bg) catch {};
|
||||
_ = self.plane.putstr("") catch {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue