LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

BoxLayoutElement

Description
Layout element which lays out child elements in regular rows or columns. Exceptions are elements whose "layoutIgnore" property is true. Used layers: "image" for a background image.
Parent
BitmapElement
XML Configuration Parameters
GuiElement#alignmentXstring [optional] Horizontal alignment of the layout, defaults to "left". Valid values are "left", "right" and "center".
GuiElement#alignmentYstring [optional] Vertical alignment of the layout, defaults to "top". Valid values are "top", "bottom" and "middle".
GuiElement#flowDirectionstring [optional] Flow direction of the layout, defaults to "vertical". A vertical layout is column-based while a horizontal one is row-based. Valid values are "vertical" and "horizontal".
GuiElement#focusDirectionstring [optional] If set, overrides focus input to use the given direction instead. Defaults to the flow direction. This may be required for layouts which contain elements that handle input in the flow direction, e.g. MultiOptionElements. Valid values are "vertical", "horizontal" or "none" for no focus linking.
GuiElement#numFlowsint [optional] Number of rows or columns depending on the flow direction, defaults to 1.
GuiElement#lateralFlowSizestring [optional] Pixel size of row height or column width in reference resolution. Format: "[size]px"
GuiElement#flowMarginstring [optional] Pixel sizes of margin around rows or columns in reference resolution. Format: see GuiElement#margin
GuiElement#fitFlowToElementsbool [optional] If true, will ignore #lateralFlowSize and use the size of the largest element per row or column instead.
GuiElement#autoValidateLayoutbool [optional] If true, will re-layout each time after adding or removing a new element.
GuiElement#wrapAroundbool [optional] If true, will make focus navigation on child elements wrap around within the layout. Use this only for top-level layouts like the main menu.
GuiElement#rememberLastFocusbool [optional] If true, remembers the last focused child element when the layout box loses focus and reactivates that element when focus is reacquired. Otherwise, default focus navigation logic is used.

Functions

addElement

Description
Definition
addElement()
Code
231function BoxLayoutElement:addElement(element)
232 BoxLayoutElement:superClass().addElement(self, element)
233 if self.autoValidateLayout then
234 self:invalidateLayout()
235 end
236end

canReceiveFocus

Description
Definition
canReceiveFocus()
Code
619function BoxLayoutElement:canReceiveFocus()
620 -- element can receive focus if any sub elements are ready to receive focus
621 if self.handleFocus then
622 for _, v in ipairs(self.elements) do
623 if (v:canReceiveFocus()) then
624 return true
625 end
626 end
627 end
628 return false
629end

copyAttributes

Description
Definition
copyAttributes()
Code
198function BoxLayoutElement:copyAttributes(src)
199 BoxLayoutElement:superClass().copyAttributes(self, src)
200
201 self.alignmentX = src.alignmentX
202 self.alignmentY = src.alignmentY
203 self.autoValidateLayout = src.autoValidateLayout
204 self.useFullVisibility = src.useFullVisibility
205
206 self.layoutToleranceX, self.layoutToleranceY = src.layoutToleranceX, src.layoutToleranceY
207
208 self.flowDirection = src.flowDirection
209 self.focusDirection = src.focusDirection
210 self.numFlows = src.numFlows
211 self.lateralFlowSize = src.lateralFlowSize
212 self.flowMargin = src.flowMargin
213 self.fitFlowToElements = src.fitFlowToElements
214
215 self.wrapAround = src.wrapAround
216 self.rememberLastFocus = src.rememberLastFocus
217end

getIsElementIncluded

Description
Definition
getIsElementIncluded()
Code
249function BoxLayoutElement:getIsElementIncluded(element, ignoreVisibility)
250 return not element.ignoreLayout and ignoreVisibility or (element:getIsVisibleNonRec() and self.useFullVisibility) or (element.visible and not self.useFullVisibility)
251end

loadFromXML

Description
Definition
loadFromXML()
Code
104function BoxLayoutElement:loadFromXML(xmlFile, key)
105 BoxLayoutElement:superClass().loadFromXML(self, xmlFile, key)
106
107 local alignmentX = getXMLString(xmlFile, key.."#alignmentX")
108 if alignmentX ~= nil then
109 alignmentX = alignmentX:lower()
110 if alignmentX == "right" then
111 self.alignmentX = BoxLayoutElement.ALIGN_RIGHT
112 elseif alignmentX == "center" then
113 self.alignmentX = BoxLayoutElement.ALIGN_CENTER
114 else
115 self.alignmentX = BoxLayoutElement.ALIGN_LEFT
116 end
117 end
118
119 local alignmentY = getXMLString(xmlFile, key.."#alignmentY")
120 if alignmentY ~= nil then
121 alignmentY = alignmentY:lower()
122 if alignmentY == "bottom" then
123 self.alignmentY = BoxLayoutElement.ALIGN_BOTTOM
124 elseif alignmentY == "middle" then
125 self.alignmentY = BoxLayoutElement.ALIGN_MIDDLE
126 else
127 self.alignmentY = BoxLayoutElement.ALIGN_TOP
128 end
129 end
130
131 self.flowDirection = Utils.getNoNil(getXMLString(xmlFile, key.."#flowDirection"), self.flowDirection)
132 self.focusDirection = getXMLString(xmlFile, key.."#focusDirection") or self.flowDirection -- use flow direction as default
133
134 self.numFlows = Utils.getNoNil(tonumber(getXMLString(xmlFile, key.."#numFlows")), self.numFlows)
135 self.lateralFlowSize = Utils.getNoNil(GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#lateralFlowSize"), self.outputSize, {self.lateralFlowSize})[1], self.lateralFlowSize)
136 self.flowMargin = GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#flowMargin"), self.outputSize, self.flowMargin)
137 self.fitFlowToElements = Utils.getNoNil(getXMLBool(xmlFile, key.."#fitFlowToElements"), self.fitFlowToElements)
138
139 self.autoValidateLayout = Utils.getNoNil(getXMLBool(xmlFile, key.."#autoValidateLayout"), self.autoValidateLayout)
140 self.useFullVisibility = Utils.getNoNil(getXMLBool(xmlFile, key.."#useFullVisibility"), self.useFullVisibility)
141
142 self.wrapAround = Utils.getNoNil(getXMLBool(xmlFile, key.."#wrapAround"), self.wrapAround)
143 self.rememberLastFocus = Utils.getNoNil(getXMLBool(xmlFile, key.."#rememberLastFocus"), self.rememberLastFocus)
144end

loadProfile

Description
Definition
loadProfile()
Code
148function BoxLayoutElement:loadProfile(profile, applyProfile)
149 BoxLayoutElement:superClass().loadProfile(self, profile, applyProfile)
150
151 local alignmentX = profile:getValue("alignmentX")
152 if alignmentX ~= nil then
153 alignmentX = alignmentX:lower()
154 if alignmentX == "right" then
155 self.alignmentX = BoxLayoutElement.ALIGN_RIGHT
156 elseif alignmentX == "center" then
157 self.alignmentX = BoxLayoutElement.ALIGN_CENTER
158 else
159 self.alignmentX = BoxLayoutElement.ALIGN_LEFT
160 end
161 end
162
163 local alignmentY = profile:getValue("alignmentY")
164 if alignmentY ~= nil then
165 alignmentY = alignmentY:lower()
166 if alignmentY == "bottom" then
167 self.alignmentY = BoxLayoutElement.ALIGN_BOTTOM
168 elseif alignmentY == "middle" then
169 self.alignmentY = BoxLayoutElement.ALIGN_MIDDLE
170 else
171 self.alignmentY = BoxLayoutElement.ALIGN_TOP
172 end
173 end
174
175 local autoValidateLayout = profile:getBool("autoValidateLayout")
176 if autoValidateLayout ~= nil then
177 self.autoValidateLayout = autoValidateLayout
178 end
179 local useFullVisibility = profile:getBool("useFullVisibility")
180 if useFullVisibility ~= nil then
181 self.useFullVisibility = useFullVisibility
182 end
183
184 self.flowDirection = Utils.getNoNil(profile:getValue("flowDirection"), self.flowDirection)
185 self.focusDirection = profile:getValue("focusDirection") or self.flowDirection
186 self.numFlows = profile:getNumber("numFlows", self.numFlows)
187
188 self.lateralFlowSize = GuiUtils.getNormalizedValues(profile:getValue("lateralFlowSize", "0px"), self.outputSize, {self.lateralFlowSize})[1]
189 self.flowMargin = GuiUtils.getNormalizedValues(profile:getValue("flowMargin", "0px 0px 0px 0px"), self.outputSize, self.flowMargin)
190 self.fitFlowToElements = profile:getBool("fitFlowToElements", self.fitFlowToElements)
191
192 self.wrapAround = profile:getBool("wrapAround", self.wrapAround)
193 self.rememberLastFocus = profile:getBool("rememberLastFocus", self.rememberLastFocus)
194end

new

Description
Definition
new()
Code
76function BoxLayoutElement.new(target, custom_mt)
77 if custom_mt == nil then
78 custom_mt = BoxLayoutElement_mt
79 end
80 local self = BitmapElement.new(target, custom_mt)
81 self.alignmentX = BoxLayoutElement.ALIGN_LEFT
82 self.alignmentY = BoxLayoutElement.ALIGN_TOP
83
84 self.autoValidateLayout = false
85 self.useFullVisibility = true
86
87 self.wrapAround = false
88 self.flowDirection = BoxLayoutElement.FLOW_VERTICAL
89 self.numFlows = 1 -- number of flows (columns or rows, depending on flow direction)
90 self.lateralFlowSize = 0.5 -- lateral size of flow (column width or row height, depending on flow direction)
91 self.fitFlowToElements = false -- ignore lateral flow size and fit flows to element dimensions
92 self.flowMargin = {0, 0, 0, 0} -- outward offset between flows, no effect at numFlows == 1
93 self.layoutToleranceX, self.layoutToleranceY = 0, 0
94
95 self.rememberLastFocus = false
96 self.lastFocusElement = nil
97 self.incomingFocusTargets = {}
98 self.defaultFocusTarget = nil -- first focusable element of the current layout state
99 return self
100end

onFocusLeave

Description
Definition
onFocusLeave()
Code
674function BoxLayoutElement:onFocusLeave()
675 BoxLayoutElement:superClass().onFocusLeave(self)
676
677 if self.rememberLastFocus then
678 local lastFocus = FocusManager:getFocusedElement()
679 if lastFocus:isChildOf(self) then
680 self.lastFocusElement = lastFocus
681 end
682 end
683end

onGuiSetupFinished

Description
Definition
onGuiSetupFinished()
Code
221function BoxLayoutElement:onGuiSetupFinished()
222 BoxLayoutElement:superClass().onGuiSetupFinished(self)
223 self.layoutToleranceX = BoxLayoutElement.LAYOUT_TOLERANCE / g_screenWidth
224 self.layoutToleranceY = BoxLayoutElement.LAYOUT_TOLERANCE / g_screenHeight
225
226 self:invalidateLayout(false)
227end

removeElement

Description
Definition
removeElement()
Code
240function BoxLayoutElement:removeElement(element)
241 BoxLayoutElement:superClass().removeElement(self, element)
242 if self.autoValidateLayout then
243 self:invalidateLayout()
244 end
245end