LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

ButtonElement

Description
Clickable button element. Used layers: "image" for the background, "icon" for a button glyph. All button UI callbacks do not require or provide any arguments.
Parent
TextElement
XML Configuration Parameters
GuiElement#iconSizestring [optional] Pixel size of button glyph in reference resolution. Format: "[width]px [height]px"
GuiElement#iconTextOffsetstring [optional] Pixel offset of of icon relative to text position in reference resolution. Format: "[x]px [y]px"
GuiElement#hotspotstring [optional] Pixel offset of the clickable button area borders in reference resolution, defaults to [0, 0, 0, 0]. Format: "[leftOffset]px [topOffset]px [rightOffset]px [bottomOffset]px"
GuiElement#forceFocusbool [optional] If true, focus on this button is not automatically set when it is clicked but must instead be set by code.
GuiElement#forceHighlightbool [optional] If true, highlight on this button is not automatically set on mouse over but must instead be set by code.
GuiElement#needExternalClickbool [optional] If true prevents this button from being "clicked" by being activated when focused. Instead, a direct input activation (e.g. controller button) is required.
GuiElement#inputActionstring [optional] Input action name which triggers this button's click event, defaults to nil.
GuiElement#clickSoundstring [optional] Sound sample name which is played on button activation, defaults to "CLICK". Valid values are defined in GuiSoundPlayer.SOUND_SAMPLES.
GuiElement#fitToContentbool [optional] Fit width of button to fix content
GuiElement#hideKeyboardGlyph[optional] If true, does not draw the keyboard glyphs
GuiElement#fitMarginsstring [optional] Extra margins when fitting
GuiElement#onClickcallback [optional] Called when this button is clicked / activated.
GuiElement#onFocuscallback [optional] Called when this button is focused.
GuiElement#onLeavecallback [optional] Called when this button loses focus.
GuiElement#onHighlightcallback [optional] Called when this button is highlighted.
GuiElement#onHighlightRemovecallback [optional] Called when this button loses highlight.

Functions

applyButtonAspectScale

Description
Definition
applyButtonAspectScale()
Code
233function ButtonElement:applyButtonAspectScale()
234 local xScale, yScale = self:getAspectScale()
235
236 self.iconSize[1] = self.iconSize[1] * xScale
237 self.iconTextOffset[1] = self.iconTextOffset[1] * xScale
238 self.hotspot[1] = self.hotspot[1] * xScale
239 self.hotspot[3] = self.hotspot[3] * xScale
240 self.fitExtraWidth[1] = self.fitExtraWidth[1] * xScale
241
242 self.iconSize[2] = self.iconSize[2] * yScale
243 self.iconTextOffset[2] = self.iconTextOffset[2] * yScale
244 self.hotspot[2] = self.hotspot[2] * yScale
245 self.hotspot[4] = self.hotspot[4] * yScale
246end

applyScreenAlignment

Description
Definition
applyScreenAlignment()
Code
250function ButtonElement:applyScreenAlignment()
251 self:applyButtonAspectScale()
252
253 ButtonElement:superClass().applyScreenAlignment(self)
254end

canReceiveFocus

Description
Definition
canReceiveFocus()
Code
594function ButtonElement:canReceiveFocus()
595 return not (self.disabled or not self:getIsVisible()) and self:getHandleFocus()
596end

copyAttributes

Description
Definition
copyAttributes()
Code
160function ButtonElement:copyAttributes(src)
161 ButtonElement:superClass().copyAttributes(self, src)
162
163 GuiOverlay.copyOverlay(self.overlay, src.overlay)
164 GuiOverlay.copyOverlay(self.icon, src.icon)
165
166 self.iconSize = ListUtil.copyTable(src.iconSize)
167 self.iconTextOffset = ListUtil.copyTable(src.iconTextOffset)
168 self.hotspot = ListUtil.copyTable(src.hotspot)
169 self.forceFocus = src.forceFocus
170 self.forceHighlight = src.forceHighlight
171 self.needExternalClick = src.needExternalClick
172 self.inputActionName = src.inputActionName
173 self.clickSoundName = src.clickSoundName
174 self.hideKeyboardGlyph = src.hideKeyboardGlyph
175 self.fitExtraWidth = src.fitExtraWidth
176 self.fitToContent = src.fitToContent
177
178 self.onClickCallback = src.onClickCallback
179 self.onLeaveCallback = src.onLeaveCallback
180 self.onFocusCallback = src.onFocusCallback
181 self.onHighlightCallback = src.onHighlightCallback
182 self.onHighlightRemoveCallback = src.onHighlightRemoveCallback
183
184 GuiMixin.cloneMixin(PlaySampleMixin, src, self)
185end

delete

Description
Definition
delete()
Code
69function ButtonElement:delete()
70 GuiOverlay.deleteOverlay(self.overlay)
71 GuiOverlay.deleteOverlay(self.icon)
72
73 ButtonElement:superClass().delete(self)
74end

draw

Description
Definition
draw()
Code
471function ButtonElement:draw()
472 self:setKeyboardMode(self.keyDisplayText ~= nil and g_inputBinding:getInputHelpMode() == GS_INPUT_HELP_MODE_KEYBOARD)
473 GuiOverlay.renderOverlay(self.overlay, self.absPosition[1], self.absPosition[2], self.size[1], self.size[2], self:getOverlayState())
474
475 local xPos, yPos = self:getTextPosition(self.text)
476 local textOffsetX, textOffsetY = self:getTextOffset()
477 local xOffset, yOffset = self:getIconOffset(self:getTextWidth(), getTextHeight(self.textSize, self.text))
478
479 local iconXPos = xPos + textOffsetX + xOffset
480 local iconYPos = yPos + textOffsetY + yOffset
481 local iconSizeX, iconSizeY = self:getIconSize() -- includes modifications for key glyph (if necessary)
482 local overlayState = self:getOverlayState()
483
484 if self.keyDisplayText ~= nil and self.isKeyboardMode then
485 if not self.hideKeyboardGlyph then
486 local color = GuiOverlay.getOverlayColor(self.iconColors, overlayState)
487 self.keyOverlay:setColor(unpack(color))
488 self.keyOverlay:renderButton(self.keyDisplayText, iconXPos, iconYPos, iconSizeY, self.textAlignment, overlayState == GuiOverlay.STATE_DISABLED)
489 end
490 else
491 GuiOverlay.renderOverlay(self.icon, iconXPos, iconYPos, iconSizeX, iconSizeY, overlayState)
492 end
493
494 if self.debugEnabled or g_uiDebugEnabled then
495 local xPixel = 1 / g_screenWidth
496 local yPixel = 1 / g_screenHeight
497 setOverlayColor(GuiElement.debugOverlay, 0, 1, 0, 0.7)
498
499 local posX1 = self.absPosition[1]+self.hotspot[1]
500 local posX2 = self.absPosition[1]+self.size[1]+self.hotspot[3]-xPixel
501
502 local posY1 = self.absPosition[2]+self.hotspot[2]
503 local posY2 = self.absPosition[2]+self.size[2]+self.hotspot[4]-yPixel
504
505 renderOverlay(GuiElement.debugOverlay, posX1, posY1, posX2-posX1, yPixel)
506 renderOverlay(GuiElement.debugOverlay, posX1, posY2, posX2-posX1, yPixel)
507 renderOverlay(GuiElement.debugOverlay, posX1, posY1, xPixel, posY2-posY1)
508 renderOverlay(GuiElement.debugOverlay, posX1+posX2-posX1, posY1, xPixel, posY2-posY1)
509 end
510
511 ButtonElement:superClass().draw(self)
512end

getIconModifiedTextOffset

Description
Get modified text offset including changes from icon position and dimensions.
Definition
getIconModifiedTextOffset(float textOffsetX, float textOffsetY)
Arguments
floattextOffsetXScreen space text X offset
floattextOffsetYScreen space text Y offset
Return Values
floatModifiedX offset
floatModifiedY offset
Code
545function ButtonElement:getIconModifiedTextOffset(textOffsetX, textOffsetY)
546 local xOffset, yOffset = textOffsetX, textOffsetY
547 local iconWidth, _ = self:getIconSize()
548
549 if self.textAlignment == RenderText.ALIGN_LEFT then
550 xOffset = xOffset - self.iconTextOffset[1] + iconWidth
551 elseif self.textAlignment == RenderText.ALIGN_CENTER then
552 xOffset = xOffset + (-self.iconTextOffset[1] + iconWidth) * 0.5
553 end
554
555 return xOffset, yOffset
556end

getIconOffset

Description
Definition
getIconOffset()
Code
448function ButtonElement:getIconOffset(textWidth, textHeight)
449 local iconSizeX, iconSizeY = self:getIconSize()
450 local xOffset, yOffset = self.iconTextOffset[1], self.iconTextOffset[2]
451
452 if self.textAlignment == RenderText.ALIGN_LEFT then
453 xOffset = xOffset - iconSizeX
454 elseif self.textAlignment == RenderText.ALIGN_CENTER then
455 xOffset = xOffset - textWidth * 0.5 - iconSizeX
456 elseif self.textAlignment == RenderText.ALIGN_RIGHT then
457 xOffset = xOffset + textWidth - iconSizeX
458 end
459
460 if self.textVerticalAlignment == TextElement.VERTICAL_ALIGNMENT.TOP then
461 yOffset = yOffset - textHeight
462 elseif self.textVerticalAlignment == TextElement.VERTICAL_ALIGNMENT.MIDDLE then
463 yOffset = yOffset + (textHeight - iconSizeY) * 0.5
464 end
465
466 return xOffset, yOffset
467end

getIconSize

Description
Get the current icon size in screen space.
Definition
getIconSize()
Code
574function ButtonElement:getIconSize()
575 if self.isKeyboardMode then
576 return self.keyGlyphSize[1], self.keyGlyphSize[2]
577 else
578 return self.iconSize[1], self.iconSize[2]
579 end
580end

getIsActive

Description
Definition
getIsActive()
Code
369function ButtonElement:getIsActive()
370 local baseActive = ButtonElement:superClass().getIsActive(self)
371 return baseActive and self.onClickCallback ~= nil
372end

getIsHighlighted

Description
Determine if this button is highlighted
Definition
getIsHighlighted()
Code
534function ButtonElement:getIsHighlighted()
535 local superSelected = ButtonElement:superClass().getIsHighlighted(self)
536 return superSelected or self:getOverlayState() == GuiOverlay.STATE_HIGHLIGHTED
537end

getIsSelected

Description
Determine if this button is selected
Definition
getIsSelected()
Code
526function ButtonElement:getIsSelected()
527 local isSelected = ButtonElement:superClass().getIsSelected(self)
528 local state = self:getOverlayState()
529 return isSelected or state == GuiOverlay.STATE_FOCUSED or state == GuiOverlay.STATE_PRESSED or state == GuiOverlay.STATE_SELECTED
530end

getText2Offset

Description
Get shadow text offset from element position including modifications from icon.
Definition
getText2Offset()
Code
567function ButtonElement:getText2Offset()
568 local xOffset, yOffset = ButtonElement:superClass().getText2Offset(self)
569 return self:getIconModifiedTextOffset(xOffset, yOffset)
570end

getTextOffset

Description
Get text offset from element position including modifications from icon.
Definition
getTextOffset()
Code
560function ButtonElement:getTextOffset()
561 local xOffset, yOffset = ButtonElement:superClass().getTextOffset(self)
562 return self:getIconModifiedTextOffset(xOffset, yOffset)
563end

isFocused

Description
Definition
isFocused()
Code
634function ButtonElement:isFocused()
635 return self:getIsActive() and self:getOverlayState() == GuiOverlay.STATE_FOCUSED
636end

keyEvent

Description
Definition
keyEvent()
Code
437function ButtonElement:keyEvent(unicode, sym, modifier, isDown, eventUsed)
438 if self:getIsActive() then
439 if ButtonElement:superClass().keyEvent(self, unicode, sym, modifier, isDown, eventUsed) then
440 return true
441 end
442 end
443 return false
444end

loadFromXML

Description
Definition
loadFromXML()
Code
78function ButtonElement:loadFromXML(xmlFile, key)
79 ButtonElement:superClass().loadFromXML(self, xmlFile, key)
80
81 self:addCallback(xmlFile, key.."#onClick", "onClickCallback")
82 self:addCallback(xmlFile, key.."#onFocus", "onFocusCallback")
83 self:addCallback(xmlFile, key.."#onLeave", "onLeaveCallback")
84 self:addCallback(xmlFile, key.."#onHighlight", "onHighlightCallback")
85 self:addCallback(xmlFile, key.."#onHighlightRemove", "onHighlightRemoveCallback")
86
87 GuiOverlay.loadOverlay(self, self.overlay, "image", self.imageSize, nil, xmlFile, key)
88
89 self.iconSize = GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#iconSize"), self.outputSize, self.iconSize)
90 self.iconTextOffset = GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#iconTextOffset"), self.outputSize, self.iconTextOffset)
91 self.hotspot = GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#hotspot"), self.outputSize, self.hotspot)
92 self.forceFocus = Utils.getNoNil(getXMLBool(xmlFile, key.."#forceFocus"), self.forceFocus)
93 self.forceHighlight = Utils.getNoNil(getXMLBool(xmlFile, key.."#forceHighlight"), self.forceHighlight)
94 self.needExternalClick = Utils.getNoNil(getXMLBool(xmlFile, key.."#needExternalClick"), self.needExternalClick)
95 self.fitToContent = Utils.getNoNil(getXMLBool(xmlFile, key.."#fitToContent"), self.fitToContent)
96 self.fitExtraWidth = GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#fitExtraWidth"), self.outputSize, self.fitExtraWidth)
97 self.hideKeyboardGlyph = Utils.getNoNil(getXMLBool(xmlFile, key .. "#hideKeyboardGlyph"), self.hideKeyboardGlyph)
98
99 local inputActionName = getXMLString(xmlFile, key .. "#inputAction")
100 if inputActionName ~= nil and InputAction[inputActionName] ~= nil then
101 self.inputActionName = inputActionName
102 self:loadInputGlyphColors(nil, xmlFile, key)
103 else
104 GuiOverlay.loadOverlay(self, self.icon, "icon", self.imageSize, nil, xmlFile, key)
105 GuiOverlay.createOverlay(self.icon)
106 end
107
108 local sampleName = getXMLString(xmlFile, key .. "#clickSound") or self.clickSoundName
109 local resolvedSampleName = GuiSoundPlayer.SOUND_SAMPLES[sampleName]
110 if resolvedSampleName ~= nil then
111 self.clickSoundName = resolvedSampleName
112 end
113
114 GuiOverlay.createOverlay(self.overlay)
115
116 self:updateSize()
117end

loadInputGlyphColors

Description
Load glyph overlay colors.
Definition
loadInputGlyphColors(profile If, xmlFile If, key XML)
Arguments
profileIfset, loads overlay properties from this button's GUI profile
xmlFileIfset, loads overlay properties from this button's XML configuration
keyXMLbase configuration node of this button
Code
192function ButtonElement:loadInputGlyphColors(profile, xmlFile, key)
193 if xmlFile ~= nil then
194 GuiOverlay.loadXMLColors(xmlFile, key, self.iconColors, "icon")
195 GuiOverlay.loadXMLColors(xmlFile, key, self.icon, "icon")
196 elseif profile ~= nil then
197 GuiOverlay.loadProfileColors(profile, self.iconColors, "icon")
198 GuiOverlay.loadProfileColors(profile, self.icon, "icon")
199 end
200end

loadProfile

Description
Definition
loadProfile()
Code
121function ButtonElement:loadProfile(profile, applyProfile)
122 ButtonElement:superClass().loadProfile(self, profile, applyProfile)
123
124 GuiOverlay.loadOverlay(self, self.overlay, "image", self.imageSize, profile, nil, nil)
125
126 self.iconSize = GuiUtils.getNormalizedValues(profile:getValue("iconSize"), self.outputSize, self.iconSize)
127 self.iconTextOffset = GuiUtils.getNormalizedValues(profile:getValue("iconTextOffset"), self.outputSize, self.iconTextOffset)
128 self.hotspot = GuiUtils.getNormalizedValues(profile:getValue("hotspot"), self.outputSize, self.hotspot)
129
130 self.forceFocus = profile:getBool("forceFocus", self.forceFocus)
131 self.forceHighlight = profile:getBool("forceHighlight", self.forceHighlight)
132 self.needExternalClick = profile:getBool("needExternalClick", self.needExternalClick)
133 self.fitToContent = profile:getBool("fitToContent", self.fitToContent)
134 self.fitExtraWidth = GuiUtils.getNormalizedValues(profile:getValue("fitExtraWidth"), self.outputSize, self.fitExtraWidth)
135 self.hideKeyboardGlyph = profile:getBool("hideKeyboardGlyph", self.hideKeyboardGlyph)
136
137 local inputActionName = profile:getValue("inputAction", self.inputActionName)
138 if inputActionName ~= nil and InputAction[inputActionName] ~= nil then
139 self.inputActionName = inputActionName
140 self:loadInputGlyphColors(profile, nil, nil)
141 else
142 GuiOverlay.loadOverlay(self, self.icon, "icon", self.imageSize, profile, nil, nil)
143 GuiOverlay.createOverlay(self.icon)
144 end
145
146 local sampleName = profile:getValue("clickSound", self.clickSoundName)
147 local resolvedSampleName = GuiSoundPlayer.SOUND_SAMPLES[sampleName]
148 if resolvedSampleName ~= nil then
149 self.clickSoundName = resolvedSampleName
150 end
151
152 if applyProfile then
153 self:applyButtonAspectScale()
154 self:updateSize()
155 end
156end

mouseEvent

Description
Definition
mouseEvent()
Code
376function ButtonElement:mouseEvent(posX, posY, isDown, isUp, button, eventUsed)
377 if self:getIsActive() then
378 eventUsed = eventUsed or ButtonElement:superClass().mouseEvent(self, posX, posY, isDown, isUp, button, eventUsed)
379
380 -- handle highlight regardless of event used state
381 local cursorInElement = GuiUtils.checkOverlayOverlap(posX, posY, self.absPosition[1], self.absPosition[2], self.size[1], self.size[2], self.hotspot)
382 if cursorInElement then
383 if not self.mouseEntered and not self.focusActive then
384 -- set highlight on mouse over without focus
385 if not self.forceHighlight then
386 FocusManager:setHighlight(self)
387 end
388
389 self.mouseEntered = true
390 end
391 else -- mouse event outside button
392 self:restoreOverlayState()
393 self.mouseDown = false
394 self.mouseEntered = false
395 if not self.forceHighlight then
396 -- reset highlight
397 FocusManager:unsetHighlight(self)
398 end
399 end
400
401 -- handle click/activate only if event has not been consumed, yet
402 if not eventUsed then
403 if cursorInElement and not FocusManager:isLocked() then
404 if isDown and button == Input.MOUSE_BUTTON_LEFT then
405 if self.handleFocus and not self.forceFocus then
406 FocusManager:setFocus(self) -- focus on mouse down
407 eventUsed = true
408 end
409
410 self.mouseDown = true
411 end
412
413 -- if needed, set state to PRESSED and store current overlay state for restoration
414 if self.mouseDown and self:getOverlayState() ~= GuiOverlay.STATE_PRESSED then
415 self:storeOverlayState()
416 self:setOverlayState(GuiOverlay.STATE_PRESSED)
417 end
418
419 if isUp and button == Input.MOUSE_BUTTON_LEFT and self.mouseDown then
420 self:playSample(self.clickSoundName)
421
422 self:restoreOverlayState()
423 self.mouseDown = false
424 self:raiseCallback("onClickCallback", self)
425
426 eventUsed = true
427 end
428 end
429 end
430 end
431
432 return eventUsed
433end

new

Description
Definition
new()
Code
36function ButtonElement:new(target, custom_mt)
37 local self = TextElement:new(target, custom_mt or ButtonElement_mt)
38 self:include(PlaySampleMixin) -- add sound playing
39
40 self.mouseDown = false
41 self.forceFocus = false
42 self.forceHighlight = false -- if true, highlight state is managed by external caller
43 self.overlay = {}
44 self.icon = {}
45 self.iconSize = {0,0}
46 self.iconTextOffset = {0,0}
47 self.focusedTextOffset = {0,0}
48 self.hotspot = {0, 0, 0, 0} -- to define clickable area offset
49 self.needExternalClick = false -- used to override focus behaviour in special cases
50 self.clickSoundName = GuiSoundPlayer.SOUND_SAMPLES.CLICK
51 self.fitToContent = false
52 self.fitExtraWidth = {0}
53 self.hideKeyboardGlyph = false
54
55 self.inputActionName = nil -- name of input action whose primary input binding will be displayed as a glyph, if set
56 self.hasLoadedInputGlyph = false
57 self.isKeyboardMode = false
58 self.keyDisplayText = nil -- resolved key display text for the input action
59 self.keyOverlay = nil -- holds a shared keyboard key glyph display overlay, do not delete!
60 self.keyGlyphOffsetX = 0 -- additional text offset when displaying keyboard key glyph
61 self.keyGlyphSize = {0, 0}
62 self.iconColors = {color={1, 1, 1, 1}} -- holds overlay color information for keyboard key glyph display
63
64 return self
65end

onClose

Description
Definition
onClose()
Code
323function ButtonElement:onClose()
324 ButtonElement:superClass().onClose(self)
325 self:reset()
326 self.hasLoadedInputGlyph = false
327 g_messageCenter:unsubscribeAll(self)
328end

onFocusActivate

Description
Definition
onFocusActivate()
Code
624function ButtonElement:onFocusActivate()
625 if self:getIsActive() then
626 self:playSample(self.clickSoundName)
627
628 self:raiseCallback("onClickCallback", self)
629 end
630end

onFocusEnter

Description
Definition
onFocusEnter()
Code
606function ButtonElement:onFocusEnter()
607 self:raiseCallback("onFocusCallback", self)
608end

onFocusLeave

Description
Definition
onFocusLeave()
Code
600function ButtonElement:onFocusLeave()
601 self:raiseCallback("onLeaveCallback", self)
602end

onHighlight

Description
Definition
onHighlight()
Code
612function ButtonElement:onHighlight()
613 self:raiseCallback("onHighlightCallback", self)
614end

onHighlightRemove

Description
Definition
onHighlightRemove()
Code
618function ButtonElement:onHighlightRemove()
619 self:raiseCallback("onHighlightRemoveCallback", self)
620end

onOpen

Description
Definition
onOpen()
Code
304function ButtonElement:onOpen()
305 ButtonElement:superClass().onOpen(self)
306 if self.disabled then
307 self:setOverlayState(GuiOverlay.STATE_DISABLED)
308 end
309
310 -- deferred loading of input glyph, so that not having a controller plugged in does not break the UI on loading:
311 if self.inputActionName ~= nil and not self.hasLoadedInputGlyph then
312 self:loadInputGlyph(true)
313 end
314
315 if GS_PLATFORM_TYPE == GS_PLATFORM_TYPE_GGP then
316 g_messageCenter:subscribe(MessageType.INPUT_MODE_CHANGED, self.onControllerChanged, self)
317 g_messageCenter:subscribe(MessageType.INPUT_HELP_MODE_CHANGED, self.onControllerChanged, self)
318 end
319end

reset

Description
Definition
reset()
Code
338function ButtonElement:reset()
339 ButtonElement:superClass().reset(self)
340 self:setOverlayState(GuiOverlay.STATE_NORMAL)
341 self.mouseDown = false
342end

setAlpha

Description
Definition
setAlpha()
Code
268function ButtonElement:setAlpha(alpha)
269 ButtonElement:superClass().setAlpha(self, alpha)
270 if self.overlay ~= nil then
271 self.overlay.alpha = self.alpha
272 end
273 if self.icon ~= nil then
274 self.icon.alpha = self.alpha
275 end
276end

setClickSound

Description
Definition
setClickSound()
Code
675function ButtonElement:setClickSound(soundName)
676 self.clickSoundName = soundName
677end

setDisabled

Description
Definition
setDisabled()
Code
280function ButtonElement:setDisabled(disabled)
281 ButtonElement:superClass().setDisabled(self, disabled)
282 if disabled then
283 FocusManager:unsetFocus(self)
284 self.mouseEntered = false
285 self:raiseCallback("onLeaveCallback", self)
286 self.mouseDown = false
287 self:setOverlayState(GuiOverlay.STATE_DISABLED)
288 else
289 self:setOverlayState(GuiOverlay.STATE_NORMAL)
290 end
291end

setIconSize

Description
Definition
setIconSize()
Code
584function ButtonElement:setIconSize(x,y)
585 self.iconSize[1] = Utils.getNoNil(x, self.iconSize[1])
586 self.iconSize[2] = Utils.getNoNil(y, self.iconSize[2])
587
588 self:updateSize()
589end

setImageFilename

Description
Definition
setImageFilename()
Code
346function ButtonElement:setImageFilename(filename, iconFilename)
347 if filename ~= nil then
348 self.overlay = GuiOverlay.createOverlay(self.overlay, filename)
349 end
350 if iconFilename ~= nil then
351 self.icon = GuiOverlay.createOverlay(self.icon, iconFilename)
352 end
353end

setImageUVs

Description
Set UV coordinates for the button background and/or icon.
Definition
setImageUVs()
Code
357function ButtonElement:setImageUVs(backgroundUVs, iconUVs)
358 if backgroundUVs ~= nil then
359 self.overlay.uvs = backgroundUVs
360 end
361
362 if iconUVs ~= nil then
363 self.icon.uvs = iconUVs
364 end
365end

setInputAction

Description
Set the input action for the display glyph by name.
Definition
setInputAction()
Code
295function ButtonElement:setInputAction(inputActionName)
296 if inputActionName ~= nil and InputAction[inputActionName] ~= nil then
297 self.inputActionName = inputActionName
298 self:loadInputGlyph(true) -- true -> force reloading the overlay
299 end
300end

setKeyboardMode

Description
Set the keyboard mode flag.
Definition
setKeyboardMode()
Code
258function ButtonElement:setKeyboardMode(isKeyboardMode)
259 if self.isKeyboardMode ~= isKeyboardMode then
260 self.isKeyboardMode = isKeyboardMode
261
262 self:updateSize()
263 end
264end

setSelected

Description
Set whether the button is selected
Definition
setSelected()
Code
516function ButtonElement:setSelected(isSelected)
517 if isSelected then
518 self:setOverlayState(GuiOverlay.STATE_SELECTED)
519 else
520 self:setOverlayState(GuiOverlay.STATE_NORMAL)
521 end
522end

setText

Description
Set the button text
Definition
setText()
Code
659function ButtonElement:setText(text, forceTextSize)
660 ButtonElement:superClass().setText(self, text, forceTextSize)
661
662 self:updateSize()
663end

setTextSize

Description
Definition
setTextSize()
Code
667function ButtonElement:setTextSize(size)
668 ButtonElement:superClass().setTextSize(self, size)
669
670 self:updateSize()
671end

updateSize

Description
Update size of element depending on content
Definition
updateSize()
Code
640function ButtonElement:updateSize()
641 if not self.fitToContent then
642 return
643 end
644
645 local iconWidth, _ = self:getIconSize()
646 local xOffset, _ = self:getTextOffset()
647 local textWidth = self:getTextWidth()
648
649 local width = xOffset + textWidth + self.fitExtraWidth[1]
650 self:setSize(width, nil)
651
652 if self.parent ~= nil and self.parent.invalidateLayout ~= nil then
653 self.parent:invalidateLayout()
654 end
655end