Skip to content

Commit f460f0b

Browse files
committed
Update code docs
1 parent a578dda commit f460f0b

5 files changed

Lines changed: 77 additions & 25 deletions

docs/components_ui_button_TextButton.bs.html

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
m.top.observeField("minWidth", "onSizeChanged")
1717
m.top.observeField("minHeight", "onSizeChanged")
1818

19+
' Enable render tracking on parent to know when component has rendered
20+
m.top.enableRenderTracking = true
21+
m.top.observeField("renderTracking", "onRenderComplete")
22+
1923
applyTheme()
2024
end sub
2125

@@ -67,38 +71,41 @@
6771

6872
sub onTextChanged()
6973
m.buttonText.text = m.top.text
74+
' If already rendered, resize immediately. Otherwise wait for onRenderComplete
75+
if m.top.renderTracking = "full"
76+
setSizeAndCenterText()
77+
end if
78+
end sub
79+
80+
' Called when the component has rendered and we can measure the label accurately
81+
sub onRenderComplete()
82+
if m.top.renderTracking <> "full" then return
7083
setSizeAndCenterText()
7184
end sub
7285

7386
sub setSizeAndCenterText()
7487
if not isValid(m.buttonText) then return
7588
if m.buttonText.text.Len() = 0 then return
7689

77-
' Store the current text to detect if we've already sized for this text
78-
if not isValid(m.lastSizedText) then m.lastSizedText = ""
79-
if m.lastSizedText = m.buttonText.text and isValid(m.top.width) and m.top.width > 0
80-
' We've already sized this text, just update the focus border and return
81-
setFocusBorderSize()
82-
return
83-
end if
84-
m.lastSizedText = m.buttonText.text
90+
' Reset label size to allow accurate measurement of text content
91+
m.buttonText.width = 0
92+
m.buttonText.height = 0
8593

86-
' Always use font-based calculation to avoid stale localBoundingRect() issues
87-
textLength = m.buttonText.text.Len()
88-
fontSize = m.buttonText.font.size
89-
charWidth = fontSize * 0.64
90-
textWidth = textLength * charWidth
94+
' Get accurate text dimensions from rendered label
95+
boundingRect = m.buttonText.localBoundingRect()
96+
textWidth = boundingRect.width
9197

92-
' Use font size for height to avoid stale localBoundingRect() issues
93-
textHeight = fontSize
98+
' If not rendered yet, wait for onRenderComplete
99+
if textWidth = 0 then return
94100

95-
' print "[TextButton] text='"; m.buttonText.text; "', length="; textLength; ", charWidth="; charWidth; ", textWidth="; textWidth; ", textHeight="; textHeight
101+
' Calculate visible text height for equal padding
102+
' localBoundingRect height includes line spacing, adjust to match horizontal padding
103+
fontSize = m.buttonText.font.size
104+
visibleTextHeight = fontSize * 0.7
96105

97106
' Calculate button dimensions with padding
98107
buttonWidth = textWidth + (m.top.padding * 2)
99-
buttonHeight = textHeight + (m.top.padding * 2)
100-
101-
' print "[TextButton] size with padding: width=", buttonWidth, ", height=", buttonHeight
108+
buttonHeight = visibleTextHeight + (m.top.padding * 2)
102109

103110
' Ensure minimum dimensions (this is the ONLY place minWidth should be enforced)
104111
if buttonWidth < m.top.minWidth
@@ -108,8 +115,6 @@
108115
buttonHeight = m.top.minHeight
109116
end if
110117

111-
' print "[TextButton] ACTUAL size (using minWidth): width=", buttonWidth, ", height=", buttonHeight
112-
113118
' Set background size
114119
m.buttonBackground.width = buttonWidth
115120
m.buttonBackground.height = buttonHeight
@@ -120,6 +125,14 @@
120125
m.buttonText.translation = [0, 0]
121126

122127
setFocusBorderSize()
128+
129+
' Show the button now that it's properly sized
130+
m.buttonBackground.visible = true
131+
m.buttonBorder.visible = true
132+
m.buttonText.visible = true
133+
134+
' Signal that the button is ready (sized and visible)
135+
m.top.ready = true
123136
end sub
124137

125138
sub onPaddingChanged()

docs/components_ui_buttongroup_JRButtonGroup.bs.html

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,47 @@
2626
' center the button group horizontally
2727
' NOTE: this centers using the entire screen width, not the parent bounding rect
2828
sub center()
29-
buttonsBoundingRect = m.top.boundingRect()
29+
' Check if any child buttons have a 'ready' field that's not yet true
30+
' (This handles TextButtons that need to finish sizing before we can center)
31+
allReady = true
32+
for i = 0 to m.top.getChildCount() - 1
33+
child = m.top.getChild(i)
34+
if child <> invalid and child.hasField("ready") and not child.ready
35+
allReady = false
36+
' Observe this child's ready field if not already observing
37+
if m.observingReadyFields = invalid
38+
m.observingReadyFields = []
39+
end if
40+
' Check if we're already observing this child
41+
alreadyObserving = false
42+
for each observedChild in m.observingReadyFields
43+
if observedChild.isSameNode(child)
44+
alreadyObserving = true
45+
exit for
46+
end if
47+
end for
48+
if not alreadyObserving
49+
child.observeField("ready", "onChildReady")
50+
m.observingReadyFields.push(child)
51+
end if
52+
end if
53+
end for
54+
55+
' If all children are ready (or don't have ready fields), center now
56+
if allReady
57+
doCentering()
58+
end if
59+
end sub
3060

61+
' Called when a child button becomes ready
62+
sub onChildReady()
63+
' Try centering again - this will check if ALL children are now ready
64+
center()
65+
end sub
66+
67+
' Actually perform the centering calculation
68+
sub doCentering()
69+
buttonsBoundingRect = m.top.boundingRect()
3170
m.top.translation = [(1920 - buttonsBoundingRect.width) / 2, m.top.translation[1]]
3271
end sub
3372

docs/data/search.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/module-JRButtonGroup.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/module-TextButton.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)