use crate::{ScrollbarAxis, ScrollbarHandle};
use gpui::{AnyElement, App, Bounds, Pixels, Point, ScrollHandle, Size, Window};
use std::rc::Rc;
#[derive(Clone)]
pub struct EditorScrollbarContext {
pub(crate) handle: ScrollHandle,
pub(crate) viewport: Bounds<Pixels>,
pub(crate) scroll_viewport: Size<Pixels>,
pub(crate) content: Size<Pixels>,
pub(crate) axis: ScrollbarAxis,
}
impl EditorScrollbarContext {
pub fn axis(&self) -> ScrollbarAxis {
self.axis
}
pub fn scroll_viewport_size(&self) -> Size<Pixels> {
self.scroll_viewport
}
}
impl ScrollbarHandle for EditorScrollbarContext {
fn viewport_bounds(&self) -> Bounds<Pixels> {
self.viewport
}
fn content_size(&self) -> Size<Pixels> {
self.content + (self.viewport.size - self.scroll_viewport)
}
fn offset(&self) -> Point<Pixels> {
self.handle.offset()
}
fn set_offset(&self, offset: Point<Pixels>) {
self.handle.set_offset(offset);
}
}
pub type EditorScrollbarRenderer =
Rc<dyn Fn(EditorScrollbarContext, &mut Window, &mut App) -> AnyElement>;