Fix rendering of horizontal scrollbar, related to #59

This commit is contained in:
Jeremy Soller 2024-05-30 15:52:53 -06:00
parent 55e89579ad
commit fe280423b8
No known key found for this signature in database
GPG key ID: D02FD439211AF56F

View file

@ -622,17 +622,17 @@ where
); );
state.scrollbar_v_rect.set(rect); state.scrollbar_v_rect.set(rect);
if (image_w as f32) < max_line_width { let (buffer_w, buffer_h) = buffer.size();
let scrollbar_h_width = image_w as f32 / scale_factor - scrollbar_w as f32;
if buffer_w < max_line_width {
let rect = Rectangle::new( let rect = Rectangle::new(
[ [
(scroll_x as f32 / max_line_width as f32) * image_w as f32 (buffer.scroll().horizontal / max_line_width) * scrollbar_h_width,
/ scale_factor, buffer_h / scale_factor - scrollbar_w as f32,
image_h as f32 / scale_factor - scrollbar_w as f32,
] ]
.into(), .into(),
Size::new( Size::new(
(image_w as f32 / max_line_width as f32) * image_w as f32 (buffer_w / max_line_width) * scrollbar_h_width,
/ scale_factor,
scrollbar_w as f32, scrollbar_w as f32,
), ),
); );
@ -765,6 +765,7 @@ where
// Draw horizontal scrollbar // Draw horizontal scrollbar
//TODO: reduce repitition //TODO: reduce repitition
if let Some(scrollbar_h_rect) = state.scrollbar_h_rect.get() { if let Some(scrollbar_h_rect) = state.scrollbar_h_rect.get() {
/*TODO: horizontal scrollbar track?
// neutral_3, 0.7 // neutral_3, 0.7
let track_color = cosmic_theme let track_color = cosmic_theme
.palette .palette
@ -777,7 +778,10 @@ where
Quad { Quad {
bounds: Rectangle::new( bounds: Rectangle::new(
Point::new(image_position.x, image_position.y + scrollbar_h_rect.y), Point::new(image_position.x, image_position.y + scrollbar_h_rect.y),
Size::new(layout.bounds().width, scrollbar_h_rect.height), Size::new(
layout.bounds().width - scrollbar_w as f32,
scrollbar_h_rect.height,
),
), ),
border: Border { border: Border {
radius: (scrollbar_h_rect.height / 2.0).into(), radius: (scrollbar_h_rect.height / 2.0).into(),
@ -788,6 +792,7 @@ where
}, },
Color::from(track_color), Color::from(track_color),
); );
*/
let pressed = matches!(&state.dragging, Some(Dragging::ScrollbarH { .. })); let pressed = matches!(&state.dragging, Some(Dragging::ScrollbarH { .. }));