Skip to content

Commit 9f3bc1e

Browse files
committed
nuon: Scroll rendering fixes
1 parent c46fa2b commit 9f3bc1e

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

nuon/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,24 @@ impl Scroll {
393393
}
394394

395395
pub fn build(&self, ui: &mut Ui, build: impl FnOnce(&mut Ui)) {
396+
// ┌► ┌─────┐ ◄┐
397+
// │ │~~~~~│ │ visible_h
398+
// │ │~~~ │ │
399+
// full │ ├─────┤ ◄┘
400+
// │ │~~~ │
401+
// │ │~~~~~│
402+
// └► └─────┘
403+
396404
self::layer().scissor_rect(self.rect).build(ui, |ui| {
397405
let last = self::translate().y(-self.scroll).build(ui, build);
398-
let last_y = last.y - self.rect.size.height;
399406

400-
let percentage = self.scroll / last_y;
407+
let visible_h = self.rect.size.height;
408+
let full_h = last.y;
409+
410+
let mult = visible_h / full_h;
411+
let h = visible_h * mult;
401412

402413
let w = 10.0;
403-
let h = self.rect.height() / (last_y / self.rect.height());
404414

405415
self::quad()
406416
.y(0.0)
@@ -410,7 +420,7 @@ impl Scroll {
410420
.border_radius([5.0; 4])
411421
.build(ui);
412422
self::quad()
413-
.y(percentage * (self.rect.size.height - h))
423+
.y(self.scroll * mult)
414424
.x(self.rect.size.width - w)
415425
.size(w, h)
416426
.color([74, 68, 88])

0 commit comments

Comments
 (0)