Clean up ScrollBar a bit
This commit is contained in:
parent
9d83792ef7
commit
343905811c
|
@ -253,7 +253,7 @@ impl ScrollBar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn body_rect(&self) -> Rect {
|
pub fn get_body_rect(&self) -> Rect {
|
||||||
let style = &self.style;
|
let style = &self.style;
|
||||||
let rail_height = self.rail_rect.height();
|
let rail_height = self.rail_rect.height();
|
||||||
let body_height = (self.height / self.content_height) * rail_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);
|
let body_size = Vec2::new(style.body_width, body_height);
|
||||||
Rect::from_xy_size(body_xy, body_size)
|
Rect::from_xy_size(body_xy, body_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_scroll(&self) -> f32 {
|
||||||
|
self.scroll
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for ScrollBar {
|
impl Widget for ScrollBar {
|
||||||
|
@ -271,13 +275,13 @@ impl Widget for ScrollBar {
|
||||||
|
|
||||||
fn draw(&mut self, ctx: &DrawContext) {
|
fn draw(&mut self, ctx: &DrawContext) {
|
||||||
let style = &self.style;
|
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_rect(self.rail_rect, style.rail_color);
|
||||||
ctx.draw_rounded_rect(body_rect, style.body_radius, self.body_color_anim.get());
|
ctx.draw_rounded_rect(body_rect, style.body_radius, self.body_color_anim.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
|
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 {
|
match kind {
|
||||||
CursorEventKind::Hover | CursorEventKind::Drag => {
|
CursorEventKind::Hover | CursorEventKind::Drag => {
|
||||||
|
|
Loading…
Reference in New Issue