Scroll fixes

This commit is contained in:
Jonathan Johnson 2023-11-11 10:23:24 -08:00
parent eb4b24f4a9
commit 68339dfb62
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
3 changed files with 6 additions and 12 deletions

View file

@ -46,6 +46,7 @@ fn main() -> gooey::Result {
Lp::points(300)..Lp::points(600), Lp::points(300)..Lp::points(600),
Stack::rows(username_row.and(password_row).and(buttons)), Stack::rows(username_row.and(password_row).and(buttons)),
) )
.scroll()
.centered() .centered()
.expand() .expand()
.run() .run()

View file

@ -5,5 +5,6 @@ use gooey::Run;
fn main() -> gooey::Result { fn main() -> gooey::Result {
Label::new(include_str!("../src/widgets/scroll.rs")) Label::new(include_str!("../src/widgets/scroll.rs"))
.scroll() .scroll()
.expand()
.run() .run()
} }

View file

@ -126,22 +126,17 @@ impl Widget for Scroll {
fn redraw(&mut self, context: &mut crate::context::GraphicsContext<'_, '_, '_, '_, '_>) { fn redraw(&mut self, context: &mut crate::context::GraphicsContext<'_, '_, '_, '_, '_>) {
context.redraw_when_changed(&self.scrollbar_opacity); context.redraw_when_changed(&self.scrollbar_opacity);
let Some(visible_rect) = context.gfx.visible_rect() else {
return;
};
let visible_bottom_right = visible_rect.into_signed().extent();
let managed = self.contents.mounted(&mut context.as_event_context()); let managed = self.contents.mounted(&mut context.as_event_context());
context.for_other(&managed).redraw(); context.for_other(&managed).redraw();
let size = context.gfx.region().size;
if self.horizontal_bar.amount_hidden > 0 { if self.horizontal_bar.amount_hidden > 0 {
context.gfx.draw_shape( context.gfx.draw_shape(
&Shape::filled_rect( &Shape::filled_rect(
Rect::new( Rect::new(
Point::new( Point::new(self.horizontal_bar.offset, size.height - self.bar_width),
self.horizontal_bar.offset,
self.control_size.height - self.bar_width,
),
Size::new(self.horizontal_bar.size, self.bar_width), Size::new(self.horizontal_bar.size, self.bar_width),
), ),
Color::new_f32(1.0, 1.0, 1.0, *self.scrollbar_opacity.get()), Color::new_f32(1.0, 1.0, 1.0, *self.scrollbar_opacity.get()),
@ -156,10 +151,7 @@ impl Widget for Scroll {
context.gfx.draw_shape( context.gfx.draw_shape(
&Shape::filled_rect( &Shape::filled_rect(
Rect::new( Rect::new(
Point::new( Point::new(size.width - self.bar_width, self.vertical_bar.offset),
visible_bottom_right.x - self.bar_width,
self.vertical_bar.offset,
),
Size::new(self.bar_width, self.vertical_bar.size), Size::new(self.bar_width, self.vertical_bar.size),
), ),
Color::new_f32(1.0, 1.0, 1.0, *self.scrollbar_opacity.get()), Color::new_f32(1.0, 1.0, 1.0, *self.scrollbar_opacity.get()),