Skip to content

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

feat(ui): extend proximity glow to interactive surfaces

Petar Margetićb5b5771112ea
diff --git a/src/control_center/sections/appearance_rows.zig b/src/control_center/sections/appearance_rows.zig
index b06561f..1adb82d 100644
--- a/src/control_center/sections/appearance_rows.zig
+++ b/src/control_center/sections/appearance_rows.zig
@@ -352,8 +352,8 @@ pub fn buildFontRows(out: *Section, arena: std.mem.Allocator, t: theme.Theme, pa
};
out.button_hover_glow_label_children = .{
- .{ .kind = .{ .text = .{ .content = i18n.tr("Button hover glow"), .font_size = theme.global.app_text_size, .weight = 600, .color = pal.fg } } },
- .{ .kind = .{ .text = .{ .content = i18n.tr("Light button edges near the pointer"), .font_size = theme.global.settings_description_size, .color = pal.dim } } },
+ .{ .kind = .{ .text = .{ .content = i18n.tr("Interactive surface glow"), .font_size = theme.global.app_text_size, .weight = 600, .color = pal.fg } } },
+ .{ .kind = .{ .text = .{ .content = i18n.tr("Light interactive control edges near the pointer"), .font_size = theme.global.settings_description_size, .color = pal.dim } } },
};
out.button_hover_glow_row_children = .{
.{ .kind = .container, .direction = .column, .gap = 2, .width = .{ .flex = 1 }, .children = &out.button_hover_glow_label_children },
diff --git a/src/ui/input.zig b/src/ui/input.zig
index 9e464eb..f0cda2c 100644
--- a/src/ui/input.zig
+++ b/src/ui/input.zig
@@ -17,6 +17,7 @@ const interaction_surface = @import("interaction_surface.zig");
const theme = @import("theme.zig");
const checkbox_widget = @import("widgets/checkbox.zig");
const scroll_widget = @import("widgets/scroll_container.zig");
+const scrollbar = @import("widgets/scrollbar.zig");
const text_input_widget = @import("widgets/text_input.zig");
const toggle_widget = @import("widgets/toggle.zig");
const slider_widget = @import("widgets/slider.zig");
@@ -46,11 +47,11 @@ fn widgetRect(widget: *const Widget) ProximityRect {
};
}
-/// Updates every button in the retained tree, not merely the hit-tested one.
-/// `viewport` is the host panel's visible content rectangle. Scroll containers
-/// add their own paint clip as recursion descends. Returns true only when a
-/// button's stored sample actually changes.
-pub fn updateButtonProximity(
+/// Updates proximity samples for every interactive surface in the
+/// retained tree, not merely the hit-tested one. `viewport` is the host
+/// panel's visible content rectangle; scroll containers add their paint clip
+/// as recursion descends. Returns true only when a stored sample changes.
+pub fn updateInteractiveProximity(
root: *Widget,
x: f32,
y: f32,
@@ -58,35 +59,192 @@ pub fn updateButtonProximity(
) bool {
var changed = false;
const root_clip = button_widget.intersectRect(viewport, widgetRect(root));
- sampleButtonProximity(root, x, y, root_clip, &changed);
+ sampleInteractiveProximity(root, x, y, root_clip, root_clip, &changed);
return changed;
}
-fn sampleButtonProximity(
+/// Retain the old entry point for callers that still use the button-only name.
+pub fn updateButtonProximity(
+ root: *Widget,
+ x: f32,
+ y: f32,
+ viewport: ProximityRect,
+) bool {
+ return updateInteractiveProximity(root, x, y, viewport);
+}
+
+const ProximityTarget = struct {
+ rect: button_widget.Rect,
+ clip: button_widget.Rect,
+};
+
+fn proximityTarget(
widget: *Widget,
x: f32,
y: f32,
- clip: ProximityRect,
- changed: *bool,
-) void {
+ clip: button_widget.Rect,
+ overlay_clip: button_widget.Rect,
+) ?ProximityTarget {
+ const bounds = widgetRect(widget);
+ var rect = bounds;
+ var target_clip = clip;
+
switch (widget.kind) {
- .button => |*data| {
- const sample = interaction_surface.sampleButtonProximity(
- widgetRect(widget), x, y, clip, theme.global.border_glow_reach,
+ .button => |data| {
+ if (data.state == .disabled) return null;
+ },
+ .row => |data| {
+ if (data.state == .disabled) return null;
+ },
+ .checkbox => |data| {
+ if (data.disabled) return null;
+ },
+ .toggle => |data| {
+ if (data.disabled) return null;
+ },
+ .select => |data| {
+ if (data.disabled) return null;
+ },
+ .scroll_container => |data| {
+ // Keep sampling the groove geometry even when its current relief is
+ // flat; the painter decides whether that groove is visible.
+ const geometry = scroll_widget.geometry(widget) orelse return null;
+ const look = scrollbar.look(
+ geometry,
+ data.bar,
+ theme.global.scrollbar_width,
+ theme.global,
);
- const sample_x = sample.x;
- const sample_y = sample.y;
+ rect = .{
+ .x = look.track.x,
+ .y = look.track.y,
+ .w = look.track.w,
+ .h = look.track.h,
+ };
+ },
+ .text_input, .secret_input, .slider, .segmented, .swatch,
+ .stepper, .arrangement => {},
+ else => return null,
+ }
+
+ // Dropdowns paint outside their normal tree position. Compare the
+ // control and popup samples, using the root overlay clip for the popup.
+ if (widget.kind == .select and widget.kind.select.open) {
+ const popup = select_widget.popupBounds(widget);
+ const popup_rect: button_widget.Rect = .{
+ .x = popup.x,
+ .y = popup.y,
+ .w = popup.w,
+ .h = popup.h,
+ };
+ const popup_clip = button_widget.intersectRect(overlay_clip, popup_rect);
+ const popup_sample = interaction_surface.sampleButtonProximity(
+ popup_rect, x, y, popup_clip, theme.global.border_glow_reach,
+ );
+ const control_sample = interaction_surface.sampleButtonProximity(
+ bounds, x, y, clip, theme.global.border_glow_reach,
+ );
+ if (popup_sample.distance < control_sample.distance) {
+ rect = popup_rect;
+ target_clip = popup_clip;
+ }
+ }
+
+ // A checkbox's interactive surface is its square, not the label row.
+ if (widget.kind == .checkbox) {
+ const side = checkbox_widget.box_size;
+ rect = .{
+ .x = bounds.x,
+ .y = bounds.y + (bounds.h - side) / 2,
+ .w = side,
+ .h = side,
+ };
+ }
+
+ return .{ .rect = rect, .clip = target_clip };
+}
+
+fn sameProximity(a: layout.ProximityData, b: layout.ProximityData) bool {
+ return a.distance == b.distance and a.x == b.x and a.y == b.y and
+ a.rect.x == b.rect.x and a.rect.y == b.rect.y and
+ a.rect.w == b.rect.w and a.rect.h == b.rect.h;
+}
+
+fn clearWidgetProximity(widget: *Widget) bool {
+ var dirty = false;
+
+ if (widget.kind == .button) {
+ const data = &widget.kind.button;
+ if (data.proximity_distance != std.math.inf(f32) or
+ data.proximity_x != 0 or data.proximity_y != 0)
+ {
+ data.proximity_distance = std.math.inf(f32);
+ data.proximity_x = 0;
+ data.proximity_y = 0;
+ dirty = true;
+ }
+ }
+
+ if (!sameProximity(widget.proximity, .{})) {
+ widget.proximity = .{};
+ dirty = true;
+ }
+
+ if (dirty) widget.markPaintDirty();
+ return dirty;
+}
+
+fn sampleInteractiveProximity(
+ widget: *Widget,
+ x: f32,
+ y: f32,
+ clip: button_widget.Rect,
+ overlay_clip: button_widget.Rect,
+ changed: *bool,
+) void {
+ if (proximityTarget(widget, x, y, clip, overlay_clip)) |target| {
+ const sample = interaction_surface.sampleButtonProximity(
+ target.rect,
+ x,
+ y,
+ target.clip,
+ theme.global.border_glow_reach,
+ );
+
+ if (widget.kind == .button) {
+ const data = &widget.kind.button;
if (data.proximity_distance != sample.distance or
- data.proximity_x != sample_x or data.proximity_y != sample_y)
+ data.proximity_x != sample.x or data.proximity_y != sample.y)
{
data.proximity_distance = sample.distance;
- data.proximity_x = sample_x;
- data.proximity_y = sample_y;
+ data.proximity_x = sample.x;
+ data.proximity_y = sample.y;
widget.markPaintDirty();
changed.* = true;
}
- },
- else => {},
+ } else {
+ var next: layout.ProximityData = .{};
+ if (sample.distance < std.math.inf(f32)) {
+ next = .{
+ .rect = .{
+ .x = target.rect.x,
+ .y = target.rect.y,
+ .w = target.rect.w,
+ .h = target.rect.h,
+ },
+ .distance = sample.distance,
+ .x = sample.x,
+ .y = sample.y,
+ };
+ }
+ if (!sameProximity(widget.proximity, next)) {
+ widget.proximity = next;
+ widget.markPaintDirty();
+ changed.* = true;
+ }
+ }
+ } else if (clearWidgetProximity(widget)) {
+ changed.* = true;
}
// paintScrollContainer clips all descendants to its own full rectangle.
@@ -96,10 +254,20 @@ fn sampleButtonProximity(
clip;
for (widget.children) |*child| {
- sampleButtonProximity(child, x, y, child_clip, changed);
+ sampleInteractiveProximity(child, x, y, child_clip, overlay_clip, changed);
}
}
+/// Clears retained proximity state when the host surface loses the pointer.
+pub fn clearInteractiveProximity(root: *Widget) void {
+ clearInteractiveProximityTree(root);
+}
+
+fn clearInteractiveProximityTree(widget: *Widget) void {
+ _ = clearWidgetProximity(widget);
+ for (widget.children) |*child| clearInteractiveProximityTree(child);
+}
+
pub const HitResult = struct {
widget: ?*Widget,
/// The nearest enclosing `.scroll_container`, if any — its scrollbar is
@@ -318,6 +486,7 @@ pub const Dispatcher = struct {
pub fn pointerLeave(self: *Dispatcher, root: *Widget) void {
if (self.tree != root) return;
_ = self.surface.pointerLeave();
+ clearInteractiveProximity(root);
if (self.thumb_hover) |prev| setThumbHover(prev, false);
self.thumb_hover = null;
// A slider is only lit while the pointer is over it; forgetting it as
diff --git a/src/ui/input_pointer.zig b/src/ui/input_pointer.zig
index c97a506..1a38a06 100644
--- a/src/ui/input_pointer.zig
+++ b/src/ui/input_pointer.zig
@@ -32,7 +32,7 @@ const findScrollContainer = input_mod.findScrollContainer;
pub fn pointerMotion(self: *Dispatcher, root: *Widget, x: f32, y: f32) void {
self.bindTree(root);
- _ = input_mod.updateButtonProximity(root, x, y, .{
+ _ = input_mod.updateInteractiveProximity(root, x, y, .{
.x = root.computed_x,
.y = root.computed_y,
.w = root.computed_width,
diff --git a/src/ui/input_tests.zig b/src/ui/input_tests.zig
index 7574e3c..a439370 100644
--- a/src/ui/input_tests.zig
+++ b/src/ui/input_tests.zig
@@ -3,6 +3,7 @@
const std = @import("std");
const anim = @import("anim.zig");
const layout = @import("layout.zig");
+const theme = @import("theme.zig");
const Widget = layout.Widget;
const scroll_widget = @import("widgets/scroll_container.zig");
const hitTest = @import("input.zig").hitTest;
@@ -204,6 +205,120 @@ test "dispatcher forwards retained-tree hits to the interaction surface" {
try std.testing.expect(dispatcher.surface.hovered == null);
}
+test "proximity samples shared widget surfaces and clears on pointer leave" {
+ const TextSink = struct {
+ fn call(_: ?*anyopaque, _: usize, _: []const u8) void {}
+ };
+ const CheckSink = struct {
+ fn call(_: ?*anyopaque, _: usize, _: bool) void {}
+ };
+
+ var children = [_]Widget{
+ .{
+ .kind = .{ .text_input = .{
+ .placeholder = "",
+ .value = &.{},
+ .on_change = TextSink.call,
+ } },
+ .computed_x = 10,
+ .computed_y = 10,
+ .computed_width = 60,
+ .computed_height = 30,
+ },
+ .{
+ .kind = .{ .checkbox = .{
+ .label = "Enabled",
+ .checked = false,
+ .on_change = CheckSink.call,
+ } },
+ .computed_x = 100,
+ .computed_y = 10,
+ .computed_width = 80,
+ .computed_height = 30,
+ },
+ .{
+ .kind = .{ .checkbox = .{
+ .label = "Disabled",
+ .checked = false,
+ .disabled = true,
+ .on_change = CheckSink.call,
+ } },
+ .computed_x = 200,
+ .computed_y = 10,
+ .computed_width = 80,
+ .computed_height = 30,
+ },
+ };
+ var root: Widget = .{
+ .kind = .container,
+ .computed_width = 300,
+ .computed_height = 60,
+ .children = &children,
+ };
+ root.linkParents();
+
+ var dispatcher = Dispatcher{};
+ dispatcher.pointerMotion(&root, 20, 20);
+
+ const field = &root.children[0];
+ try std.testing.expectEqual(@as(f32, 0), field.proximity.distance);
+ try std.testing.expectEqual(@as(f32, 10), field.proximity.x);
+ try std.testing.expectEqual(@as(f32, 10), field.proximity.y);
+
+ // The checkbox illuminates its square, not the label's whole row.
+ const checkbox = &root.children[1];
+ try std.testing.expect(std.math.isInf(checkbox.proximity.distance));
+ dispatcher.pointerMotion(&root, 105, 20);
+ try std.testing.expectEqual(@as(f32, 0), checkbox.proximity.distance);
+ try std.testing.expectEqual(@as(f32, 100), checkbox.proximity.rect.x);
+ try std.testing.expectEqual(@as(f32, 16), checkbox.proximity.rect.y);
+ try std.testing.expectEqual(@as(f32, 18), checkbox.proximity.rect.w);
+ try std.testing.expectEqual(@as(f32, 18), checkbox.proximity.rect.h);
+ try std.testing.expectEqual(@as(f32, 5), checkbox.proximity.x);
+ try std.testing.expectEqual(@as(f32, 4), checkbox.proximity.y);
+
+ // Disabled controls never acquire a proximity sample.
+ try std.testing.expect(std.math.isInf(root.children[2].proximity.distance));
+
+ dispatcher.pointerLeave(&root);
+ try std.testing.expect(std.math.isInf(field.proximity.distance));
+ try std.testing.expect(std.math.isInf(checkbox.proximity.distance));
+}
+
+test "scrollbar groove proximity follows the visible inset groove" {
+ const saved_theme = theme.global;
+ defer theme.global = saved_theme;
+ theme.global.scrollbar_width = 8;
+ theme.global.scrollbar_track_relief = .inset;
+
+ var root: Widget = .{
+ .kind = .{ .scroll_container = .{ .content_size = 200 } },
+ .direction = .column,
+ .computed_x = 20,
+ .computed_y = 20,
+ .computed_width = 100,
+ .computed_height = 100,
+ };
+
+ var dispatcher = Dispatcher{};
+ dispatcher.pointerMotion(&root, 110, 90);
+
+ // The 14 px gutter produces a 12 px inset groove at x=107.
+ try std.testing.expectEqual(@as(f32, 0), root.proximity.distance);
+ try std.testing.expectEqual(@as(f32, 107), root.proximity.rect.x);
+ try std.testing.expectEqual(@as(f32, 20), root.proximity.rect.y);
+ try std.testing.expectEqual(@as(f32, 12), root.proximity.rect.w);
+ try std.testing.expectEqual(@as(f32, 100), root.proximity.rect.h);
+ try std.testing.expectEqual(@as(f32, 3), root.proximity.x);
+ try std.testing.expectEqual(@as(f32, 70), root.proximity.y);
+
+ // Sampling is independent of relief so making the groove visible again
+ // does not require another pointer movement. The painter gates flat tracks.
+ theme.global.scrollbar_track_relief = .flat;
+ dispatcher.pointerMotion(&root, 110, 90);
+ try std.testing.expectEqual(@as(f32, 0), root.proximity.distance);
+}
+
test "hitTest returns the topmost overlapping widget" {
var kids = [_]Widget{
.{ .kind = .container },
diff --git a/src/ui/layout.zig b/src/ui/layout.zig
index 355607e..335f2ed 100644
--- a/src/ui/layout.zig
+++ b/src/ui/layout.zig
@@ -495,6 +495,22 @@ pub const WidgetKind = union(enum) {
container,
};
+pub const ProximityRect = struct {
+ x: f32 = 0,
+ y: f32 = 0,
+ w: f32 = 0,
+ h: f32 = 0,
+};
+
+/// Pointer sample for a shared interactive surface. Coordinates are local
+/// to `rect`; an infinite distance means the pointer is outside glow reach.
+pub const ProximityData = struct {
+ rect: ProximityRect = .{},
+ distance: f32 = std.math.inf(f32),
+ x: f32 = 0,
+ y: f32 = 0,
+};
+
pub const Widget = struct {
// --- Layout inputs (set by caller) ---
width: SizeConstraint = .auto,
@@ -518,6 +534,9 @@ pub const Widget = struct {
computed_width: f32 = 0,
computed_height: f32 = 0,
+ /// Mouse-proximity illumination state for non-button interactive surfaces.
+ proximity: ProximityData = .{},
+
// --- Widget identity ---
name: ?[]const u8 = null,
kind: WidgetKind,
diff --git a/src/ui/paint.zig b/src/ui/paint.zig
index 8407749..ffb5db7 100644
--- a/src/ui/paint.zig
+++ b/src/ui/paint.zig
@@ -696,6 +696,9 @@ pub fn paintTree(widget: *const Widget, renderer: *Renderer) void {
}
if (recurse_children) {
if (widget.underlay) |under| under.paint(under.owner, widget, renderer);
+ }
+ paint_widgets.paintInteractiveProximity(widget, renderer);
+ if (recurse_children) {
for (widget.children) |*child| paintTree(child, renderer);
}
}
diff --git a/src/ui/paint_tests.zig b/src/ui/paint_tests.zig
index b18e45f..505589f 100644
--- a/src/ui/paint_tests.zig
+++ b/src/ui/paint_tests.zig
@@ -817,6 +817,121 @@ test "button hover glow is independent of window edge glow and stays rounded and
}
}
+test "non-button interactive surfaces use the shared proximity edge painter" {
+ const background: u32 = 0xff808080;
+ var pixels: [80 * 60]u32 = @splat(background);
+ var renderer = Renderer.init(&pixels, 80, 60, 1);
+ var palette: theme.Theme = .{};
+ palette.button_hover_glow_enabled = true;
+ palette.border_glow = .{ 1, 0, 0, 0.60 };
+ palette.border_glow_reach = 56;
+ palette.border_glow_length = 72;
+ palette.border_glow_depth = 3;
+ renderer.palette = palette;
+ renderer.clip = .{ .x = 30, .y = 20, .w = 20, .h = 24 };
+
+ var widget = Widget{
+ .kind = .{ .row = .{} },
+ .computed_x = 20,
+ .computed_y = 20,
+ .computed_width = 40,
+ .computed_height = 24,
+ .proximity = .{
+ .rect = .{ .x = 20, .y = 20, .w = 40, .h = 24 },
+ .distance = 4,
+ .x = 20,
+ .y = -4,
+ },
+ };
+ paintTree(&widget, &renderer);
+ const illuminated = pixels;
+
+ widget.proximity = .{};
+ @memset(&pixels, background);
+ paintTree(&widget, &renderer);
+ try std.testing.expect(!std.mem.eql(u32, &illuminated, &pixels));
+
+ // The shared painter respects the renderer's clip.
+ try std.testing.expectEqual(background, illuminated[20 * 80 + 25]);
+ try std.testing.expect(illuminated[20 * 80 + 40] != background);
+
+ // A control becoming disabled must stop painting its cached sample,
+ // even when the pointer has not moved to trigger another sample.
+ widget.kind.row.state = .disabled;
+ widget.proximity = .{
+ .rect = .{ .x = 20, .y = 20, .w = 40, .h = 24 },
+ .distance = 4,
+ .x = 20,
+ .y = -4,
+ };
+ @memset(&pixels, background);
+ paintTree(&widget, &renderer);
+ try std.testing.expect(std.mem.eql(u32, &pixels, &@as([80 * 60]u32, @splat(background))));
+}
+
+test "scrollbar groove proximity glows without covering the thumb" {
+ const background: u32 = 0xff808080;
+ const saved_theme = theme.global;
+ defer theme.global = saved_theme;
+
+ var palette: theme.Theme = .{};
+ palette.button_hover_glow_enabled = true;
+ palette.border_glow = .{ 1, 0, 0, 0.60 };
+ palette.border_glow_reach = 56;
+ palette.border_glow_length = 72;
+ palette.border_glow_depth = 3;
+ palette.scrollbar_width = 8;
+ palette.scrollbar_track_relief = .inset;
+ theme.global = palette;
+
+ var pixels: [160 * 160]u32 = @splat(background);
+ var renderer = Renderer.init(&pixels, 160, 160, 1);
+ renderer.palette = palette;
+
+ var widget = Widget{
+ .kind = .{ .scroll_container = .{ .content_size = 200 } },
+ .direction = .column,
+ .computed_x = 20,
+ .computed_y = 20,
+ .computed_width = 100,
+ .computed_height = 100,
+ .proximity = .{
+ .rect = .{ .x = 107, .y = 20, .w = 12, .h = 100 },
+ .distance = 0,
+ .x = 3,
+ .y = 70,
+ },
+ };
+
+ paintTree(&widget, &renderer);
+ const with_glow = pixels;
+
+ widget.proximity = .{};
+ @memset(&pixels, background);
+ paintTree(&widget, &renderer);
+ const without_glow = pixels;
+
+ const groove_edge = 90 * 160 + 107;
+ const thumb_centre = 35 * 160 + 113;
+
+ try std.testing.expect(with_glow[groove_edge] != without_glow[groove_edge]);
+ // The thumb is painted after the groove glow and remains unchanged.
+ try std.testing.expectEqual(without_glow[thumb_centre], with_glow[thumb_centre]);
+
+ // A flat track remains unlit even though its proximity sample is retained.
+ palette.scrollbar_track_relief = .flat;
+ theme.global = palette;
+ renderer.palette = palette;
+ @memset(&pixels, background);
+ paintTree(&widget, &renderer);
+ const flat_with_sample = pixels;
+
+ widget.proximity = .{};
+ @memset(&pixels, background);
+ paintTree(&widget, &renderer);
+ try std.testing.expect(std.mem.eql(u32, &flat_with_sample, &pixels));
+}
+
test "button hover glow lights adjacent and independently reachable edges" {
const sample = struct {
fn red(pixels: []const u32, x: usize, y: usize) u32 {
diff --git a/src/ui/paint_widgets.zig b/src/ui/paint_widgets.zig
index 5b5c8df..9ee850c 100644
--- a/src/ui/paint_widgets.zig
+++ b/src/ui/paint_widgets.zig
@@ -80,6 +80,65 @@ pub fn paintButton(widget: *const Widget, data: ButtonData, renderer: *Renderer)
});
}
+fn paintProximitySample(widget: *const Widget, renderer: *Renderer) void {
+ const disabled = switch (widget.kind) {
+ .button => |data| data.state == .disabled,
+ .row => |data| data.state == .disabled,
+ .checkbox => |data| data.disabled,
+ .toggle => |data| data.disabled,
+ .select => |data| data.disabled,
+ else => false,
+ };
+ if (disabled) return;
+
+ const sample = widget.proximity;
+ if (sample.distance >= std.math.inf(f32)) return;
+
+ const box: button_widget.Rect = .{
+ .x = sample.rect.x,
+ .y = sample.rect.y,
+ .w = sample.rect.w,
+ .h = sample.rect.h,
+ };
+ const t = renderer.palette orelse theme.global;
+ const radius: f32 = switch (widget.kind) {
+ .row => |data| if (data.background) |style| style.radius else t.radius,
+ .checkbox => t.checkbox_radius,
+ .text_input => |data| field_widget.metrics(data.field.size, t).radius,
+ .secret_input => |data| field_widget.metrics(data.field.size, t).radius,
+ .toggle => |data| if (data.style == .settings) t.toggle_radius else box.h / 2,
+ .slider => box.h / 2,
+ .select, .segmented, .stepper, .arrangement => t.radius,
+ .swatch => t.swatch_radius,
+ else => return,
+ };
+
+ button_widget.paintProximityGlowAt(
+ renderer, box, radius, sample.distance, sample.x, sample.y,
+ );
+}
+
+/// Paints proximity illumination during the normal tree pass. A dropdown
+/// popup sample is deferred to the overlay pass below.
+pub fn paintInteractiveProximity(widget: *const Widget, renderer: *Renderer) void {
+ if (widget.kind == .select and widget.kind.select.open) {
+ const popup = @import("widgets/select.zig").popupBounds(widget);
+ const sample = widget.proximity.rect;
+ if (sample.x == popup.x and sample.y == popup.y and
+ sample.w == popup.w and sample.h == popup.h) return;
+ }
+ paintProximitySample(widget, renderer);
+}
+
+fn paintSelectPopupProximity(widget: *const Widget, renderer: *Renderer) void {
+ if (!(widget.kind == .select and widget.kind.select.open)) return;
+ const popup = @import("widgets/select.zig").popupBounds(widget);
+ const sample = widget.proximity.rect;
+ if (sample.x != popup.x or sample.y != popup.y or
+ sample.w != popup.w or sample.h != popup.h) return;
+ paintProximitySample(widget, renderer);
+}
+
pub fn paintCheckbox(widget: *const Widget, data: CheckboxData, renderer: *Renderer) void {
checkbox_widget.paint(renderer, .{
.x = widget.computed_x,
@@ -383,6 +442,33 @@ pub fn paintStepper(widget: *const Widget, data: StepperData, renderer: *Rendere
});
}
+fn paintScrollbarGrooveProximity(
+ widget: *const Widget,
+ look: scrollbar.Look,
+ renderer: *Renderer,
+) void {
+ const sample = widget.proximity;
+ if (look.track_relief == .flat or sample.distance >= std.math.inf(f32)) return;
+
+ // Only paint a sample that still belongs to this groove's geometry.
+ if (sample.rect.x != look.track.x or sample.rect.y != look.track.y or
+ sample.rect.w != look.track.w or sample.rect.h != look.track.h) return;
+
+ button_widget.paintProximityGlowAt(
+ renderer,
+ .{
+ .x = look.track.x,
+ .y = look.track.y,
+ .w = look.track.w,
+ .h = look.track.h,
+ },
+ look.track_radius,
+ sample.distance,
+ sample.x,
+ sample.y,
+ );
+}
+
pub fn paintScrollContainer(widget: *const Widget, state: ScrollState, renderer: *Renderer) void {
const prev_clip = renderer.clip;
renderer.clip = intersectClip(prev_clip, .{ .x = widget.computed_x, .y = widget.computed_y, .w = widget.computed_width, .h = widget.computed_height });
@@ -400,7 +486,10 @@ pub fn paintScrollContainer(widget: *const Widget, state: ScrollState, renderer:
const g = @import("widgets/scroll_container.zig").geometry(widget) orelse return;
const t = renderer.palette orelse theme.global;
- scrollbar.paint(renderer, scrollbar.look(g, state.bar, theme.global.scrollbar_width, t));
+ const look = scrollbar.look(g, state.bar, theme.global.scrollbar_width, t);
+ scrollbar.paintTrack(renderer, look);
+ paintScrollbarGrooveProximity(widget, look, renderer);
+ scrollbar.paintThumb(renderer, look);
}
pub fn intersectClip(a: ?ClipRect, b: ClipRect) ClipRect {
@@ -456,6 +545,7 @@ pub fn paintOverlays(widget: *const Widget, r: *Renderer) void {
if (scrollbar.Geometry.compute(.vertical, track, @floatFromInt(visible), @floatFromInt(d.labels.len), @floatFromInt(d.first_visible))) |g|
scrollbar.paint(r, scrollbar.look(g, .{}, theme.global.scrollbar_width, t));
}
+ paintSelectPopupProximity(widget, r);
}
for (widget.children) |*child| paintOverlays(child, r);
}
diff --git a/src/ui/theme.zig b/src/ui/theme.zig
index f489263..cf2ff60 100644
--- a/src/ui/theme.zig
+++ b/src/ui/theme.zig
@@ -211,7 +211,8 @@ pub const Theme = struct {
/// (`Toplevel.setGlow`). Its alpha is the strength at full proximity; zero
/// turns it off.
border_glow_enabled: bool = true,
- /// Independent gate for proximity highlights painted inside buttons.
+ /// Shared gate for proximity highlights painted inside interactive
+ /// widget surfaces. The legacy key name is retained for theme compatibility.
/// Colour and reach/length/depth are shared with the window-edge glow.
button_hover_glow_enabled: bool = true,
border_glow: [4]f32 = .{ 237.0 / 255.0, 27.0 / 255.0, 46.0 / 255.0, 0.60 },
diff --git a/src/ui/widgets/button.zig b/src/ui/widgets/button.zig
index e3b59b1..aa323f9 100644
--- a/src/ui/widgets/button.zig
+++ b/src/ui/widgets/button.zig
@@ -297,8 +297,29 @@ fn glowNear(px: f32, py: f32, edge_x: f32, edge_y: f32, reach: f32) f32 {
/// Paints independent pointer-facing highlights on every nearby button edge.
/// Overlapping edge contributions use their maximum, keeping corners controlled.
fn paintProximityGlow(r: *Renderer, box: Rect, radius: f32, state: State) void {
+ if (state.pointer == .disabled) return;
+ paintProximityGlowAt(
+ r,
+ box,
+ radius,
+ state.proximity_distance,
+ state.proximity_x,
+ state.proximity_y,
+ );
+}
+
+/// Shared edge-light painter for buttons and other interactive surfaces.
+/// Pointer coordinates are local to `box`.
+pub fn paintProximityGlowAt(
+ r: *Renderer,
+ box: Rect,
+ radius: f32,
+ proximity_distance: f32,
+ proximity_x: f32,
+ proximity_y: f32,
+) void {
const t = r.palette orelse theme.global;
- if (!t.button_hover_glow_enabled or state.proximity_distance >= std.math.inf(f32) or
+ if (!t.button_hover_glow_enabled or proximity_distance >= std.math.inf(f32) or
t.border_glow[3] <= 0 or t.border_glow_reach <= 0 or
t.border_glow_length <= 0 or t.border_glow_depth <= 0 or
box.w <= 0 or box.h <= 0)
@@ -306,8 +327,8 @@ fn paintProximityGlow(r: *Renderer, box: Rect, radius: f32, state: State) void {
const corner_radius = std.math.clamp(radius, 0, 0.5 * @min(box.w, box.h));
const reach = t.border_glow_reach;
- const pointer_x = state.proximity_x;
- const pointer_y = state.proximity_y;
+ const pointer_x = proximity_x;
+ const pointer_y = proximity_y;
const Edge = struct {
x: f32,