:dragnpats: kɜ:ʳ :cydr_a: is a user on cybre.space. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
:dragnpats: kɜ:ʳ :cydr_a: @chr

the hardest unsolved problem in computer science: making a box that always scrolls to the bottom except when you don't want it to

· Web · 2 · 12

@MightyPork im trying to implement it in qml right now and let me tell you,

@MightyPork (i either have to hijack a ScrollView somehow to give it behavior it doesn't have built in, or basically rebuild it from other primitives so that i can do it myself)

(some ui frameworks get out of the way and let you do your ui. qml is not one of them)

@chr well okay i think it's easy in winforms/WPF, this may be different

I'd detect two states (scrolled and not scrolled to the bottom), and autoscroll after a write only if not scrolled up
Of course this assumes it let's you bind to the events and scroll manually :/

@chr @MightyPork np

disclaimer: I have no idea if this is "the right thing", but it's worked for me so far lol

@ninjawedding @MightyPork hmm well i've been trying to do it with a Label and a ScrollView/Flickable+ScrollBar and it hasn't been going terribly well so far. not sure if i can make use of a ListView for this but it's something to try if this doesn't work out

@chr @MightyPork atYEnd is a property of a Flickable, so you can still reuse that.

positionViewAtEnd is a ListView thing, but you can do that with a Flickable by setting its contentY to, uhh, contentHeight - height I think
@chr @MightyPork what that's doing: scrolls to the bottom on model count change, but does it on the next frame. (QML timers don't start triggered and have a minimum granularity of the frame)
@chr @MightyPork oh, I found a note to myself explaining why I threw that in a Timer. maybe I should add it as a comment :P

the ListView's delegate may not have been fully drawn when onCountChanged fires, so doing positionViewAtEnd may use the incorrect Y coordinate. using a Timer delays the repositioning to (at least) the next frame, at which point the last delegate will be visible and the height will be correct

@ninjawedding @chr this sounds like the sort of hacks you do in javascript,

@MightyPork @ninjawedding (qml literally has a javascript interpreter for the light UI logic stuff, so, pretty accurate)

@MightyPork @chr it kinda is, yeah. it's what makes me a bit suspicious of the solution; it's also the only zero-interval Timer I haven't replaced with different code. that said, it's worked so far :P

I would like better hooks into the QML renderer for this kind of thing (right now all the hooks are only available from C++ code) and/or have high-level methods like positionViewAtEnd do The Right Thing internally

@chr I thought it was, "what the fuck is a timezone"

@karyl @chr well, "load the tzinfo database and use it" gets you most of the way there!

@riking @chr USING THIRD PARTY TOOLS IS CHEATING :B (jk of course)

in my day we computed the offset and fucked up the edge cases manually, and we liked it that way

@karyl store the timezone, not the offset! that way you manage transitions (DST...) correctly

@chr Solution: assume nobody ever wants it to.