LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

ScrollingLayoutElement

Description
Box layout that supports smooth scrolling
Parent
BoxLayoutElement
Functions

addElement

Description
Update content size when an element is added
Definition
addElement()
Code
177function ScrollingLayoutElement:addElement(element)
178 ScrollingLayoutElement:superClass().addElement(self, element)
179
180 if self.autoValidateLayout then
181 self:invalidateLayout()
182 end
183end

copyAttributes

Description
Definition
copyAttributes()
Code
43function ScrollingLayoutElement:copyAttributes(src)
44 ScrollingLayoutElement:superClass().copyAttributes(self, src)
45
46 self.topClipperElementName = src.topClipperElementName
47 self.bottomClipperElementName = src.bottomClipperElementName
48end

invalidateLayout

Description
Rebuild the layout. Adjusts start Y with our visible Y
Definition
invalidateLayout()
Code
69function ScrollingLayoutElement:invalidateLayout(ignoreVisibility)
70 local cells = self:getLayoutCells(ignoreVisibility)
71
72 local lateralFlowSizes, totalLateralSize, flowSize = self:getLayoutSizes(cells)
73 local offsetStartX, offsetStartY, xDir, yDir = self:getAlignmentOffset(flowSize, totalLateralSize)
74
75 offsetStartY = offsetStartY + self.firstVisibleY
76
77 self:applyCellPositions(cells, offsetStartX, offsetStartY, xDir, yDir, lateralFlowSizes)
78
79 if self.handleFocus and self.focusDirection ~= BoxLayoutElement.FLOW_NONE then
80 self:focusLinkCells(cells)
81 end
82
83 self:updateContentSize()
84 self:updateScrollClippers()
85
86 for _, e in pairs(self.elements) do
87 self:addFocusListener(e)
88 end
89
90 return flowSize
91end

loadFromXML

Description
Definition
loadFromXML()
Code
34function ScrollingLayoutElement:loadFromXML(xmlFile, key)
35 ScrollingLayoutElement:superClass().loadFromXML(self, xmlFile, key)
36
37 self.topClipperElementName = getXMLString(xmlFile, key.."#topClipperElementName")
38 self.bottomClipperElementName = getXMLString(xmlFile, key.."#bottomClipperElementName")
39end

new

Description
Definition
new()
Code
15function ScrollingLayoutElement.new(target, custom_mt)
16 local self = BoxLayoutElement.new(target, custom_mt or ScrollingLayoutElement_mt)
17
18 self.alignmentX = BoxLayoutElement.ALIGN_LEFT
19 self.alignmentY = BoxLayoutElement.ALIGN_TOP
20 self.clipping = true
21 self.wrapAround = true -- needed for focus handling when scrolling
22
23 self.sliderElement = nil -- sliders register themselves with lists in this field if they point at them via configuration
24
25 self.firstVisibleY = 0
26 self.targetFirstVisibleY = 0
27 self.contentSize = 1 -- height only for now
28
29 return self
30end

onGuiSetupFinished

Description
Definition
onGuiSetupFinished()
Code
52function ScrollingLayoutElement:onGuiSetupFinished()
53 ScrollingLayoutElement:superClass().onGuiSetupFinished(self)
54
55 if self.topClipperElementName ~= nil then
56 self.topClipperElement = self.parent:getDescendantByName(self.topClipperElementName)
57 end
58 if self.bottomClipperElementName ~= nil then
59 self.bottomClipperElement = self.parent:getDescendantByName(self.bottomClipperElementName)
60 end
61
62 for _, e in pairs(self.elements) do
63 self:addFocusListener(e)
64 end
65end

onSliderValueChanged

Description
Definition
onSliderValueChanged()
Code
107function ScrollingLayoutElement:onSliderValueChanged(slider, newValue)
108 local newStartY = 0
109 if slider.minValue ~= slider.maxValue then
110 newStartY = ((self.contentSize - self.absSize[2]) / (slider.maxValue - slider.minValue)) * (newValue - slider.minValue)
111 end
112
113 self:scrollTo(newStartY, false)
114end

onVerticalCursorInput

Description
Event function for vertical cursor input bound to InputAction.MENU_AXIS_UP_DOWN_SECONDARY.
Definition
onVerticalCursorInput()
Code
288function ScrollingLayoutElement:onVerticalCursorInput(_, inputValue)
289 if not self.useMouse then
290 self.sliderElement:setValue(self.sliderElement.currentValue + self.sliderElement.stepSize * inputValue)
291 end
292 self.useMouse = false
293end

raiseSliderUpdateEvent

Description
Definition
raiseSliderUpdateEvent()
Code
169function ScrollingLayoutElement:raiseSliderUpdateEvent()
170 if self.sliderElement ~= nil then
171 self.sliderElement:onBindUpdate(self)
172 end
173end

removeActionEvents

Description
Remove non-GUI input action events.
Definition
removeActionEvents()
Code
282function ScrollingLayoutElement:removeActionEvents()
283 g_inputBinding:removeActionEventsByTarget(self)
284end

removeElement

Description
Update content size when an element is removed
Definition
removeElement()
Code
200function ScrollingLayoutElement:removeElement(element)
201 ScrollingLayoutElement:superClass().removeElement(self, element)
202
203 if element.scrollingFocusEnter_orig == nil then
204 element.onFocusEnter = element.scrollingFocusEnter_orig
205 end
206
207 if self.autoValidateLayout then
208 self:invalidateLayout()
209 end
210end

scrollTo

Description
Scroll to an Y position within the content
Definition
scrollTo()
Code
118function ScrollingLayoutElement:scrollTo(startY, updateSlider, noUpdateTarget)
119 self.firstVisibleY = startY
120
121 if not noUpdateTarget then
122 self.targetFirstVisibleY = startY
123 self.isMovingToTarget = false
124 end
125
126 self:invalidateLayout()
127
128 -- update scrolling
129 if updateSlider == nil or updateSlider then
130 if self.sliderElement ~= nil then
131 local newValue = startY / ((self.contentSize - self.absSize[2]) / self.sliderElement.maxValue)
132 self.sliderElement:setValue(newValue, true)
133 end
134 end
135
136 self:raiseCallback("onScrollCallback")
137end