Skip to content

Commit 49dc3a6

Browse files
committed
[[ WidgetUtils ]] Use widget utils placeholder API in native widgets and browser
1 parent 2856bf1 commit 49dc3a6

5 files changed

Lines changed: 19 additions & 215 deletions

File tree

extensions/widgets/androidbutton/androidbutton.lcb

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -215,56 +215,20 @@ public handler OnClick()
215215
post "mouseUp"
216216
end handler
217217

218-
constant kSvgIcon is "M493 615Q509 615 520.5 603.5 532 592 532 576 532 560 520.5 548.5 509 537 493 537 477 537 466 548.5 455 560 455 576 455 592 466 603.5 477 615 493 615ZM915 615Q931 615 942 603.5 953 592 953 576 953 560 942 548.5 931 537 915 537 899 537 887.5 548.5 876 560 876 576 876 592 887.5 603.5 899 615 915 615ZM103 799Q145 799 175 829 205 859 205 901L205 1331Q205 1374 175.5 1404 146 1434 103 1434 60 1434 30 1404 0 1374 0 1331L0 901Q0 859 30 829 60 799 103 799ZM1163 818L1163 1484Q1163 1530 1131 1562 1099 1594 1054 1594L979 1594 979 1821Q979 1864 949 1894 919 1924 876 1924 833 1924 803 1894 773 1864 773 1821L773 1594 635 1594 635 1821Q635 1864 605 1894 575 1924 532 1924 490 1924 460 1894 430 1864 430 1821L429 1594 355 1594Q309 1594 277 1562 245 1530 245 1484L245 818 1163 818ZM931 413Q1038 468 1102 566.5 1166 665 1166 782L241 782Q241 665 305 566.5 369 468 477 413L406 282Q399 269 411 262 424 256 431 268L503 400Q598 358 704 358 810 358 905 400L977 268Q984 256 997 262 1009 269 1002 282ZM1408 901L1408 1331Q1408 1374 1378 1404 1348 1434 1305 1434 1263 1434 1233 1404 1203 1374 1203 1331L1203 901Q1203 858 1233 828.5 1263 799 1305 799 1348 799 1378 828.5 1408 858 1408 901Z"
219-
constant kBorderWidth is 5
220-
private handler expandRectangle(in pRect as Rectangle, in pExp as Number) returns Rectangle
221-
return rectangle [ the left of pRect - pExp, the top of pRect - pExp, the right of pRect + pExp, the bottom of pRect + pExp]
222-
end handler
223-
224218
public handler OnPaint()
225219
if IsAndroid() then
226220
return
227221
end if
228222

229-
// Draw placeholder image - the icon
230-
variable tFillPaint as Paint
231-
variable tStrokePaint as Paint
232-
put solid paint with color [0.875, 0.875, 0.875] into tFillPaint
233-
put solid paint with color [0.75, 0.75, 0.75] into tStrokePaint
234-
variable tBounds as Rectangle
235-
put my bounds into tBounds
236-
set the paint of this canvas to tFillPaint
237-
fill rectangle path of tBounds on this canvas
238-
set the paint of this canvas to tStrokePaint
239-
set the stroke width of this canvas to kBorderWidth
240-
set the join style of this canvas to "bevel"
241-
stroke rectangle path of expandRectangle(tBounds, -kBorderWidth / 2) on this canvas
242-
variable tPath as Path
243-
put path kSvgIcon into tPath
244-
constrainPathToRect(expandRectangle(tBounds, -2 * kBorderWidth), tPath)
245-
fill tPath on this canvas
246-
// Draw the control name
247-
put solid paint with color [1, 1, 1, 0.1] into tFillPaint
248-
put solid paint with color [0.25, 0.25, 0.25] into tStrokePaint
249-
variable tNameString as String
223+
variable tLabel as String
250224
if mLabel is empty then
251-
put my name into tNameString
225+
put my name into tLabel
252226
else
253-
put mLabel into tNameString
227+
put mLabel into tLabel
254228
end if
255-
set the font of this canvas to my font
256-
257-
variable tTextBounds as Rectangle
258-
put the image bounds of text tNameString on this canvas into tTextBounds
259-
translate this canvas by [ the width of tBounds / 2, the height of tBounds / 2]
260-
translate this canvas by [ -(the width of tTextBounds / 2), the height of tTextBounds / 2]
261-
set the paint of this canvas to tFillPaint
262229

263-
variable tRect as Rectangle
264-
put expandRectangle(tTextBounds, kBorderWidth) into tRect
265-
fill rounded rectangle path of tRect with radius 5 on this canvas
266-
set the paint of this canvas to solid paint with stringToColor(mColor)
267-
fill text tNameString at center of tRect on this canvas
230+
paintPlaceholderImage(this canvas, my bounds, placeholderIcon("android"), \
231+
tLabel, my font, stringToColor(mColor))
268232
end handler
269233

270234
handler SetEnabled(in pValue as Boolean)

extensions/widgets/androidfield/androidfield.lcb

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,55 +1789,13 @@ public handler GetFocused() returns Boolean
17891789
return View_isFocused(mNativeObj)
17901790
end handler
17911791

1792-
constant kSvgIcon is "M493 615Q509 615 520.5 603.5 532 592 532 576 532 560 520.5 548.5 509 537 493 537 477 537 466 548.5 455 560 455 576 455 592 466 603.5 477 615 493 615ZM915 615Q931 615 942 603.5 953 592 953 576 953 560 942 548.5 931 537 915 537 899 537 887.5 548.5 876 560 876 576 876 592 887.5 603.5 899 615 915 615ZM103 799Q145 799 175 829 205 859 205 901L205 1331Q205 1374 175.5 1404 146 1434 103 1434 60 1434 30 1404 0 1374 0 1331L0 901Q0 859 30 829 60 799 103 799ZM1163 818L1163 1484Q1163 1530 1131 1562 1099 1594 1054 1594L979 1594 979 1821Q979 1864 949 1894 919 1924 876 1924 833 1924 803 1894 773 1864 773 1821L773 1594 635 1594 635 1821Q635 1864 605 1894 575 1924 532 1924 490 1924 460 1894 430 1864 430 1821L429 1594 355 1594Q309 1594 277 1562 245 1530 245 1484L245 818 1163 818ZM931 413Q1038 468 1102 566.5 1166 665 1166 782L241 782Q241 665 305 566.5 369 468 477 413L406 282Q399 269 411 262 424 256 431 268L503 400Q598 358 704 358 810 358 905 400L977 268Q984 256 997 262 1009 269 1002 282ZM1408 901L1408 1331Q1408 1374 1378 1404 1348 1434 1305 1434 1263 1434 1233 1404 1203 1374 1203 1331L1203 901Q1203 858 1233 828.5 1263 799 1305 799 1348 799 1378 828.5 1408 858 1408 901Z"
1793-
constant kBorderWidth is 5
1794-
private handler expandRectangle(in pRect as Rectangle, in pExp as Number) returns Rectangle
1795-
return rectangle [ the left of pRect - pExp, the top of pRect - pExp, the right of pRect + pExp, the bottom of pRect + pExp]
1796-
end handler
17971792
public handler OnPaint()
17981793
if IsAndroid() then
17991794
return
18001795
end if
18011796

1802-
// Draw placeholder image - the android icon
1803-
variable tFillPaint as Paint
1804-
variable tStrokePaint as Paint
1805-
put solid paint with color [0.875, 0.875, 0.875] into tFillPaint
1806-
put solid paint with color [0.75, 0.75, 0.75] into tStrokePaint
1807-
variable tBounds as Rectangle
1808-
put my bounds into tBounds
1809-
set the paint of this canvas to tFillPaint
1810-
fill rectangle path of tBounds on this canvas
1811-
set the paint of this canvas to tStrokePaint
1812-
set the stroke width of this canvas to kBorderWidth
1813-
set the join style of this canvas to "bevel"
1814-
stroke rectangle path of expandRectangle(tBounds, -kBorderWidth / 2) on this canvas
1815-
variable tPath as Path
1816-
put path kSvgIcon into tPath
1817-
constrainPathToRect(expandRectangle(tBounds, -2 * kBorderWidth), tPath)
1818-
fill tPath on this canvas
1819-
// Draw the control name
1820-
put solid paint with color [1, 1, 1, 0.1] into tFillPaint
1821-
put solid paint with color [0.25, 0.25, 0.25] into tStrokePaint
1822-
variable tNameString as String
1823-
if mText is empty then
1824-
put my name into tNameString
1825-
else
1826-
put mText into tNameString
1827-
end if
1828-
set the font of this canvas to my font
1829-
1830-
variable tTextBounds as Rectangle
1831-
put the image bounds of text tNameString on this canvas into tTextBounds
1832-
translate this canvas by [ the width of tBounds / 2, the height of tBounds / 2]
1833-
translate this canvas by [ -(the width of tTextBounds / 2), the height of tTextBounds / 2]
1834-
set the paint of this canvas to tFillPaint
1835-
1836-
variable tRect as Rectangle
1837-
put expandRectangle(tTextBounds, kBorderWidth) into tRect
1838-
fill rounded rectangle path of tRect with radius 5 on this canvas
1839-
set the paint of this canvas to solid paint with stringToColor(mTextColor)
1840-
fill text tNameString at center of tRect on this canvas
1797+
paintPlaceholderImage(this canvas, my bounds, placeholderIcon("android"), \
1798+
my name, my font, stringToColor(mTextColor))
18411799
end handler
18421800

18431801
end widget

extensions/widgets/browser/browser.lcb

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -709,52 +709,8 @@ end handler
709709
----------
710710

711711
constant kSvgIcon is "M21.7,12c0,5.4-4.4,9.7-9.7,9.7S2.3,17.4,2.3,12S6.6,2.3,12,2.3S21.7,6.6,21.7,12z M11.9,16.6c0-0.2-0.1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 5
713-
714-
private handler expandRectangle(in pRect as Rectangle, in pExp as Number) returns Rectangle
715-
return rectangle [ the left of pRect - pExp, the top of pRect - pExp, the right of pRect + pExp, the bottom of pRect + pExp]
716-
end handler
717-
718712
public handler OnPaint() returns nothing
719-
// Draw placeholder image - the browser icon
720-
variable tFillPaint as Paint
721-
variable tStrokePaint as Paint
722-
put solid paint with color [0.875, 0.875, 0.875] into tFillPaint
723-
put solid paint with color [0.75, 0.75, 0.75] into tStrokePaint
724-
725-
variable tBounds as Rectangle
726-
put my bounds into tBounds
727-
728-
set the paint of this canvas to tFillPaint
729-
fill rectangle path of tBounds on this canvas
730-
set the paint of this canvas to tStrokePaint
731-
set the stroke width of this canvas to kBorderWidth
732-
set the join style of this canvas to "bevel"
733-
stroke rectangle path of expandRectangle(tBounds, -kBorderWidth / 2) on this canvas
734-
735-
variable tPath as Path
736-
put path kSvgIcon into tPath
737-
constrainPathToRect(expandRectangle(tBounds, -2 * kBorderWidth), tPath)
738-
fill tPath on this canvas
739-
740-
// Draw the control name
741-
put solid paint with color [1, 1, 1] into tFillPaint
742-
put solid paint with color [0.25, 0.25, 0.25] into tStrokePaint
743-
744-
variable tNameString as String
745-
put my name into tNameString
746-
747-
set the font of this canvas to font "Arial" at size 14
748-
749-
variable tTextBounds as Rectangle
750-
put the image bounds of text tNameString on this canvas into tTextBounds
751-
752-
translate this canvas by [ the width of tBounds / 2, the height of tBounds / 2]
753-
translate this canvas by [ -(the width of tTextBounds / 2), the height of tTextBounds / 2]
754-
set the paint of this canvas to tFillPaint
755-
fill rounded rectangle path of expandRectangle(tTextBounds, kBorderWidth) with radius 5 on this canvas
756-
set the paint of this canvas to tStrokePaint
757-
fill text tNameString at point [0, 0] on this canvas
713+
paintPlaceholderImage(this canvas, my bounds, kSvgIcon, my name, nothing, nothing)
758714
end handler
759715

760716
----------

extensions/widgets/iosbutton/iosbutton.lcb

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ metadata author is "LiveCode"
4646
metadata title is "iOS Native Button"
4747
metadata svgicon is "M 535.66797 241.55273 C 491.1077 241.55273 455.23438 277.42605 455.23438 321.98633 L 455.23438 913.65039 C 455.23438 958.21066 491.1077 994.08398 535.66797 994.08398 L 2014.5762 994.08398 C 2059.1364 994.08398 2095.0098 958.21066 2095.0098 913.65039 L 2095.0098 321.98633 C 2095.0098 277.42605 2059.1364 241.55273 2014.5762 241.55273 L 535.66797 241.55273 z M 1155.1543 304.32422 C 1293.7311 304.30837 1399.8223 413.6262 1399.8223 613.28906 C 1399.8223 831.92443 1278.4507 931.3125 1145.5957 931.3125 C 1009.8798 931.3125 899.97656 823.80972 899.97656 622.33203 C 899.97656 415.4574 1013.7086 304.32422 1155.1543 304.32422 z M 1637.668 305.20508 C 1689.1647 305.20508 1728.013 319.66027 1746.082 332.30859 L 1738.9023 347.9043 C 1723.5436 337.0708 1682.0317 323.26562 1636.875 323.26562 C 1535.6646 323.26562 1491.5781 399.7417 1491.5781 456.04102 C 1491.5781 533.80129 1551.8559 559.80417 1629.5527 596.8457 C 1719.89 641.10692 1767.7656 680.13793 1767.7656 765.07031 C 1767.7656 856.31896 1702.7239 930.38477 1587.082 930.38477 C 1539.1912 930.38477 1484.0899 914.13108 1456.9863 893.34375 L 1465.0605 875.2832 C 1494.8824 895.15914 1546.3559 914.35352 1590.625 914.35352 C 1674.646 914.35352 1749.3711 855.57405 1749.3711 769.05664 C 1749.3711 688.7683 1699.5944 646.87616 1615.082 610.88867 C 1539.4457 578.68139 1471.4414 543.72442 1471.4414 457.89648 C 1471.4414 368.46267 1541.9021 305.20508 1637.668 305.20508 z M 1156.1758 325.58008 C 999.78351 325.58008 917.99023 456.01743 917.99023 617.80664 C 917.99023 783.58214 998.33285 912.36328 1146.4355 912.36328 C 1295.5685 912.36328 1381.1035 779.61907 1381.1035 615.91992 C 1381.1035 464.11624 1312.5681 325.58008 1156.1758 325.58008 z M 799.93164 336.48438 C 810.31342 336.48438 816.91406 344.97176 816.91406 355.35352 C 816.91406 366.19495 810.31315 374.21484 798.98828 374.21484 C 789.55751 374.21484 782.48047 366.19495 782.48047 355.35352 C 782.48047 344.97176 790.02537 336.48438 799.93164 336.48438 z M 790.80859 488.61328 L 808.58398 488.61328 L 808.58398 922.26953 L 790.80859 922.26953 L 790.80859 488.61328 z"
4848

49-
constant kSvgIcon is "M4.621 6.965c0 1.368-.833 2.38-2.262 2.38-1.19 0-2.083-1.012-2.083-2.38 0-1.31.952-2.381 2.202-2.381 1.31 0 2.143 1.071 2.143 2.381zM1.327 78.5V23.78H3.57V78.5H1.327zM78.174 39.512c0 27.588-15.315 40.129-32.079 40.129-17.125 0-30.993-13.565-30.993-38.988C15.102 14.549 29.453.526 47.301.526 64.787.524 78.174 14.318 78.174 39.512zm-60.799.57C17.375 61 27.513 77.25 46.201 77.25c18.818 0 29.611-16.75 29.611-37.406 0-19.155-8.648-36.636-28.382-36.636S17.375 19.667 17.375 40.082zM86.406 72.571c3.763 2.508 10.258 4.93 15.844 4.93 10.602 0 20.031-7.417 20.031-18.334 0-10.131-6.281-15.417-16.945-19.958-9.544-4.064-18.125-8.475-18.125-19.305 0-11.285 8.891-19.267 20.975-19.267 6.498 0 11.4 1.824 13.68 3.42l-.906 1.968c-1.938-1.367-7.176-3.109-12.874-3.109-12.771 0-18.334 9.65-18.334 16.754 0 9.812 7.606 13.093 17.41 17.767 11.399 5.585 17.44 10.51 17.44 21.227 0 11.514-8.207 20.86-22.799 20.86-6.043 0-12.996-2.051-16.416-4.674l1.019-2.279z"
50-
5149
/**
5250
Syntax:
5351
set the label of <widget> to <pLabel>
@@ -106,55 +104,20 @@ end handler
106104

107105
/**/
108106

109-
constant kBorderWidth is 5
110-
private handler expandRectangle(in pRect as Rectangle, in pExp as Number) returns Rectangle
111-
return rectangle [ the left of pRect - pExp, the top of pRect - pExp, the right of pRect + pExp, the bottom of pRect + pExp]
112-
end handler
113-
114107
public handler OnPaint()
115108
if IsIOS() then
116109
return
117110
end if
118-
119-
// Draw placeholder image - the icon
120-
variable tFillPaint as Paint
121-
variable tStrokePaint as Paint
122-
put solid paint with color [0.875, 0.875, 0.875] into tFillPaint
123-
put solid paint with color [0.75, 0.75, 0.75] into tStrokePaint
124-
variable tBounds as Rectangle
125-
put my bounds into tBounds
126-
set the paint of this canvas to tFillPaint
127-
fill rectangle path of tBounds on this canvas
128-
set the paint of this canvas to tStrokePaint
129-
set the stroke width of this canvas to kBorderWidth
130-
set the join style of this canvas to "bevel"
131-
stroke rectangle path of expandRectangle(tBounds, -kBorderWidth / 2) on this canvas
132-
variable tPath as Path
133-
put path kSvgIcon into tPath
134-
constrainPathToRect(expandRectangle(tBounds, -2 * kBorderWidth), tPath)
135-
fill tPath on this canvas
136-
// Draw the control name
137-
put solid paint with color [1, 1, 1, 0.1] into tFillPaint
138-
put solid paint with color [0.25, 0.25, 0.25] into tStrokePaint
139-
variable tNameString as String
111+
112+
variable tLabel as String
140113
if mLabel is empty then
141-
put my name into tNameString
114+
put my name into tLabel
142115
else
143-
put mLabel into tNameString
116+
put mLabel into tLabel
144117
end if
145-
set the font of this canvas to my font
146-
147-
variable tTextBounds as Rectangle
148-
put the image bounds of text tNameString on this canvas into tTextBounds
149-
translate this canvas by [ the width of tBounds / 2, the height of tBounds / 2]
150-
translate this canvas by [ -(the width of tTextBounds / 2), the height of tTextBounds / 2]
151-
set the paint of this canvas to tFillPaint
152118

153-
variable tRect as Rectangle
154-
put expandRectangle(tTextBounds, kBorderWidth) into tRect
155-
fill rounded rectangle path of tRect with radius 5 on this canvas
156-
set the paint of this canvas to solid paint with color [0.0, 0.0, 0.0]
157-
fill text tNameString at center of tRect on this canvas
119+
paintPlaceholderImage(this canvas, my bounds, placeholderIcon("ios"), \
120+
tLabel, my font, nothing)
158121
end handler
159122

160123
/**/

0 commit comments

Comments
 (0)