gpui_base/input/
scrollbar_presentation.rs1use crate::{ScrollbarAxis, ScrollbarHandle};
3use gpui::{AnyElement, App, Bounds, Pixels, Point, ScrollHandle, Size, Window};
4use std::rc::Rc;
5
6#[derive(Clone)]
11pub struct EditorScrollbarContext {
12 pub(crate) handle: ScrollHandle,
13 pub(crate) viewport: Bounds<Pixels>,
14 pub(crate) scroll_viewport: Size<Pixels>,
15 pub(crate) content: Size<Pixels>,
16 pub(crate) axis: ScrollbarAxis,
17}
18
19impl EditorScrollbarContext {
20 pub fn axis(&self) -> ScrollbarAxis {
21 self.axis
22 }
23
24 pub fn scroll_viewport_size(&self) -> Size<Pixels> {
29 self.scroll_viewport
30 }
31}
32
33impl ScrollbarHandle for EditorScrollbarContext {
34 fn viewport_bounds(&self) -> Bounds<Pixels> {
35 self.viewport
36 }
37 fn content_size(&self) -> Size<Pixels> {
38 self.content + (self.viewport.size - self.scroll_viewport)
39 }
40 fn offset(&self) -> Point<Pixels> {
41 self.handle.offset()
42 }
43 fn set_offset(&self, offset: Point<Pixels>) {
44 self.handle.set_offset(offset);
45 }
46}
47
48pub type EditorScrollbarRenderer =
50 Rc<dyn Fn(EditorScrollbarContext, &mut Window, &mut App) -> AnyElement>;