@@ -28,6 +28,7 @@ use com.livecode.canvas
2828use com.livecode.widget
2929use com.livecode.engine
3030use com.livecode.library.iconSVG
31+ use com.livecode.widgetutils
3132--
3233
3334-- adding metadata to ensure the extension displays correctly in LiveCode
@@ -295,7 +296,7 @@ public handler OnSave(out rProperties as Array)
295296 put mLabelStyle into rProperties["labelStyle"]
296297 put mLabelText into rProperties["labelText"]
297298 put mLabelIcon into rProperties["labelIcon"]
298- put colorToString(mLabelColor) into rProperties["labelColor"]
299+ put colorToString(mLabelColor, false ) into rProperties["labelColor"]
299300 put mBackgroundOpacity into rProperties["opacity"]
300301 put mColorScheme into rProperties["colorScheme"]
301302 put mColorTheme into rProperties["colorTheme"]
@@ -517,7 +518,7 @@ private handler fetchIconPath(in pIconName as String) returns Path
517518 put rectangle [(mWidth-mFloatingActionIconDimension)/2, mFloatingActionRadius-mFloatingActionIconDimension/2, (mWidth+mFloatingActionIconDimension)/2, mFloatingActionRadius+mFloatingActionIconDimension/2] into tIconRect
518519 end if
519520
520- setIconPath (tIconRect, tIconPath)
521+ constrainPathToRect (tIconRect, tIconPath)
521522 return tIconPath
522523end handler
523524
@@ -746,7 +747,7 @@ private handler setLabelIcon(in pIconName as String)
746747end handler
747748
748749public handler getLabelColor() returns String
749- return colorToString(mLabelColor)
750+ return colorToString(mLabelColor, false )
750751end handler
751752
752753constant kWhiteColorString is "255,255,255"
@@ -825,124 +826,4 @@ private handler setMiniFloatingAction(in pIsMiniFloatingAction as Boolean) retur
825826 redraw all
826827end handler
827828
828- --------------------------------------------------------------------------------
829- --
830- -- Icon Paths
831- --
832- --------------------------------------------------------------------------------
833-
834- -- Translate and scale xPath so that it fits within pTargetRect
835- private handler setIconPath(in pTargetRect as Rectangle, inout xPath as Path)
836-
837- -- Scale the icon appropriately
838- variable tBounds
839- variable tXScale as Real
840- variable tYScale as Real
841-
842- put the bounding box of xPath into tBounds
843- put the width of pTargetRect / the width of tBounds into tXScale
844- put the height of pTargetRect / the height of tBounds into tYScale
845-
846- if tXScale > tYScale then
847- put tYScale into tXScale
848- else
849- put tXScale into tYScale
850- end if
851-
852- scale xPath by [tXScale, tYScale]
853-
854- variable tXTranslate as Real
855- variable tYTranslate as Real
856-
857- put the bounding box of xPath into tBounds
858-
859- put the left of pTargetRect - the left of tBounds into tXTranslate
860- put the top of pTargetRect - the top of tBounds into tYTranslate
861-
862- variable tXDiff as Real
863- variable tYDiff as Real
864-
865- put the width of pTargetRect - the width of tBounds into tXDiff
866- put the height of pTargetRect - the height of tBounds into tYDiff
867-
868- -- Align center
869- divide tXDiff by 2
870- divide tYDiff by 2
871-
872- translate xPath by [tXTranslate + tXDiff, tYTranslate + tYDiff]
873- end handler
874-
875- --------------------------------------------------------------------------------
876- --
877- -- Converting Data Types
878- --
879- --------------------------------------------------------------------------------
880-
881- -- this handler converts a string of numbers to an RGBA color
882- private handler stringToColor(in pString as String) returns Color
883- variable tRed as Real
884- variable tGreen as Real
885- variable tBlue as Real
886- variable tAlpha as Real
887-
888- variable tComponentList as List
889- split pString by "," into tComponentList
890-
891- variable tComponentCount
892- put the number of elements in tComponentList into tComponentCount
893- if tComponentCount is not 3 and tComponentCount is not 4 then
894- -- Invalid number of components detected
895- throw "Invalid color"
896- end if
897-
898- put (element 1 of tComponentList) parsed as number into tRed
899- put (element 2 of tComponentList) parsed as number into tGreen
900- put (element 3 of tComponentList) parsed as number into tBlue
901-
902- if tComponentCount is 4 then
903- put (element 4 of tComponentList) parsed as number into tAlpha
904- return color [tRed/255, tGreen/255, tBlue/255, tAlpha/255]
905- else
906- return color [tRed/255, tGreen/255, tBlue/255]
907- end if
908-
909- end handler
910-
911- -- this handler converts an RGBA color to a string of numbers
912- private handler colorToString(in pColor as Color) returns String
913-
914- variable tRed as String
915- variable tGreen as String
916- variable tBlue as String
917- variable tAlpha as String
918-
919- put stripZeros((the rounded of ((the red of pColor) * 255)) formatted as string) into tRed
920- put stripZeros((the rounded of ((the green of pColor) * 255)) formatted as string) into tGreen
921- put stripZeros((the rounded of ((the blue of pColor) * 255)) formatted as string) into tBlue
922- put stripZeros((the rounded of ((the alpha of pColor) * 255)) formatted as string) into tAlpha
923-
924- if tAlpha is "255" then
925- return tRed & "," & tGreen & "," & tBlue
926- else
927- return tRed & "," & tGreen & "," & tBlue & "," & tAlpha
928- end if
929-
930- end handler
931-
932- -- this handler strips the zeros when a integer is formatted as a string
933- private handler stripZeros(in tString as String) returns String
934- if tString contains "." then
935- variable tCount as Integer
936- repeat while ((the last char of tString) is in ".0")
937- if the last char of tString is "." then
938- delete the last char of tString
939- exit repeat
940- else
941- delete the last char of tString
942- end if
943- end repeat
944- end if
945- return tString
946- end handler
947-
948829end widget
0 commit comments