Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 33d3379

Browse files
[[New Widget]] added ability to draw a default sized or mini sized android floating action button
1 parent 4314c9d commit 33d3379

File tree

1 file changed

+113
-13
lines changed

1 file changed

+113
-13
lines changed

extensions/widgets/pushbutton/pushbutton.lcb

Lines changed: 113 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ metadata colorScheme.label is "Color Scheme"
224224

225225
/*
226226
Syntax: set the colorTheme of <widget> to <pColorTheme>
227-
Synatx: get the colorTheme of <widget>
227+
Syntax: get the colorTheme of <widget>
228228

229229
Summary: The color theme of the widget
230230

@@ -242,6 +242,19 @@ metadata colorTheme.options is "Light,Dark"
242242
metadata colorTheme.default is "Light"
243243
metadata colorTheme.label is "Color Theme"
244244

245+
/*
246+
Syntax: set the miniFloatingAction of <widget> to {true | false}
247+
Syntax: get the miniFloatingAction of <widget>
248+
249+
Summary: Whether the floating action button is the default size or mini
250+
251+
Description:
252+
Use this property to determine whether the Android Floating Action button is the default size (false) or mini (true), Android only.
253+
*/
254+
property miniFloatingAction get mIsMiniFloatingAction set setMiniFloatingAction
255+
metadata miniFloatingAction.default is "false"
256+
metadata miniFloatingAction.label is "Mini Floating Action"
257+
245258
-- private instance variables
246259
private variable mWidgetTheme as String
247260
private variable mLabelStyle as String
@@ -252,6 +265,7 @@ private variable mBackgroundColor as Color
252265
private variable mBackgroundOpacity as String
253266
private variable mColorScheme as String
254267
private variable mColorTheme as String
268+
private variable mIsMiniFloatingAction as Boolean
255269

256270
private variable mShowBorder as Boolean
257271
private variable mDefaultColor as Color
@@ -261,9 +275,15 @@ private variable mWidth as Real
261275
private variable mHeight as Real
262276

263277
private variable mAndroidColors as Array
278+
private variable mAndroidColorsPressed as Array
264279
private variable mAndroidBackgroundColor as Color
265280
private variable mAndroidLabelColor as Color
266281

282+
private variable mFloatingActionRadius as Real
283+
private variable mFloatingActionIconDimension as Real
284+
285+
private variable mIsPressed as Boolean
286+
267287
-- constants
268288
constant kWidgetThemeIos is "iOS"
269289
constant kWidgetThemeAndroidFloatingAction is "Android(Floating Action)"
@@ -282,6 +302,10 @@ constant kIosDefaultHeight is 29
282302
constant kAndroidDefaultFontSize is 14
283303
constant kAndroidDefaultHeight is 36
284304

305+
constant kAndroidDefaultIconDimension is 24
306+
constant kDefaultFloatingActionDiameter is 56
307+
constant kDefaultMiniFloatingActionDiameter is 40
308+
285309
public handler OnSave(out rProperties as Array)
286310
put the empty array into rProperties
287311

@@ -294,6 +318,7 @@ public handler OnSave(out rProperties as Array)
294318
put mBackgroundOpacity into rProperties["opacity"]
295319
put mColorScheme into rProperties["colorScheme"]
296320
put mColorTheme into rProperties["colorTheme"]
321+
put mIsMiniFloatingAction into rProperties["miniFloatingAction"]
297322

298323
end handler
299324

@@ -307,6 +332,7 @@ public handler OnLoad(in pProperties as Array)
307332
put pProperties["opacity"] into mBackgroundOpacity
308333
put pProperties["colorScheme"] into mColorScheme
309334
put pProperties["colorTheme"] into mColorTheme
335+
put pProperties["miniFloatingAction"] into mIsMiniFloatingAction
310336
end handler
311337

312338
public handler OnCreate() returns nothing
@@ -319,11 +345,14 @@ public handler OnCreate() returns nothing
319345
put "Transparent" into mBackgroundOpacity
320346
put "Blue" into mColorScheme
321347
put "Light" into mColorTheme
348+
put false into mIsMiniFloatingAction
322349

323350
put false into mShowBorder
324351
put color [0, 121/255, 1] into mDefaultColor
325352
updateVariables()
326353
fetchAndroidColors()
354+
355+
put false into mIsPressed
327356
end handler
328357

329358
public handler OnPaint() returns nothing
@@ -367,6 +396,11 @@ private handler drawAndroidFloatingActionButton() returns nothing
367396
set the paint of this canvas to fetchPaint("background")
368397
fill fetchPath("background") on this canvas
369398

399+
-- border
400+
set the paint of this canvas to solid paint with color [209/255,209/255,209/255]
401+
set the stroke width of this canvas to 0.5
402+
stroke fetchPath("background") on this canvas
403+
370404
-- label
371405
set the paint of this canvas to fetchPaint("label")
372406
fill fetchIconPath(mLabelIcon) on this canvas
@@ -409,6 +443,12 @@ private handler drawAndroidRaisedButton() returns nothing
409443
end handler
410444

411445
private handler drawAndroidFlatButton() returns nothing
446+
-- background if button is pressed
447+
if mIsPressed then
448+
set the paint of this canvas to fetchPaint("background")
449+
fill fetchPath("background") on this canvas
450+
end if
451+
412452
-- label
413453
variable tLabel as String
414454
put the upper of mLabelText into tLabel
@@ -422,19 +462,17 @@ private handler drawDropShadow() returns Effect
422462
variable tProps as Array
423463
put the empty array into tProps
424464

465+
put color [39/255, 39/255, 39/255, 0.2] into tProps["color"]
466+
put "source over" into tProps["blend mode"]
467+
put 255 into tProps["opacity"]
468+
425469
if mWidgetTheme is kWidgetThemeAndroidFloatingAction then
426-
put color [186/255, 186/255, 186/255, 0.8] into tProps["color"]
427-
put "source over" into tProps["blend mode"]
428-
put 255 into tProps["opacity"]
429470
put 0.5 into tProps["spread"]
430471
put 5 into tProps["size"]
431472
put 7 into tProps["distance"]
432473
put 90 into tProps["angle"]
433474

434475
else if mWidgetTheme is kWidgetThemeAndroidRaised then
435-
put color [186/255, 186/255, 186/255, 0.8] into tProps["color"]
436-
put "source over" into tProps["blend mode"]
437-
put 255 into tProps["opacity"]
438476
put 0.6 into tProps["spread"]
439477
put 1 into tProps["size"]
440478
put 4 into tProps["distance"]
@@ -472,10 +510,10 @@ private handler fetchPath(in pObject as String) returns Path
472510
if pObject is "background" then
473511
if mWidgetTheme is kWidgetThemeIos then
474512
return rounded rectangle path of my bounds with radius 5
475-
else if mWidgetTheme is kWidgetThemeAndroidRaised then
513+
else if mWidgetTheme is kWidgetThemeAndroidRaised or mWidgetTheme is kWidgetThemeAndroidFlat then
476514
return rounded rectangle path of rectangle [0, 0, mWidth-5, mHeight-5] with radius 2
477515
else if mWidgetTheme is kWidgetThemeAndroidFloatingAction then
478-
return circle path centered at point [mWidth/2, (mHeight-10)/2] with radius (mHeight-10)/2
516+
return circle path centered at point [mWidth/2, mFloatingActionRadius] with radius mFloatingActionRadius
479517
end if
480518
else if pObject is "border" then
481519
return rounded rectangle path of rectangle [0, 0, mWidth-5, mHeight-5] with radius 2
@@ -490,7 +528,7 @@ private handler fetchIconPath(in pIconName as String) returns Path
490528
if mWidgetTheme is kWidgetThemeIos then
491529
put rectangle [0, mHeight/4, mWidth, 3*mHeight/4] into tIconRect
492530
else if mWidgetTheme is kWidgetThemeAndroidFloatingAction then
493-
put rectangle [mWidth/2 - (mHeight-10)/2, (mHeight-10)/4, mWidth/2 + (mHeight-10)/2, 3*(mHeight-10)/4] into tIconRect
531+
put rectangle [(mWidth-mFloatingActionIconDimension)/2, mFloatingActionRadius-mFloatingActionIconDimension/2, (mWidth+mFloatingActionIconDimension)/2, mFloatingActionRadius+mFloatingActionIconDimension/2] into tIconRect
494532
end if
495533

496534
setIconPath(tIconRect, tIconPath)
@@ -512,12 +550,27 @@ private handler updateVariables() returns nothing
512550
put mHeight*(kIosDefaultFontSize/kIosDefaultHeight) into mIosFontSize
513551
put mHeight*(kAndroidDefaultFontSize/kAndroidDefaultHeight) into mAndroidFontSize
514552

515-
if mWidgetTheme contains "Android" then
553+
if mIsMiniFloatingAction then
554+
put ((mHeight-10)/2)*(kDefaultMiniFloatingActionDiameter/kDefaultFloatingActionDiameter) into mFloatingActionRadius
555+
put mFloatingActionRadius*2*(kAndroidDefaultIconDimension/kDefaultMiniFloatingActionDiameter) into mFloatingActionIconDimension
556+
else
557+
put (mHeight-10)/2 into mFloatingActionRadius
558+
put mFloatingActionRadius*2*(kAndroidDefaultIconDimension/kDefaultFloatingActionDiameter) into mFloatingActionIconDimension
559+
end if
516560

561+
if mWidgetTheme contains "Android" then
517562
if mColorTheme is "Light" then
518563
if my enabled then
519564
put stringToColor(mAndroidColors[mColorScheme]) into mAndroidLabelColor
520-
put color [1,1,1] into mAndroidBackgroundColor
565+
if mIsPressed then
566+
if mWidgetTheme is kWidgetThemeAndroidFlat then
567+
put color [153/255, 153/255, 153/255, 0.4] into mAndroidBackgroundColor
568+
-- TO-DO raised light background color ??
569+
end if
570+
else
571+
put color [1,1,1] into mAndroidBackgroundColor
572+
end if
573+
521574
else
522575
put color [0,0,0,0.26] into mAndroidLabelColor
523576
if mWidgetTheme is kWidgetThemeAndroidRaised then
@@ -527,8 +580,18 @@ private handler updateVariables() returns nothing
527580

528581
else if mColorTheme is "Dark" then
529582
if my enabled then
530-
put stringToColor(mAndroidColors[mColorScheme]) into mAndroidBackgroundColor
531583
put color [1,1,1] into mAndroidLabelColor
584+
585+
if mIsPressed then
586+
if mWidgetTheme is kWidgetThemeAndroidFlat then
587+
put color [204/255, 204/255, 204/255, 0.25] into mAndroidBackgroundColor
588+
else if mWidgetTheme is kWidgetThemeAndroidRaised then
589+
put stringToColor(mAndroidColorsPressed[mColorScheme]) into mAndroidBackgroundColor
590+
end if
591+
else
592+
put stringToColor(mAndroidColors[mColorScheme]) into mAndroidBackgroundColor
593+
end if
594+
532595
else
533596
put color [1,1,1,0.3] into mAndroidLabelColor
534597
if mWidgetTheme is kWidgetThemeAndroidRaised then
@@ -564,6 +627,38 @@ private handler fetchAndroidColors() returns nothing
564627
put "140,140,140" into mAndroidColors["Grey"]
565628
put "78,106,120" into mAndroidColors["Blue Grey"]
566629

630+
put the empty array into mAndroidColorsPressed
631+
put "199,25,36" into mAndroidColorsPressed["Red"]
632+
put "179,0,73" into mAndroidColorsPressed["Pink"]
633+
put "102,0,145" into mAndroidColorsPressed["Purple"]
634+
put "63,23,151" into mAndroidColorsPressed["Deep Purple"]
635+
put "36,42,142" into mAndroidColorsPressed["Indigo"]
636+
put "23,95,199" into mAndroidColorsPressed["Blue"]
637+
put "14,114,198" into mAndroidColorsPressed["Light Blue"]
638+
put "17,134,150" into mAndroidColorsPressed["Cyan"]
639+
put "13,104,88" into mAndroidColorsPressed["Teal"]
640+
put "46,127,46" into mAndroidColorsPressed["Green"]
641+
put "87,145,43" into mAndroidColorsPressed["Light Green"]
642+
put "160,168,33" into mAndroidColorsPressed["Lime"]
643+
put "249,180,36" into mAndroidColorsPressed["Yellow"]
644+
put "253,142,9" into mAndroidColorsPressed["Amber"]
645+
put "240,103,8" into mAndroidColorsPressed["Orange"]
646+
put "222,51,21" into mAndroidColorsPressed["Deep Orange"]
647+
put "74,49,42" into mAndroidColorsPressed["Brown"]
648+
put "78,78,78" into mAndroidColorsPressed["Grey"]
649+
put "54,72,81" into mAndroidColorsPressed["Blue Grey"]
650+
651+
end handler
652+
653+
public handler OnMouseDown() returns nothing
654+
put true into mIsPressed
655+
redraw all
656+
end handler
657+
658+
public handler OnMouseUp() returns nothing
659+
put false into mIsPressed
660+
redraw all
661+
post "mouseUp"
567662
end handler
568663

569664
--------------------------------------------------------------------------------
@@ -730,6 +825,11 @@ private handler setColorTheme(in pColorTheme as String) returns nothing
730825

731826
end handler
732827

828+
private handler setMiniFloatingAction(in pIsMiniFloatingAction as Boolean) returns nothing
829+
put pIsMiniFloatingAction into mIsMiniFloatingAction
830+
redraw all
831+
end handler
832+
733833
--------------------------------------------------------------------------------
734834
--
735835
-- Icon Paths

0 commit comments

Comments
 (0)