-
|
I need a widget to display runtime log which support auto scroll to bottom when new log string is added. Ideally, TextEdit or ScrollView+Text might have some function like "Scroll To XY", I could invoke it to control the scroll position programable, but I didn't find any clue from document and examples. Any hint? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
|
That's a feature that make sense. I wonder what API it should have. Right now, you will have to set the content-y manually to go to the end like so: |
Beta Was this translation helpful? Give feedback.
-
|
Are there any plans for an out-of-the-box autoscroll feature? I currently have to manually implement a scroll-to-bottom function like @ogoffart suggested and manually invoke it from the backend code every time I want to add a new output line to a |
Beta Was this translation helpful? Give feedback.
-
|
Hi! I was looking at this pattern for a chat app, starting from the timer-based polling shape upthread, and ran into the harder version of the problem: how to keep auto-scroll-to-bottom when the user is allowed to scroll up at any time. The trick I found was to stop trying to tell "user scroll" apart from "layout shift". The observation: the only direction layout-induced motion can move That collapses the whole thing to a three-rule state machine on a polling Timer:
Packaged as a reusable component: export component StickyBottomList inherits Rectangle {
in property <length> up_tolerance: 0px;
in property <length> bottom_margin: 16px;
in property <duration> poll_interval: 100ms;
out property <bool> sticky_to_bottom: true;
out property <bool> has_unseen_growth: false;
public function snap_to_bottom() { /* set sticky, write vp-y, clear */ }
private property <length> prev_vp_y: 0;
private property <length> prev_vp_h: 0;
listview := Flickable {
VerticalLayout { @children }
}
Timer {
interval: root.poll_interval;
running: true;
triggered => {
if (listview.viewport-y > prev_vp_y + root.up_tolerance) {
sticky_to_bottom = false;
}
if (listview.viewport-y
<= (listview.height - listview.viewport-height) + root.bottom_margin) {
sticky_to_bottom = true;
has_unseen_growth = false;
}
if (listview.viewport-height > prev_vp_h) {
if (sticky_to_bottom) {
listview.viewport-y = listview.height - listview.viewport-height;
} else {
has_unseen_growth = true;
}
}
prev_vp_y = listview.viewport-y;
prev_vp_h = listview.viewport-height;
}
}
}The |
Beta Was this translation helpful? Give feedback.
-
|
any updates on this? |
Beta Was this translation helpful? Give feedback.
That's a feature that make sense. I wonder what API it should have.
Right now, you will have to set the content-y manually to go to the end like so:
Full example