RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Align sidebar transfer and torrent tooltips
Melc32d62686ddd
diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zigindex 6ad79a6..768ea32 100644--- a/src/files/app_sidebar_paint.zig+++ b/src/files/app_sidebar_paint.zig@@ -606,8 +606,21 @@ pub fn renderSidebarScrollbar(self: *App, cr: *c.cairo_t) void {pub fn renderFileOpsTip(self: *App, cr: *c.cairo_t) void {if (self.hoverKey() != std.math.maxInt(usize) - 2002) return;+ const title, const running_status = if (self.job_runner) |runner| switch (runner.kind) {+ .copy => .{ tr("Copying files"), tr("Copying") },+ .move => .{ tr("Moving files"), tr("Moving") },+ .extract => .{ tr("Extracting files"), tr("Extracting") },+ .open_archive_member => .{ tr("Extracting archive member"), tr("Extracting") },+ } else .{ tr("File transfer"), tr("In progress") };+ const status = switch (self.job_state) {+ .running => running_status,+ .paused => tr("Paused"),+ .waiting_conflict => tr("Waiting for confirmation"),+ .finished => tr("Complete"),+ .idle => tr("Ready"),+ };+var speed_buf: [96]u8 = undefined;- var bytes_buf: [96]u8 = undefined;var speed_size_buf: [32]u8 = undefined;var bytes_size_buf: [32]u8 = undefined;const speed = i18n.fmt(&speed_buf, tr("{rate}/s"), .{@@ -616,12 +629,14 @@ pub fn renderFileOpsTip(self: *App, cr: *c.cairo_t) void {&speed_size_buf,),}) catch "";- const transferred = i18n.fmt(&bytes_buf, tr("{value} transferred"), .{- .value = @import("app_draw.zig").formatSize(- @intCast(@min(self.job_transferred_bytes, @as(u64, std.math.maxInt(i64)))),- &bytes_size_buf,- ),- }) catch "";- const details = [_][]const u8{ speed, transferred };- transferTip.render(cr, self.w, self.h, self.mouse_x, self.mouse_y, tr("File transfer"), &details);+ const transferred = @import("app_draw.zig").formatSize(+ @intCast(@min(self.job_transferred_bytes, @as(u64, std.math.maxInt(i64)))),+ &bytes_size_buf,+ );+ const details = [_]transferTip.Detail{+ .{ .label = tr("Status"), .value = status },+ .{ .label = tr("Speed"), .value = speed },+ .{ .label = tr("Transferred"), .value = transferred },+ };+ transferTip.render(cr, self.w, self.h, self.mouse_x, self.mouse_y, title, &details);}diff --git a/src/files/app_torrents.zig b/src/files/app_torrents.zigindex 5a04a71..ffbc749 100644--- a/src/files/app_torrents.zig+++ b/src/files/app_torrents.zig@@ -932,16 +932,19 @@ pub fn renderTorrentSidebarTip(self: *App, cr: *c.cairo_t) void {if (self.torrents.items().len == 0) return;const t = self.torrents.items()[0];- var download_buf: [96]u8 = undefined;- var upload_buf: [96]u8 = undefined;+ var speed_buf: [160]u8 = undefined;+ var transferred_buf: [32]u8 = undefined;var download_size_buf: [32]u8 = undefined;var upload_size_buf: [32]u8 = undefined;- const download = i18n.fmt(&download_buf, tr("Download: {rate}/s"), .{- .rate = draw.formatSize(t.download_rate, &download_size_buf),- }) catch "";- const upload = i18n.fmt(&upload_buf, tr("Upload: {rate}/s"), .{- .rate = draw.formatSize(t.upload_rate, &upload_size_buf),+ const speed = i18n.fmt(&speed_buf, tr("↑ {upload}/s · ↓ {download}/s"), .{+ .upload = draw.formatSize(t.upload_rate, &upload_size_buf),+ .download = draw.formatSize(t.download_rate, &download_size_buf),}) catch "";- const details = [_][]const u8{ download, upload };+ const transferred = draw.formatSize(t.done, &transferred_buf);+ const details = [_]transferTip.Detail{+ .{ .label = tr("Status"), .value = t.status() },+ .{ .label = tr("Speed"), .value = speed },+ .{ .label = tr("Transferred"), .value = transferred },+ };transferTip.render(cr, self.w, self.h, self.mouse_x, self.mouse_y, t.name, &details);}diff --git a/src/files/app_transfer_tip.zig b/src/files/app_transfer_tip.zigindex 7e42be2..9e741e2 100644--- a/src/files/app_transfer_tip.zig+++ b/src/files/app_transfer_tip.zig@@ -1,11 +1,17 @@//! Shared tooltip frame and layout for transfer details.const std = @import("std");const ui = @import("ui").cairo;+const text = @import("ui").text;const theme = @import("ui").theme;const frame = @import("ui").widgets.dialog;const c = @import("c.zig").api;const header = @import("header.zig");+pub const Detail = struct {+ label: []const u8,+ value: []const u8,+};+/// Exact window-coordinate bounds shared by tooltip painting and damage.pub fn bounds(window_w: i32,@@ -45,7 +51,7 @@ pub fn render(mouse_x: f64,mouse_y: f64,title: []const u8,- details: []const []const u8,+ details: []const Detail,) void {const area = bounds(window_w, window_h, mouse_x, mouse_y, details.len) orelse return;var layer = ui.Layer.begin(cr, .{@@ -65,8 +71,21 @@ pub fn render(.color = palette.fg,});for (details, 0..) |detail, i| {- layer.renderer.drawText(12, 31 + @as(f32, @floatFromInt(i)) * 22, @as(f32, @floatCast(area.w)) - 24, 22, .{- .content = detail,+ const y = 31 + @as(f32, @floatFromInt(i)) * 22;+ const value_width = text.measureWidthF(+ detail.value,+ .manrope,+ ui.statusSize(),+ layer.renderer.scale,+ ) catch 0;+ const value_x = @max(12, @as(f32, @floatCast(area.w)) - 12 - value_width);+ layer.renderer.drawText(12, y, @max(0, value_x - 20), 22, .{+ .content = detail.label,+ .font_size = ui.statusSize(),+ .color = palette.fg,+ });+ layer.renderer.drawText(value_x, y, value_width + 1, 22, .{+ .content = detail.value,.font_size = ui.statusSize(),.color = palette.fg,});