scrolling fixed in immediate mode
This commit is contained in:
23
FlexLove.lua
23
FlexLove.lua
@@ -178,7 +178,15 @@ function Gui.endFrame()
|
|||||||
-- Sort elements by z-index for occlusion detection
|
-- Sort elements by z-index for occlusion detection
|
||||||
GuiState.sortElementsByZIndex()
|
GuiState.sortElementsByZIndex()
|
||||||
|
|
||||||
-- Auto-update all top-level elements (triggers layout calculation and overflow detection)
|
-- Layout all top-level elements now that all children have been added
|
||||||
|
-- This ensures overflow detection happens with complete child lists
|
||||||
|
for _, element in ipairs(Gui._currentFrameElements) do
|
||||||
|
if not element.parent then
|
||||||
|
element:layoutChildren() -- Layout with all children present
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Auto-update all top-level elements (triggers additional state updates)
|
||||||
-- This must happen BEFORE saving state so that scroll positions and overflow are calculated
|
-- This must happen BEFORE saving state so that scroll positions and overflow are calculated
|
||||||
for _, element in ipairs(Gui._currentFrameElements) do
|
for _, element in ipairs(Gui._currentFrameElements) do
|
||||||
-- Only update top-level elements (those without parents in the current frame)
|
-- Only update top-level elements (those without parents in the current frame)
|
||||||
@@ -583,6 +591,11 @@ function Gui.new(props)
|
|||||||
-- Mark state as used this frame
|
-- Mark state as used this frame
|
||||||
StateManager.markStateUsed(props.id)
|
StateManager.markStateUsed(props.id)
|
||||||
|
|
||||||
|
-- Inject scroll state into props BEFORE creating element
|
||||||
|
-- This ensures scroll position is set before layoutChildren/detectOverflow is called
|
||||||
|
props._scrollX = state._scrollX or 0
|
||||||
|
props._scrollY = state._scrollY or 0
|
||||||
|
|
||||||
-- Create the element
|
-- Create the element
|
||||||
local element = Element.new(props)
|
local element = Element.new(props)
|
||||||
|
|
||||||
@@ -602,11 +615,11 @@ function Gui.new(props)
|
|||||||
element._selectionStart = state._selectionStart
|
element._selectionStart = state._selectionStart
|
||||||
element._selectionEnd = state._selectionEnd
|
element._selectionEnd = state._selectionEnd
|
||||||
element._textBuffer = state._textBuffer or element.text or ""
|
element._textBuffer = state._textBuffer or element.text or ""
|
||||||
element._scrollX = state._scrollX or element._scrollX or 0
|
-- Note: scroll position already set from props during Element.new()
|
||||||
element._scrollY = state._scrollY or element._scrollY or 0
|
-- element._scrollX and element._scrollY already restored
|
||||||
element._scrollbarDragging = state._scrollbarDragging or false
|
element._scrollbarDragging = state._scrollbarDragging ~= nil and state._scrollbarDragging or false
|
||||||
element._hoveredScrollbar = state._hoveredScrollbar
|
element._hoveredScrollbar = state._hoveredScrollbar
|
||||||
element._scrollbarDragOffset = state._scrollbarDragOffset or 0
|
element._scrollbarDragOffset = state._scrollbarDragOffset ~= nil and state._scrollbarDragOffset or 0
|
||||||
|
|
||||||
-- Bind element to StateManager for interactive states
|
-- Bind element to StateManager for interactive states
|
||||||
-- Use the same ID for StateManager so state persists across frames
|
-- Use the same ID for StateManager so state persists across frames
|
||||||
|
|||||||
@@ -1165,9 +1165,9 @@ function Element.new(props)
|
|||||||
self._contentWidth = 0
|
self._contentWidth = 0
|
||||||
self._contentHeight = 0
|
self._contentHeight = 0
|
||||||
|
|
||||||
-- Scroll state
|
-- Scroll state (can be restored from props in immediate mode)
|
||||||
self._scrollX = 0
|
self._scrollX = props._scrollX or 0
|
||||||
self._scrollY = 0
|
self._scrollY = props._scrollY or 0
|
||||||
self._maxScrollX = 0
|
self._maxScrollX = 0
|
||||||
self._maxScrollY = 0
|
self._maxScrollY = 0
|
||||||
|
|
||||||
@@ -1928,8 +1928,12 @@ function Element:addChild(child)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- In immediate mode, defer layout until endFrame() when all elements are created
|
||||||
|
-- This prevents premature overflow detection with incomplete children
|
||||||
|
if not Gui._immediateMode then
|
||||||
self:layoutChildren()
|
self:layoutChildren()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Apply positioning offsets (top, right, bottom, left) to an element
|
--- Apply positioning offsets (top, right, bottom, left) to an element
|
||||||
-- @param element The element to apply offsets to
|
-- @param element The element to apply offsets to
|
||||||
|
|||||||
Reference in New Issue
Block a user