use ui::scroll::{self, Axes, ScrollbarState};
// in the view's constructor: scroll_bar: ScrollbarState::new(Painter::of(cx))
div().relative() // the bar is absolute in here
.child(
scroll::pane("pane", Axes::Vertical)
.size_full()
.track_scroll(&self.scroll) // a gpui ScrollHandle field
.child(content),
)
.child(scroll::scrollbar("pane-bar", &self.scroll, &self.scroll_bar))- The bar must span the container it reports on; its track is the viewport.
- Keep
ScrollHandleandScrollbarStateas fields on the view, not built per render. scroll::thumbandscroll::offset_for_thumbtake gpui's conventions:max_offsetis the overflow (content minus viewport) andoffsetis negative as you scroll down.