Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Add proximity glow to app surfaces

Petar Margetić4d3fa00e4534
diff --git a/src/desktop/app.zig b/src/desktop/app.zig
index df3fabc..dab2397 100644
--- a/src/desktop/app.zig
+++ b/src/desktop/app.zig
@@ -61,6 +61,7 @@ pub const App = struct {
geometry: grid.Grid = .{ .w = 1280, .h = 720 },
x: f64 = 0,
y: f64 = 0,
+ pointer_present: bool = false,
down_x: f64 = 0,
down_y: f64 = 0,
down_at: i64 = 0,
diff --git a/src/desktop/app_paint.zig b/src/desktop/app_paint.zig
index 5657ff5..752d54e 100644
--- a/src/desktop/app_paint.zig
+++ b/src/desktop/app_paint.zig
@@ -18,6 +18,7 @@ const nowMs = @import("app_draw.zig").nowMs;
const rounded = @import("app_draw.zig").rounded;
const IconRaster = @import("app_draw.zig").IconRaster;
const label = @import("app_draw.zig").label;
+const button = @import("ui").widgets.button;
/// The selection band rasterized with its own bounds as the only clip. A
/// repair can split the band's corners across several rectangular clips,
@@ -118,6 +119,27 @@ pub fn render(self: *App, cr: *c.cairo_t, damage: *const Damage, now: i64, conte
c.cairo_paint(cr);
c.cairo_set_operator(cr, c.CAIRO_OPERATOR_OVER);
if (self.wallpaper) |im| @import("wallpaper.zig").render(im, cr, self.geometry.w, self.geometry.h);
+ // Keep pointer-dependent lighting out of IconRaster: the cached icon,
+ // label and hover/selection decoration remain independent of pointer motion.
+ if (self.pointer_present and button.proximityGlowVisible(appearance_theme.global)) {
+ for (self.icons.items, 0..) |_, i| {
+ const r = self.iconRect(i);
+ if (r.contains(self.x, self.y) or !damage.intersects(r)) continue;
+ shell_cairo.drawProximityGlow(
+ @ptrCast(cr),
+ .{
+ .x = @floatFromInt(r.x),
+ .y = @floatFromInt(r.y),
+ .w = @floatFromInt(r.w),
+ .h = @floatFromInt(r.h),
+ },
+ 8,
+ .{ .x = self.x, .y = self.y },
+ null,
+ );
+ }
+ }
+
for (self.icons.items, 0..) |*ic, i| {
const r = self.iconRect(i);
if (!damage.intersects(r)) continue;
diff --git a/src/desktop/app_pointer.zig b/src/desktop/app_pointer.zig
index d6c7123..329cb0e 100644
--- a/src/desktop/app_pointer.zig
+++ b/src/desktop/app_pointer.zig
@@ -11,6 +11,41 @@ const host_mod = @import("host.zig");
const context_menu = @import("ui").context_menu;
const Menu = @import("menu.zig").Menu;
const nowMs = @import("app_draw.zig").nowMs;
+const ui_theme = @import("ui").theme;
+const widget_button = @import("ui").widgets.button;
+
+fn proximityDistance(self: *App, index: usize, x: f64, y: f64) f32 {
+ const r = self.iconRect(index);
+ const sample = widget_button.sampleProximity(
+ .{
+ .x = @floatFromInt(r.x),
+ .y = @floatFromInt(r.y),
+ .w = @floatFromInt(r.w),
+ .h = @floatFromInt(r.h),
+ },
+ @floatCast(x),
+ @floatCast(y),
+ .{
+ .x = 0,
+ .y = 0,
+ .w = @floatFromInt(self.geometry.w),
+ .h = @floatFromInt(self.geometry.h),
+ },
+ );
+ return sample.distance;
+}
+
+fn damageProximityAt(self: *App, x: f64, y: f64) void {
+ const t = ui_theme.global;
+ if (!widget_button.proximityGlowVisible(t)) return;
+
+ for (self.icons.items, 0..) |_, i| {
+ if (self.iconRect(i).contains(x, y)) continue;
+ if (proximityDistance(self, i, x, y) < t.border_glow_reach) {
+ self.damageIcon(i);
+ }
+ }
+}
pub fn motion(self: *App, x: f64, y: f64) void {
self.pointerMotion(x, y);
@@ -50,9 +85,15 @@ pub fn pointerMotion(self: *App, x: f64, y: f64) void {
return;
}
const moved = self.x != x or self.y != y;
- if (moved) self.damageDrag();
+ const newly_present = !self.pointer_present;
+ if (moved) {
+ self.damageDrag();
+ if (self.pointer_present) damageProximityAt(self, self.x, self.y);
+ }
self.x = x;
self.y = y;
+ self.pointer_present = true;
+ if (moved or newly_present) damageProximityAt(self, x, y);
const hover = if (self.edit == .rename) null else self.hit(x, y);
if (self.hover != hover) {
if (self.hover) |i| self.damageIcon(i);
@@ -92,6 +133,8 @@ pub fn pointerMotion(self: *App, x: f64, y: f64) void {
}
pub fn leave(self: *App) void {
+ if (self.pointer_present) damageProximityAt(self, self.x, self.y);
+ self.pointer_present = false;
self.deletion.placement.grab = null;
if (self.trash_card) |*card| card.placement.grab = null;
if (self.applications) |*picker| picker.placement.grab = null;
diff --git a/src/desktop/app_tests.zig b/src/desktop/app_tests.zig
index fc17668..436b40d 100644
--- a/src/desktop/app_tests.zig
+++ b/src/desktop/app_tests.zig
@@ -82,6 +82,37 @@ test "desktop pointer motion repaints only when visible state changes" {
try std.testing.expect(app.dirty);
}
+test "desktop icon-card proximity damages only nearby cards and clears on leave" {
+ var icons = [_]Icon{
+ .{ .item = .{ .path = "", .name = "Alpha", .icon = null }, .cell = .{}, .born = 0 },
+ };
+ var app = App{
+ .worker = undefined,
+ .geometry = .{ .w = 400, .h = 240 },
+ .icons = .fromOwnedSlice(&icons),
+ .dirty = false,
+ };
+
+ // Outside the card's hit box, but within its proximity reach.
+ app.motion(250, 50);
+ try std.testing.expect(app.dirty);
+ try std.testing.expectEqual(@as(?usize, null), app.hover);
+ try std.testing.expect(app.pointer_present);
+
+ app.presented();
+ app.motion(249, 50);
+ try std.testing.expect(app.dirty);
+
+ app.presented();
+ app.leave();
+ try std.testing.expect(app.dirty);
+ try std.testing.expect(!app.pointer_present);
+
+ app.presented();
+ app.leave();
+ try std.testing.expect(!app.dirty);
+}
+
test "desktop motion keeps menu highlights and moving selections live" {
var app = App{ .worker = undefined, .menu = true, .dirty = false };
app.menu_layout.layout(100, 100, 3, false);
diff --git a/src/editor/app_controls.zig b/src/editor/app_controls.zig
index 6865483..f815285 100644
--- a/src/editor/app_controls.zig
+++ b/src/editor/app_controls.zig
@@ -71,6 +71,18 @@ fn nearestButton(self: *App, x: f64, y: f64) f32 {
nearest = @min(nearest, sample.distance);
}
if (self.find_open) {
+ // Search fields use the same proximity reach as their adjacent buttons.
+ for ([_]SearchControl{ .query, .replacement }) |control| {
+ if (control == .replacement and !self.replace_open) continue;
+ const box = self.searchBox(control);
+ const sample = button.sampleProximity(
+ .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },
+ @floatCast(x), @floatCast(y),
+ .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) },
+ );
+ nearest = @min(nearest, sample.distance);
+ }
+
const controls = [_]SearchControl{ .next, .toggle, .close, .replace, .replace_all };
for (controls) |control| {
if (!self.replace_open and (control == .replace or control == .replace_all)) continue;
diff --git a/src/editor/app_search.zig b/src/editor/app_search.zig
index 45c572e..748673b 100644
--- a/src/editor/app_search.zig
+++ b/src/editor/app_search.zig
@@ -183,6 +183,19 @@ pub fn searchCaret(self: *App, cr: *c.cairo_t) @import("caret.zig").Rect {
fn paintField(self: *App, cr: *c.cairo_t, control: Control, editor: *Editor, placeholder: []const u8) void {
const box = self.searchBox(control);
const focused = self.search_focus == control;
+
+ // Paint the shared proximity glow beneath the field frame, preserving
+ // the focused border and all existing text/caret rendering.
+ if (self.close_tab == null and !self.menu_open) {
+ ui.drawProximityGlow(
+ @ptrCast(cr),
+ .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },
+ field.metrics(.md, theme.global).radius,
+ .{ .x = self.px, .y = self.py },
+ null,
+ );
+ }
+
if (ui.Layer.begin(cr, .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) })) |l| {
var layer = l;
_ = field.paintFrame(&layer.renderer, layer.local(), .{}, .{ .focused = focused });
diff --git a/src/images/app_dialogs.zig b/src/images/app_dialogs.zig
index 2221119..d58bef8 100644
--- a/src/images/app_dialogs.zig
+++ b/src/images/app_dialogs.zig
@@ -238,13 +238,33 @@ pub fn drawDialog(self: *App, cr: *c.cairo_t) void {
for (0..n) |i| {
const b = self.dialogButton(i);
const label = if (i == 0) tr("Cancel") else if (self.dialog == .save or i == 2) tr("Save as…") else if (self.dialog == .trash) tr("Move to Trash") else tr("Discard");
+ const proximity = ui_button.sampleProximity(
+ .{ .x = @floatCast(b.x), .y = @floatCast(b.y), .w = @floatCast(b.w), .h = @floatCast(b.h) },
+ @floatCast(self.px), @floatCast(self.py),
+ .{ .x = @floatCast(r.x), .y = @floatCast(r.y), .w = @floatCast(r.w), .h = @floatCast(r.h) },
+ );
ui_button.paint(lr, .{ .x = @floatCast(b.x - r.x), .y = @floatCast(b.y - r.y), .w = @floatCast(b.w), .h = @floatCast(b.h) }, .{
.variant = if (i == 0) .secondary else .primary,
.label = label,
- }, .{ .pointer = if (b.contains(self.px, self.py)) .hover else .idle });
+ }, .{
+ .pointer = if (b.contains(self.px, self.py)) .hover else .idle,
+ .proximity_distance = proximity.distance,
+ .proximity_x = proximity.x,
+ .proximity_y = proximity.y,
+ });
}
layer.finish();
}
+ if (self.dialog == .save) {
+ const f = self.filenameRect();
+ shell_ui.drawProximityGlow(
+ cr,
+ shellRect(f),
+ 7,
+ .{ .x = self.px, .y = self.py },
+ shellRect(r),
+ );
+ }
setSource(cr, t.fg);
const title = switch (self.dialog) {
.save => tr("Save a PNG copy"),
diff --git a/src/images/app_input.zig b/src/images/app_input.zig
index ab5b751..8038cd7 100644
--- a/src/images/app_input.zig
+++ b/src/images/app_input.zig
@@ -81,6 +81,83 @@ fn toolbarProximityChanged(
return false;
}
+fn contentRectProximityChanged(
+ rect: Rect,
+ old_x: f64,
+ old_y: f64,
+ new_x: f64,
+ new_y: f64,
+) bool {
+ const box = button_widget.Rect{
+ .x = @floatCast(rect.x),
+ .y = @floatCast(rect.y),
+ .w = @floatCast(rect.w),
+ .h = @floatCast(rect.h),
+ };
+ const before = button_widget.sampleProximity(
+ box,
+ @floatCast(old_x),
+ @floatCast(old_y),
+ box,
+ );
+ const after = button_widget.sampleProximity(
+ box,
+ @floatCast(new_x),
+ @floatCast(new_y),
+ box,
+ );
+ return @min(before.distance, after.distance) <= ui_theme.global.border_glow_reach;
+}
+
+fn contentProximityChanged(
+ self: *const App,
+ old_x: f64,
+ old_y: f64,
+ new_x: f64,
+ new_y: f64,
+) bool {
+ if (old_x == new_x and old_y == new_y) return false;
+ if (!button_widget.proximityGlowVisible(ui_theme.global)) return false;
+
+ if (self.dialog == .save) {
+ if (contentRectProximityChanged(
+ self.filenameRect(), old_x, old_y, new_x, new_y,
+ )) return true;
+ }
+ if (self.dialog != .none and self.dialog != .trash) {
+ const button_count: usize = if (self.dialog == .discard) 3 else 2;
+ for (0..button_count) |index| {
+ if (contentRectProximityChanged(
+ self.dialogButton(index), old_x, old_y, new_x, new_y,
+ )) return true;
+ }
+ return false;
+ }
+ if (self.dialog != .none or self.operation != null) return false;
+
+ // Only thumbnails in the currently visible filmstrip participate.
+ for (0..self.thumbCount()) |slot| {
+ if (contentRectProximityChanged(
+ self.thumbRect(slot), old_x, old_y, new_x, new_y,
+ )) return true;
+ }
+
+ if (self.stripBar()) |bar| {
+ const track = bar.track;
+ if (contentRectProximityChanged(
+ .{
+ .x = track.x,
+ .y = track.y,
+ .w = track.w,
+ .h = track.h,
+ },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ }
+
+ return false;
+}
+
pub fn hit(self: *const App, x: f64, y: f64) ?Action {
inline for (std.meta.tags(Action)) |action| if (self.buttonRect(action).contains(x, y)) return action;
return null;
@@ -231,6 +308,7 @@ pub fn handleMotion(self: *App, x: f64, y: f64) void {
self.dirty = true;
}
if (toolbarProximityChanged(self, old_x, old_y, x, y)) self.toolbar_dirty = true;
+ if (contentProximityChanged(self, old_x, old_y, x, y)) self.dirty = true;
if (self.operation != null or (self.dialog != .none and !self.filename_drag)) {
self.px = x;
self.py = y;
diff --git a/src/images/app_render.zig b/src/images/app_render.zig
index 4f98b62..6d8dae6 100644
--- a/src/images/app_render.zig
+++ b/src/images/app_render.zig
@@ -106,6 +106,15 @@ pub fn render(self: *App, cr: *c.cairo_t) void {
}
}
c.cairo_restore(cr);
+ // Keep the glow outside the card's rounded image clip, but inside the
+ // visible filmstrip viewport.
+ shell_ui.drawProximityGlow(
+ cr,
+ shellRect(r),
+ 7,
+ .{ .x = self.px, .y = self.py },
+ .{ .x = 16, .y = @floatCast(@as(f64, @floatFromInt(self.h - 32)) - self.thumbHeight()), .w = @floatFromInt(self.w - 32), .h = @floatCast(self.thumbHeight() + 8.0) },
+ );
rounded(cr, r, 7);
c.cairo_set_line_width(cr, 1);
setSource(cr, t.app_item_border);
@@ -122,7 +131,7 @@ pub fn render(self: *App, cr: *c.cairo_t) void {
setSource(cr, color);
c.cairo_stroke(cr);
}
- if (self.stripBar()) |bar| shell_ui.drawScrollbar(cr, scrollbar.look(bar, self.strip_appearance, ui_theme.global.scrollbar_width, ui_theme.shellPalette()));
+ if (self.stripBar()) |bar| shell_ui.drawScrollbarAt(cr, scrollbar.look(bar, self.strip_appearance, ui_theme.global.scrollbar_width, ui_theme.shellPalette()), .{ .x = self.px, .y = self.py });
var status: [160]u8 = undefined;
const text = if (self.image) |im| std.fmt.bufPrint(&status, "{d} × {d} · {d:.0}% · {d} / {d}", .{ im.w, im.h, self.view.scale(box, @floatFromInt(im.w), @floatFromInt(im.h)) * self.density * 100, self.position() + 1, self.count() }) catch "" else tr("Space / Esc to close · Arrow keys to browse");
setSource(cr, t.window_fg);
diff --git a/src/pdf/app_paint.zig b/src/pdf/app_paint.zig
index 7313d8d..13bb145 100644
--- a/src/pdf/app_paint.zig
+++ b/src/pdf/app_paint.zig
@@ -3,7 +3,8 @@
const std = @import("std");
const i18n = @import("i18n");
const tr = i18n.tr;
-const App = @import("app.zig").App;
+const app_mod = @import("app.zig");
+const App = app_mod.App;
const Action = @import("app.zig").Action;
const c = @import("c.zig");
const document = @import("document.zig");
@@ -21,6 +22,24 @@ const toolbar_buttons = @import("app.zig").toolbar_buttons;
const toolbar_button_y = @import("app.zig").toolbar_button_y;
const toolbar_button_h = @import("app.zig").toolbar_button_h;
+
+fn drawContentGlow(
+ cr: *c.api.cairo_t,
+ rect: app_mod.Rect,
+ px: f64,
+ py: f64,
+ clip: ?app_mod.Rect,
+) void {
+ const shell_clip: ?shell_ui.Rect = if (clip) |r| app_mod.shellRect(r) else null;
+ shell_ui.drawProximityGlow(
+ cr,
+ app_mod.shellRect(rect),
+ 7,
+ .{ .x = px, .y = py },
+ shell_clip,
+ );
+}
+
pub fn render(self: *App, cr: *c.api.cairo_t) void {
// Render reading canvas
self.renderCanvas(cr);
@@ -183,7 +202,7 @@ pub fn renderCanvas(self: *App, cr: *c.api.cairo_t) void {
}
}
- if (self.hbar()) |bar| shell_ui.drawScrollbar(cr, scrollbar.look(bar, self.hbar_appearance, ui_theme.global.scrollbar_width, ui_theme.shellPalette()));
+ if (self.hbar()) |bar| shell_ui.drawScrollbarAt(cr, scrollbar.look(bar, self.hbar_appearance, ui_theme.global.scrollbar_width, ui_theme.shellPalette()), .{ .x = self.px, .y = self.py });
}
/// Draws a raster at the current zoom one pixel per device pixel, with
@@ -243,6 +262,9 @@ pub fn renderSidebar(self: *App, cr: *c.api.cairo_t) void {
c.api.cairo_rectangle(cr, sb.x + tab_w + 2.0, sb.y + 4.0, tab_w - 6.0, tab_h - 8.0);
c.api.cairo_fill(cr);
+ drawContentGlow(cr, .{ .x = sb.x + 4.0, .y = sb.y + 4.0, .w = tab_w - 6.0, .h = tab_h - 8.0 }, self.px, self.py, sb);
+ drawContentGlow(cr, .{ .x = sb.x + tab_w + 2.0, .y = sb.y + 4.0, .w = tab_w - 6.0, .h = tab_h - 8.0 }, self.px, self.py, sb);
+
// The selected tab is told apart by its fill, not by a dimmer label.
shell_ui.setSource(cr, ui_theme.global.sidebarForeground());
shell_ui.drawText(cr, tr("Pages"), sb.x + (tab_w - shell_ui.measureText(cr, tr("Pages"), shell_ui.textSize(), true)) / 2.0, sb.y + 20.0, shell_ui.textSize(), true);
@@ -319,6 +341,12 @@ pub fn renderThumbnailCards(self: *App, cr: *c.api.cairo_t) void {
}
}
+ drawContentGlow(
+ cr,
+ .{ .x = card_x, .y = card_y, .w = card_w, .h = card.card_h },
+ self.px, self.py, sb,
+ );
+
// Highlight border if active or hover
const is_current = i == self.current_page;
const is_hover = self.hover_thumb == i;
@@ -364,6 +392,12 @@ pub fn renderOutlineList(self: *App, cr: *c.api.cairo_t) void {
c.api.cairo_fill(cr);
}
+ drawContentGlow(
+ cr,
+ .{ .x = sb.x + 4.0, .y = row_y, .w = sb.w - 8.0, .h = row_h },
+ self.px, self.py, sb,
+ );
+
const indent = @as(f64, @floatFromInt(it.level)) * 12.0;
shell_ui.setSource(cr, ui_theme.global.sidebarForeground());
c.api.cairo_save(cr);
@@ -418,6 +452,11 @@ pub fn renderToolbar(self: *App, cr: *c.api.cairo_t) void {
shell_ui.setSource(cr, ui_theme.global.field_bg);
c.api.cairo_rectangle(cr, 126.0, 8.0, 48.0, 28.0);
c.api.cairo_fill(cr);
+ drawContentGlow(
+ cr,
+ .{ .x = 126, .y = 8, .w = 48, .h = 28 },
+ self.px, self.py, null,
+ );
shell_ui.setSource(cr, if (self.focus == .page_number) ui_theme.shellPalette().fieldFocusColor() else ui_theme.global.field_border);
c.api.cairo_set_line_width(cr, 1.0);
@@ -452,6 +491,14 @@ pub fn renderSearchBar(self: *App, cr: *c.api.cairo_t) void {
c.api.cairo_rectangle(cr, sr.x, sr.y, sr.w, sr.h);
c.api.cairo_fill(cr);
+ drawContentGlow(cr, .{ .x = sr.x + 10.0, .y = sr.y, .w = sr.w - 110.0, .h = sr.h }, self.px, self.py, sr);
+ const close_x = sr.x + sr.w - 28.0;
+ const next_x = close_x - 28.0;
+ const prev_x = next_x - 28.0;
+ for ([_]f64{ prev_x, next_x, close_x }) |x| {
+ drawContentGlow(cr, .{ .x = x, .y = sr.y, .w = 28, .h = sr.h }, self.px, self.py, sr);
+ }
+
shell_ui.setSource(cr, ui_theme.global.field_border);
c.api.cairo_set_line_width(cr, 1.0);
c.api.cairo_rectangle(cr, sr.x, sr.y, sr.w, sr.h);
@@ -534,6 +581,14 @@ pub fn renderDialog(self: *App, cr: *c.api.cairo_t) void {
_ = ui_field.paintSecret(&field.renderer, field.local(), .{}, .{ .focused = true, .external_caret = true }, &self.password_input, tr("Password"));
field.finish();
}
+ // Paint over the completed field layer so its opaque frame cannot
+ // cover the shared glow. The glow is edge-weighted and leaves text legible.
+ drawContentGlow(
+ cr,
+ .{ .x = dx + 24, .y = dy + 80, .w = dw - 48, .h = 44 },
+ self.px, self.py,
+ .{ .x = dx, .y = dy, .w = dw, .h = dh },
+ );
}
self.renderButtonText(cr, dx + dw - 180, dy + dh - 46, 80, 32, tr("Cancel"), null);
@@ -542,7 +597,14 @@ pub fn renderDialog(self: *App, cr: *c.api.cairo_t) void {
}
pub fn renderButtonText(self: *App, cr: *c.api.cairo_t, x: f64, y: f64, w: f64, h: f64, label: []const u8, action: ?Action) void {
- const proximity: @import("ui").widgets.button.ProximitySample = if (action) |act| self.buttonProximity(act, self.px, self.py) else .{ .distance = std.math.inf(f32), .x = 0, .y = 0 };
+ const proximity: ui_button.ProximitySample = if (action) |act|
+ self.buttonProximity(act, self.px, self.py)
+ else
+ ui_button.sampleProximity(
+ .{ .x = @floatCast(x), .y = @floatCast(y), .w = @floatCast(w), .h = @floatCast(h) },
+ @floatCast(self.px), @floatCast(self.py),
+ .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) },
+ );
const is_hover = self.px >= x and self.px <= x + w and self.py >= y and self.py <= y + h;
var layer = shell_ui.Layer.begin(cr, .{ .x = @floatCast(x), .y = @floatCast(y), .w = @floatCast(w), .h = @floatCast(h) }) orelse return;
defer layer.finish();
diff --git a/src/pdf/app_pointer.zig b/src/pdf/app_pointer.zig
index 3677dd9..7b4508a 100644
--- a/src/pdf/app_pointer.zig
+++ b/src/pdf/app_pointer.zig
@@ -4,6 +4,7 @@ const std = @import("std");
const i18n = @import("i18n");
const tr = i18n.tr;
const App = @import("app.zig").App;
+const Rect = @import("app.zig").Rect;
const layout = @import("layout.zig");
const selection = @import("selection.zig");
const scrollbar = @import("ui").widgets.scrollbar;
@@ -73,6 +74,136 @@ fn toolbarProximityChanged(
return false;
}
+fn contentRectProximityChanged(
+ rect: Rect,
+ old_x: f64,
+ old_y: f64,
+ new_x: f64,
+ new_y: f64,
+) bool {
+ const box = button_widget.Rect{
+ .x = @floatCast(rect.x),
+ .y = @floatCast(rect.y),
+ .w = @floatCast(rect.w),
+ .h = @floatCast(rect.h),
+ };
+ const before = button_widget.sampleProximity(
+ box, @floatCast(old_x), @floatCast(old_y), box,
+ );
+ const after = button_widget.sampleProximity(
+ box, @floatCast(new_x), @floatCast(new_y), box,
+ );
+ return @min(before.distance, after.distance) <= ui_theme.global.border_glow_reach;
+}
+
+fn contentProximityChanged(
+ self: *const App,
+ old_x: f64,
+ old_y: f64,
+ new_x: f64,
+ new_y: f64,
+) bool {
+ if (old_x == new_x and old_y == new_y) return false;
+ if (!button_widget.proximityGlowVisible(ui_theme.global)) return false;
+
+ if (self.dialog != .none) {
+ const dw: f64 = 440;
+ const dh: f64 = 190;
+ const dx = (@as(f64, @floatFromInt(self.w)) - dw) / 2.0;
+ const dy = (@as(f64, @floatFromInt(self.h)) - dh) / 2.0;
+ if (self.dialog == .password and contentRectProximityChanged(
+ .{ .x = dx + 24, .y = dy + 80, .w = dw - 48, .h = 44 },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ if (contentRectProximityChanged(
+ .{ .x = dx + dw - 180, .y = dy + dh - 46, .w = 80, .h = 32 },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ return contentRectProximityChanged(
+ .{ .x = dx + dw - 90, .y = dy + dh - 46, .w = 70, .h = 32 },
+ old_x, old_y, new_x, new_y,
+ );
+ }
+
+ if (self.sidebar_open) {
+ const sb = self.sidebarRect();
+ const tab_w = sb.w / 2.0;
+ if (contentRectProximityChanged(
+ .{ .x = sb.x + 4, .y = sb.y + 4, .w = tab_w - 6, .h = 24 },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ if (contentRectProximityChanged(
+ .{ .x = sb.x + tab_w + 2, .y = sb.y + 4, .w = tab_w - 6, .h = 24 },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+
+ if (self.sidebar_tab == .pages and self.sidebar_layout != null) {
+ const sbl = self.sidebar_layout.?;
+ const visible = layout.findVisibleSidebarCards(
+ sbl.cards, self.sidebar_scroll_y, sb.h - 36.0,
+ );
+ if (visible) |range| {
+ for (range.start_index..range.end_index + 1) |i| {
+ const card = sbl.cards[i];
+ if (contentRectProximityChanged(
+ .{
+ .x = sb.x + 16,
+ .y = sb.y + 36 + card.y_offset - self.sidebar_scroll_y,
+ .w = self.sidebar_w - 32,
+ .h = card.card_h,
+ },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ }
+ }
+ } else if (self.sidebar_tab == .outline and self.outline != null) {
+ const row_h = 28.0;
+ for (self.outline.?, 0..) |_, idx| {
+ const row_y = sb.y + 40.0 +
+ @as(f64, @floatFromInt(idx)) * row_h -
+ self.sidebar_scroll_y;
+ if (row_y + row_h < sb.y + 36 or row_y > sb.y + sb.h) continue;
+ if (contentRectProximityChanged(
+ .{ .x = sb.x + 4, .y = row_y, .w = sb.w - 8, .h = row_h },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ }
+ }
+ }
+
+ // Page-number entry is a content redraw, not a toolbar-button redraw.
+ if (contentRectProximityChanged(
+ .{ .x = 126, .y = 8, .w = 48, .h = 28 },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+
+ if (self.search_open) {
+ const sr = self.searchBarRect();
+ if (contentRectProximityChanged(
+ .{ .x = sr.x + 10, .y = sr.y, .w = sr.w - 110, .h = sr.h },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ const close_x = sr.x + sr.w - 28;
+ const next_x = close_x - 28;
+ const prev_x = next_x - 28;
+ for ([_]f64{ prev_x, next_x, close_x }) |x| {
+ if (contentRectProximityChanged(
+ .{ .x = x, .y = sr.y, .w = 28, .h = sr.h },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ }
+ }
+
+ if (self.hbar()) |bar| {
+ const track = bar.track;
+ if (contentRectProximityChanged(
+ .{ .x = track.x, .y = track.y, .w = track.w, .h = track.h },
+ old_x, old_y, new_x, new_y,
+ )) return true;
+ }
+ return false;
+}
+
pub fn handleMotion(self: *App, px: f64, py: f64) void {
const old_x = self.px;
const old_y = self.py;
@@ -80,6 +211,7 @@ pub fn handleMotion(self: *App, px: f64, py: f64) void {
self.py = py;
if (toolbarProximityChanged(self, old_x, old_y, px, py)) self.toolbar_dirty = true;
+ if (contentProximityChanged(self, old_x, old_y, px, py)) self.dirty = true;
if (self.hbar_drag.active) {
if (self.hbar()) |bar| self.scroll_x = self.hbar_drag.offsetAt(bar, @floatCast(px), @floatCast(py));
@@ -152,45 +284,53 @@ pub fn handleMotion(self: *App, px: f64, py: f64) void {
}
}
- // Sidebar hover detection
+ // Sidebar hover detection. Only real cards and rows can remain hovered;
+ // moving over tabs or empty space clears the previous item.
const sb = self.sidebarRect();
+ var found_thumb: ?usize = null;
+ var found_outline: ?usize = null;
if (self.sidebar_open and sb.contains(px, py)) {
- if (self.sidebar_tab == .pages and self.sidebar_layout != null) {
+ if (self.sidebar_tab == .pages and self.sidebar_layout != null and
+ px >= sb.x + 16 and px <= sb.x + self.sidebar_w - 16 and
+ py >= sb.y + 36)
+ {
const sbl = self.sidebar_layout.?;
- const vis_sb = layout.findVisibleSidebarCards(sbl.cards, self.sidebar_scroll_y, sb.h);
- var found: ?usize = null;
- if (vis_sb) |vsb| {
- for (vsb.start_index..vsb.end_index + 1) |i| {
+ const visible = layout.findVisibleSidebarCards(
+ sbl.cards, self.sidebar_scroll_y, sb.h - 36.0,
+ );
+ if (visible) |range| {
+ for (range.start_index..range.end_index + 1) |i| {
const card = sbl.cards[i];
- const card_y = sb.y + card.y_offset - self.sidebar_scroll_y;
+ const card_y = sb.y + 36.0 + card.y_offset - self.sidebar_scroll_y;
if (py >= card_y and py <= card_y + card.card_h) {
- found = i;
+ found_thumb = i;
break;
}
}
}
- if (self.hover_thumb != found) {
- self.hover_thumb = found;
- self.dirty = true;
- }
- } else if (self.sidebar_tab == .outline and self.outline != null) {
- const row_h = 28.0;
+ } else if (self.sidebar_tab == .outline and self.outline != null and
+ py >= sb.y + 40.0)
+ {
const rel_y = py - (sb.y + 40.0) + self.sidebar_scroll_y;
- if (rel_y >= 0) {
- const idx: usize = @intFromFloat(rel_y / row_h);
- if (idx < self.outline.?.len and self.hover_outline != idx) {
- self.hover_outline = idx;
- self.dirty = true;
+ const idx: usize = @intFromFloat(rel_y / 28.0);
+ if (idx < self.outline.?.len) {
+ const row_y = sb.y + 40.0 +
+ @as(f64, @floatFromInt(idx)) * 28.0 -
+ self.sidebar_scroll_y;
+ if (py >= row_y and py <= row_y + 28.0 and
+ px >= sb.x + 4 and px <= sb.x + sb.w - 4)
+ {
+ found_outline = idx;
}
}
}
- } else {
- if (self.hover_thumb != null or self.hover_outline != null) {
- self.hover_thumb = null;
- self.hover_outline = null;
- self.dirty = true;
- }
}
+ if (self.hover_thumb != found_thumb or self.hover_outline != found_outline) {
+ self.hover_thumb = found_thumb;
+ self.hover_outline = found_outline;
+ self.dirty = true;
+ }
+
}
pub fn handleButton(self: *App, button: u32, pressed: bool) void {