fidget icon indicating copy to clipboard operation
fidget copied to clipboard

[Question] Scroll

Open mantielero opened this issue 5 years ago • 4 comments

Could you post an example about the proper way to do scrolling?

Regards, José María

mantielero avatar Sep 26 '20 11:09 mantielero

Yes I need to an an example that has scrolling.

treeform avatar Sep 26 '20 21:09 treeform

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)

alt-tosc avatar Nov 29 '20 17:11 alt-tosc

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.

treeform avatar Dec 01 '20 18:12 treeform

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.

mildred avatar Jun 18 '21 13:06 mildred