From 343905811cfb5d87e5450b197b35b8ae5b050b2a Mon Sep 17 00:00:00 2001 From: mars Date: Wed, 13 Jul 2022 14:03:15 -0600 Subject: [PATCH] Clean up ScrollBar a bit --- src/widgets.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/widgets.rs b/src/widgets.rs index 2797c64..d577bff 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -253,7 +253,7 @@ impl ScrollBar { } } - pub fn body_rect(&self) -> Rect { + pub fn get_body_rect(&self) -> Rect { let style = &self.style; let rail_height = self.rail_rect.height(); let body_height = (self.height / self.content_height) * rail_height; @@ -262,6 +262,10 @@ impl ScrollBar { let body_size = Vec2::new(style.body_width, body_height); Rect::from_xy_size(body_xy, body_size) } + + pub fn get_scroll(&self) -> f32 { + self.scroll + } } impl Widget for ScrollBar { @@ -271,13 +275,13 @@ impl Widget for ScrollBar { fn draw(&mut self, ctx: &DrawContext) { let style = &self.style; - let body_rect = self.body_rect(); + let body_rect = self.get_body_rect(); ctx.draw_rect(self.rail_rect, style.rail_color); ctx.draw_rounded_rect(body_rect, style.body_radius, self.body_color_anim.get()); } fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) { - let is_on = self.body_rect().contains_point(at); + let is_on = self.get_body_rect().contains_point(at); match kind { CursorEventKind::Hover | CursorEventKind::Drag => {