@@ -601,8 +601,8 @@ export onKeyPressed :: (state:State, key:LK.KeyConstant, scancode:LK.Scancode, i
601601 local found, i = indexWith(buttons.buttons, "selected", true)
602602
603603 i = found
604- ? ((i-1+dir) % #buttons.buttons + 1)
605- : (dir < 0 ? #buttons.buttons : 1)
604+ ? math.clamp(i+dir, 1, #buttons.buttons)-- ((i-1+dir) % #buttons.buttons + 1)
605+ : 1-- (dir < 0 ? #buttons.buttons : 1)
606606
607607 local anyChange = false
608608
@@ -3825,15 +3825,54 @@ export scrollTo :: (state:State, scrollable:Scrollable, scroll:int, limit=false)
38253825 scrollTo(scrollable, scroll, limit)
38263826}
38273827
3828+ export scrollIntoView :: (state:State, el:Element, subid:int) {
3829+ updateLayoutIfNeeded(state)
38283830
3831+ local scrollCurrent = getScrollOffset(el)
3832+ local targetY1 = el.layoutY + scrollCurrent
3833+ local targetY2 = targetY1 + el.layoutHeight
38293834
3830- export scrollIntoView :: (state:State, el:Element, subid:int) {
3831- -- @Incomplete
3835+ if el.type == Buttons {
3836+ local buttons = cast(Buttons) el
3837+ if buttons.vertical {
3838+ targetY2 = math.round(targetY1+(subid )*buttons.buttonHeight) -- Note: We change targetY1 on the next line!
3839+ targetY1 = math.round(targetY1+(subid-1)*buttons.buttonHeight)
3840+ }
3841+ }
3842+
3843+ while true {
3844+ el = el.parent
3845+ if el == NULL break
3846+
3847+ if el.type == Scrollable {
3848+ local scrollable = cast(Scrollable) el
3849+ local scrollOld = scrollable.scrollTarget
3850+ scrollCurrent = scrollCurrent - scrollOld
3851+
3852+ local scrollDelta = 0
3853+ local y1 = scrollable.layoutY + scrollCurrent + (SCROLLABLE_PADDING + SPACING) -- @UX: The top of the target element is partially behind the scrollable's shadow. Not great!
3854+ local y2 = scrollable.layoutY + scrollCurrent + scrollable.layoutHeight - (SCROLLABLE_PADDING + SPACING)
3855+
3856+ if targetY2 > y2 scrollDelta = y2 - targetY2
3857+ if targetY1 < y1 scrollDelta = y1 - targetY1
3858+
3859+ if scrollDelta {
3860+ scrollTo(scrollable, scrollable.scrollTarget+scrollDelta, limit=true)
3861+ scrollDelta = scrollable.scrollTarget - scrollOld
3862+
3863+ scrollCurrent = scrollCurrent + scrollDelta
3864+ targetY1 = targetY1 + scrollDelta
3865+ targetY2 = targetY2 + scrollDelta
3866+ }
3867+ }
3868+ }
38323869}
38333870
38343871
38353872
38363873local getVisibleAreaInLocalSpace :: (state:State, el0:Element) -> (x,y,w,h:int) {
3874+ updateLayoutIfNeeded(state)
3875+
38373876 -- @Incomplete: Check isElementVisible().
38383877 local el = el0
38393878 local x1 = el.layoutX
@@ -3852,7 +3891,7 @@ local getVisibleAreaInLocalSpace :: (state:State, el0:Element) -> (x,y,w,h:int)
38523891 y1 = math.max(y1, scrollable.layoutY)
38533892 x2 = math.min(x2, scrollable.layoutX+scrollable.layoutWidth)
38543893 y2 = math.min(y2, scrollable.layoutY+scrollable.layoutHeight)
3855- offset += math.round( scrollable.scroll)
3894+ offset += scrollable.scrollTarget
38563895 }
38573896 }
38583897
0 commit comments