RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Unify file and torrent progress bar rendering
Melf47ed23aa5af
diff --git a/src/files/app_draw.zig b/src/files/app_draw.zigindex 046a0e7..7923186 100644--- a/src/files/app_draw.zig+++ b/src/files/app_draw.zig@@ -52,6 +52,30 @@ pub fn roundedRect(cr: *c.cairo_t, x: f64, y: f64, w: f64, h: f64, r: f64) voidc.cairo_close_path(cr);}+pub fn drawProgressBar(+ cr: *c.cairo_t,+ x: f64,+ y: f64,+ width: f64,+ fraction: ?f64,+ track_color: [4]f32,+ fill_color: [4]f32,+) void {+ if (width <= 0) return;+ roundedRect(cr, x, y, width, 4, 2);+ setSource(cr, track_color);+ c.cairo_fill(cr);++ const fill_width = if (fraction) |value|+ width * @min(1.0, @max(0.0, value))+ else+ @min(width, 24);+ if (fill_width <= 0) return;+ roundedRect(cr, x, y, fill_width, 4, 2);+ setSource(cr, fill_color);+ c.cairo_fill(cr);+}+pub fn drawSpinner(cr: *c.cairo_t, cx: f64, cy: f64, r: f64) void {const angle = @as(f64, @floatFromInt(@mod(nowMs(), 1000))) / 1000.0 * 2.0 * std.math.pi;c.cairo_save(cr);diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zigindex 0c74624..75ea065 100644--- a/src/files/app_sidebar_paint.zig+++ b/src/files/app_sidebar_paint.zig@@ -552,18 +552,15 @@ pub fn renderFileOpsSidebar(self: *App, cr: *c.cairo_t) void {const track_x = area.x + 12;const track_y = area.y + area.h - 9;const track_w = area.w - 24;- roundedRect(cr, track_x, track_y, track_w, 4, 2);- setSource(cr, withAlpha(ui_theme.global.sidebarForeground(), 0.14));- c.cairo_fill(cr);- const fill_w = if (fraction) |value|- track_w * value- else- @min(track_w, 24);- if (fill_w > 0) {- roundedRect(cr, track_x, track_y, fill_w, 4, 2);- setSource(cr, palette.accent);- c.cairo_fill(cr);- }+ @import("app_draw.zig").drawProgressBar(+ cr,+ track_x,+ track_y,+ track_w,+ fraction,+ withAlpha(ui_theme.global.sidebarForeground(), 0.14),+ palette.accent,+ );const can_pause = (progress.kind == .copy or progress.kind == .move) and(progress.state == .running or progress.state == .paused);diff --git a/src/files/app_torrents.zig b/src/files/app_torrents.zigindex 2e3473d..6859c28 100644--- a/src/files/app_torrents.zig+++ b/src/files/app_torrents.zig@@ -141,7 +141,6 @@ pub fn renderTorrentSidebar(self: *App, cr: *c.cairo_t) void {if (self.chooser != null) return;const area = sidebarBox(self);var layer = ui.Layer.begin(cr, .{ .x = area.x, .y = area.y, .w = area.w, .h = area.h }) orelse return;- defer layer.finish();var palette = theme.shellPalette();palette.fg = theme.global.sidebarForeground();palette.button_font_size = ui.textSize();@@ -155,10 +154,23 @@ pub fn renderTorrentSidebar(self: *App, cr: *c.cairo_t) void {var buf: [96]u8 = undefined;const label = if (self.torrents.retry_at != null) tr("Connecting…") else if (self.torrents.message().len > 0) tr("Transfers needs attention") else i18n.fmt(&buf, tr("{value} active · {rate} KiB/s"), .{ .value = active, .rate = @divTrunc(rate, 1024) }) catch tr("Transfers");layer.renderer.drawText(12, 20, area.w - 24, 24, .{ .content = label, .font_size = ui.statusSize(), .color = palette.fg });+ var fraction: ?f64 = null;if (self.torrents.items().len > 0) {const t = self.torrents.items()[0];layer.renderer.drawText(12, 46, area.w - 24, 24, .{ .content = t.name, .font_size = ui.statusSize(), .color = palette.fg });- layer.renderer.fillRect(12, 72, (area.w - 24) * @as(f32, @floatFromInt(std.math.clamp(t.progress, 0, 1000000))) / 1000000, 2, .{ .color = palette.accent });+ fraction = @as(f64, @floatFromInt(std.math.clamp(t.progress, 0, 1000000))) / 1000000.0;+ }+ layer.finish();+ if (fraction) |value| {+ draw.drawProgressBar(+ cr,+ area.x + 12,+ area.y + 72,+ area.w - 24,+ value,+ draw.withAlpha(theme.global.sidebarForeground(), 0.14),+ palette.accent,+ );}}fn box(self: *App) Rect {