fidget
fidget copied to clipboard
[Question] Scroll
Could you post an example about the proper way to do scrolling?
Regards, José María
Yes I need to an an example that has scrolling.
Here is my approach for opengl backend:
## This minimal example shows 5 blue squares in a scroll box
import fidget
var scrollX = 0
var scrollSpeed = 4
proc drawMain() =
frame "main":
box 0, 0, 620, 140
fill "#000"
frame "scrollBox":
box 100, 0, 300, 140
clipContent true
fill "#FFF"
onHover:
scrollX += (int mouse.wheelDelta) * scrollSpeed
frame "scrollContent":
box scrollX, 0, 300, 140
for i in 0 .. 4:
group "block":
box 20 + i * 120, 20, 100, 100
fill "#2B9FEA"
startFidget(drawMain, w = 620, h = 140)
What do you think?
EDIT: it could also be nice if nodes outside of the view are not drawn:
## This minimal example shows 5 blue squares in a scroll box
import fidget, vmath
var scrollX = 0
var scrollSpeed = 4
proc drawMain() =
frame "main":
box 0, 0, 620, 140
fill "#000"
frame "scrollBox":
box 100, 0, 300, 140
clipContent true
fill "#FFF"
onHover:
scrollX += (int mouse.wheelDelta) * scrollSpeed
frame "scrollContent":
box scrollX, 0, 300, 140
var viewBox = rect(float -scrollX, 0, 300, 140)
for i in 0 .. 4:
var blockBox = rect(20 + (float i) * 120, 20, 100, 100)
if viewBox.overlap(blockBox):
group "block" & $i:
box blockBox
fill "#2B9FEA"
startFidget(drawMain, w = 620, h = 140)
Yeah that should work. I want to get scrolling working natively though. Doing some thing like scrollable true should just make the bigger child scroll inside the smaller parent.
I see 3 issues with this code wunning on a Linux desktop:
- no scrollbars, no way to discover the scroll
- mouse wheel scroll is way too slow. Generally a scroll event moves more than that, but it depends on the mouse of course
- touch events should be able to make that scroll too.