Scrollbar

An interactive scroll position control.

Basic use

Radix · integration snippet
use xgpui_luma_look_radix as radix;
use gpui::{Context};
use xgpui_luma::controls::scrollbar::Scrollbar;

struct Example {
    control: gpui::Entity<xgpui_luma::controls::scrollbar::Scrollbar>,
    scroll_offset: f32,
}

impl Example {
    fn new(cx: &mut Context<Self>) -> Self {
        let look = radix::Look::built_in();
        let control = Scrollbar::new("scrollbar").template(radix::scrollbar_template(&look))
            .on_value_changed(cx, |app, value, cx| {
                app.scroll_offset = value;
                cx.notify();
            })
            .spawn(cx);

        Self { control, scroll_offset: 0.0 }
    }
}

Integration snippet, checked against the current SDK and Radix crates. cx is the initialized owner context. The control retains its callbacks; callback owners are held weakly. Render self.control.clone() in the owner’s view.

Radix styling

Install radix::scrollbar_template(&look) on the SDK Scrollbar builder, ScrollContainer, or PopupScrollSurface. scrollbar_theme(&look) supports custom templates. Ghost and Soft styles use the neutral scale; geometry uses SDK size keys sm, md, and lg.

Pass an explicit Look, including forks. Theme adapters retain that binding; notify affected controls and their owners after palette, mode, or stylesheet edits. Resolved look values are snapshots and must be resolved again during render.

See the Radix control support table for adapter and utility status.

SDK behavior & customization

Bind its range and value to the viewport. Change reports a requested position.

Relevant contracts: ScrollbarRenderModel, ScrollbarTemplateHandlers, ScrollbarTemplateModifier, ScrollbarTemplate.

Use the module’s template contract for structural changes. Builder modifiers and item templates vary by control.

Events

Callbacks follow the existing SDK event stream. Registrations append, hold the owner weakly, and live until the control is released. cx.notify() requests an owner redraw. Compound payloads are borrowed; scalar values are passed by value.

Event / payloadCallback
Change { value: f32 }.on_value_changed(cx, |app, value, cx| { … })
DragStart.on_drag_start(cx, |app, cx| { … })
DragEnd { value: f32 }.on_drag_end(cx, |app, value, cx| { … })
FocusChanged { focused: bool }.on_focus_changed(cx, |app, focused, cx| { … })
HoverChanged { hovered: bool }.on_hover_changed(cx, |app, hovered, cx| { … })
EnabledChanged { enabled: bool }.on_enabled_changed(cx, |app, enabled, cx| { … })

Use .on_event(cx, |app, event, cx| { … }) for all events. Factory-created controls support the same callbacks through ScrollbarEventExt. Existing cx.subscribe observers remain supported.

Source

SDK module · Radix adapter