forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.lcb
More file actions
1163 lines (887 loc) · 34 KB
/
Copy pathheader.lcb
File metadata and controls
1163 lines (887 loc) · 34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2015 Runtime Revolution Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
/*
This widget is a header bar.
Name: headerAction
Type: message
Syntax: on headerAction <pName>
Summary: Sent when one of the <headerActions> icons is clicked.
Parameters:
pName: The name of the header action that was clicked.
Description:
Use the <headerAction> message to perform an action when one of the action icons is
clicked by the user.
References: headerActions (property)
Name: leftAction
Type: message
Syntax: on leftAction
Summary: Sent when the <leftLabel> of the header bar is clicked.
Description:
Use the leftAction message to perform an action when the label at the left hand side
of the header bar is clicked.
References: leftLabel (property)
Name: searchAction
Type: message
Syntax: on searchAction
Summary: Sent when the search icon of the header bar is clicked.
Description:
Use the searchAction message to perform an action when the search icon is clicked. Whether
the search icon is visible or not is controlled by the <showSearchIcon> property.
References: showSearchIcon (property)
*/
-- declaring the extension as a widget, followed by identifier
widget com.livecode.widget.headerBar
-- dependency declarations
use com.livecode.canvas
use com.livecode.widget
use com.livecode.engine
use com.livecode.library.iconSVG
-- metadata
metadata title is "Header"
metadata author is "LiveCode"
metadata version is "1.0.0"
metadata preferredSize is "320,64"
metadata svgicon is "M0,0v29.5h80.2V0H0z M13.2,20.6l-1.8,1.8l-7.5-7.5l0.1-0.1l-0.1-0.1l7.5-7.5l1.8,1.8l-5.8,5.8L13.2,20.6z M31.2,10.9h-3.8v10.3h-2.6V10.9H21V8.7h10.2V10.9z M34.7,21.2h-2.5v-9.3h2.5V21.2z M34.7,10.8h-2.5V8.6h2.5V10.8z M41.3,13.7h-1.5v4.9c0,0.4,0,0.6,0.1,0.7c0.1,0.1,0.4,0.1,0.9,0.1c0.1,0,0.2,0,0.2,0s0.2,0,0.2,0v1.8l-1.1,0c-1.1,0-1.9-0.2-2.3-0.6c-0.3-0.3-0.4-0.7-0.4-1.3v-5.7h-1.3V12h1.3V9.4h2.4V12h1.5V13.7z M45.4,21.2h-2.4V8.7h2.4V21.2z M56.2,17.3h-6.8c0,0.9,0.4,1.6,1,2c0.4,0.2,0.8,0.3,1.3,0.3c0.6,0,1-0.1,1.3-0.4c0.2-0.2,0.4-0.4,0.5-0.6h2.5c-0.1,0.6-0.4,1.1-0.9,1.7c-0.8,0.9-2,1.4-3.5,1.4c-1.2,0-2.3-0.4-3.3-1.1c-0.9-0.8-1.4-2-1.4-3.7c0-1.6,0.4-2.8,1.3-3.7c0.9-0.9,2-1.3,3.3-1.3c0.8,0,1.5,0.1,2.2,0.4c0.6,0.3,1.2,0.7,1.6,1.4c0.4,0.6,0.6,1.2,0.7,1.9c0,0,0,0.1,0,0.1h-2.5c-0.1-0.6-0.3-1-0.6-1.4c-0.4-0.3-0.9-0.5-1.4-0.5c-0.6,0-1.1,0.2-1.4,0.5c-0.3,0.4-0.6,0.8-0.6,1.4h3.1h1.1h2.5C56.2,16.1,56.2,16.6,56.2,17.3z M76.1,16.2h-4.6v4.6h-3v-4.6h-4.6v-3h4.6V8.7h3v4.6h4.6V16.2z"
-- property declarations
/*
Summary: Sets the title of the header bar
Syntax: set the headerTitle of <widget> to <pTitle>
Syntax: get the headerTitle of <widget>
Parameters:
pTitle (string): The text of the title of the header bar.
Description:
Sets the title of the header bar to any string.
*/
property headerTitle get mHeaderTitle set setHeaderTitle
metadata headerTitle.default is "Title"
metadata headerTitle.label is "Title"
/*
Summary: Sets the subtitle of the header bar
Syntax: set the headerSubtitle of <widget> to <pSubtitle>
Syntax: get the headerSubtitle of <widget>
Parameters:
pSubtitle (string): The text of the subtitle of the header bar.
Description:
Sets the subtitle of the header bar to any string.
*/
property headerSubtitle get mHeaderSubtitle set setHeaderSubtitle
metadata headerSubtitle.default is "Subtitle"
metadata headerSubtitle.label is "Subtitle"
/*
Summary: Sets the label at the left hand side of the header
Syntax: set the leftLabel of <widget> to <pLabel>
Syntax: get the leftLabel of <widget>
Parameters:
pLabel (string): the label at the left hand side of the header
Description:
Sets the label at the left hand side of the header.
*/
property leftLabel get mLeftLabel set setLeftLabel
metadata leftLabel.default is "Back"
metadata leftLabel.label is "Left Label"
/*
Summary: Sets the actions of the header bar
Syntax: set the headerActions of <widget> to <pActions>
Syntax: get the headerActions of <widget>
Parameters:
pActions (list): The list of actions.
Description:
Sets the actions of the header bar from pActions, where pActions is a line delimited list of the actions, where each line is a comma delimited list
of the different components of the action: name, label, icon
*/
property headerActions get getHeaderActions set setHeaderActions
metadata headerActions.editor is "com.livecode.pi.navbar"
metadata headerActions.label is "Header Actions"
/*
Summary: Sets the action names of the header bar
Syntax: set the actionNames of <widget> to <pNames>
Syntax: get the actionNames of <widget>
Parameters:
pNames (list): The list of names.
Description:
Sets the names of the header bar actions, where <pNames> is a comma delimited list of the names.
*/
property actionNames get getActionNames set setActionNames
metadata actionNames.user_visible is "false"
/*
Summary: Sets the action labels of the header bar
Syntax: set the actionLabels of <widget> to <pLabels>
Syntax: get the actionLabels of <widget>
Parameters:
pLabels (list): The list of labels.
Description:
Sets the labels of the header bar actions, where <pLabels> is a comma delimited list of the labels.
*/
property actionLabels get getActionLabels set setActionLabels
metadata actionLabels.user_visible is "false"
/*
Summary: Sets the action icons of the header bar
Syntax: set the actionIcons of <widget> to <pIcons>
Syntax: get the actionIcons of <widget>
Parameters:
pIcons (list): The list of icons.
Description:
Sets the icons of the header bar actions, where <pIcons> is a comma delimited list of the icon names.
*/
property actionIcons get getActionIcons set setActionIcons
metadata actionIcons.user_visible is "false"
/*
Summary: Sets the header actions display style.
Syntax: set the actionStyle of <widget> to <pActionStyle>
Syntax: get the actionStyle of <widget>
Parameters:
pActionStyle (enum): The style of the header actions display.
-"icons": Show the icons
-"names": Show the names
Description:
Sets the header actions display style of the control.
*/
property actionStyle get mActionStyle set setActionStyle
metadata actionStyle.editor is "com.livecode.pi.enum"
metadata actionStyle.options is "icons,names"
metadata actionStyle.default is "icons"
metadata actionStyle.label is "Action Display Style"
/*
Summary: Controls whether the back icon is displayed.
Syntax: set the showBackIcon of <widget> to <pShow>
Syntax: get the showBackIcon of <widget>
Parameters:
pShow (boolean): True or false
Description:
Sets whether the back icon is showing or not.
*/
property showBackIcon get mShowBackIcon set setShowBackIcon
metadata showBackIcon.editor is "com.livecode.pi.boolean"
metadata showBackIcon.default is "true"
metadata showBackIcon.label is "Show Back Icon"
/*
Summary: Sets whether there is a search icon in the header bar.
Syntax: set the showSearchIcon of <widget> to <pShow>
Syntax: get the showSearchIcon of <widget>
Parameters:
pShow (boolean): True or false
Description:
Controls whether the search icon is displayed in the header bar.
*/
property showSearchIcon get mShowSearchIcon set setShowSearchIcon
metadata showSearchIcon.editor is "com.livecode.pi.boolean"
metadata showSearchIcon.default is "false"
metadata showSearchIcon.label is "Show Search Icon"
/*
Summary: Sets the color of the actions and the back button.
Syntax: set the actionColor of <widget> to <pColor>
Syntax: get the actionColor of <widget>
Parameters:
pColor (color): The color of the actions and back button
Description:
Sets the color of the actions and the back button.
*/
property actionColor get getActionColor set setActionColor
metadata actionColor.editor is "com.livecode.pi.color"
metadata actionColor.default is "0,121,255"
metadata actionColor.label is "Action Color"
/*
Syntax: set the <opaqueBackground> of <widget> to {true | false}
Syntax: get the <opaqueBackground> of <widget>
Summary: Whether the background of the header bar is drawn opaque or not
Description:
Use the <opaqueBackground> property to determine whether objects underneath the header bar are visible or not.
*/
property opaqueBackground get mOpaque set setOpaque
metadata opaqueBackground.default is "true"
metadata opaqueBackground.label is "Opaque Background"
/*
Syntax: set the <showDivide> of <widget> to {true | false}
Syntax: get the <showDivide> of <widget>
Summary: Whether the dividing line at the top of the header bar is drawn or not
Description:
Use the <showDivide> property to determine whether the dividing line at the top of the header bar is drawn or not.
*/
property showDivide get mShowDivide set setShowDivide
metadata showDivide.default is "true"
metadata showDivide.label is "Show Divide"
-- private instance variables
private variable mHeaderTitle as String
private variable mHeaderSubtitle as String
private variable mHeaderActions as List
private variable mActionStyle as String
private variable mShowBackIcon as Boolean
private variable mLeftLabel as String
private variable mActionColor as Color
private variable mShowSearchIcon as Boolean
private variable mShowLeftLabel as Boolean
private variable mShowSubtitle as Boolean
private variable mIconColor as Color
private variable mTitleRatio as Real
private variable mTitleVAdjust as Real
private variable mIconTop as Real
private variable mIconBottom as Real
private variable mIconWidth as Real
private variable mLabelTop as Real
private variable mLabelBottom as Real
private variable mSubtitleCenter as Real
private variable mSelectedAction as Integer
private variable mRight as Real
private variable mLetterCount as Integer
private variable mActionRects as List
private variable mOpaque as Boolean
private variable mShowDivide as Boolean
-- constants (some defined as varibales)
private variable kBackgroundColor as List
private variable kBlackColor as List
constant kMargin is 8
constant kActionRatio is 0.265625
constant kSubtitleRatio is 0.171875
public handler OnSave(out rProperties as Array)
put the empty array into rProperties
put mHeaderTitle into rProperties["headerTitle"]
put mHeaderSubtitle into rProperties["headerSubtitle"]
put getHeaderActions() into rProperties["headerActions"]
put mActionStyle into rProperties["actionStyle"]
put mShowBackIcon into rProperties["showBackIcon"]
put mLeftLabel into rProperties["leftLabel"]
put getActionColor() into rProperties["actionColor"]
put mShowSearchIcon into rProperties["showSearchIcon"]
return rProperties
end handler
public handler OnLoad(in pProperties as Array)
put pProperties["headerTitle"] into mHeaderTitle
put pProperties["headerSubtitle"] into mHeaderSubtitle
setHeaderActions(pProperties["headerActions"])
put pProperties["actionStyle"] into mActionStyle
put pProperties["showBackIcon"] into mShowBackIcon
put pProperties["leftLabel"] into mLeftLabel
setActionColor(pProperties["actionColor"])
put pProperties["showSearchIcon"] into mShowSearchIcon
end handler
public handler OnCreate()
-- creating a list of actions
variable tHeaderActions as List
put the empty list into tHeaderActions
variable tArray as Array
put the empty array into tArray
put "add" into tArray["name"]
put "Add" into tArray["label"]
put "plus" into tArray["icon_name"]
put "" into tArray["selected_icon_name"]
put "" into tArray["icon"]
push tArray onto tHeaderActions
put tHeaderActions into mHeaderActions
-- properties
put "Yesterday" into mHeaderTitle
put "" into mHeaderSubtitle
put "icons" into mActionStyle
put true into mShowBackIcon
put "Back" into mLeftLabel
put color [0, 121/255, 1] into mActionColor
put true into mShowSearchIcon
-- variables
put false into mShowLeftLabel
put false into mShowSubtitle
put 0 into mSelectedAction
put 0 into mRight
put 0 into mLetterCount
-- constants (defined as variables)
put [247/255,247/255,247/255] into kBackgroundColor
put [0,0,0] into kBlackColor
put true into mOpaque
put true into mShowDivide
end handler
public handler OnPaint()
updateVariables()
-- draw the background rectangle
if mOpaque then
set the paint of this canvas to fetchPaint("background")
fill fetchPath("background") on this canvas
end if
-- draw the bottom line
if mShowDivide then
set the paint of this canvas to fetchPaint("line")
fill fetchPath("line") on this canvas
end if
-- filling in the text of the title
set the font of this canvas to fetchFont("title")
set the paint of this canvas to fetchPaint("title")
fill text mHeaderTitle at center of fetchRect("title") on this canvas
-- fill in the text of the subtitle
if mShowSubtitle is true then
set the font of this canvas to fetchFont("subtitle")
set the paint of this canvas to fetchPaint("title")
fill text mHeaderSubtitle at center of fetchRect("subtitle") on this canvas
end if
-- drawing the back button
set the paint of this canvas to fetchPaint("backButton")
if mShowBackIcon is true then
fill fetchPath("backIcon") on this canvas
end if
if mShowLeftLabel is true then
set the font of this canvas to fetchFont("label")
fill text mLeftLabel at left of fetchRect("leftLabel") on this canvas
end if
-- draw the actions
if mHeaderActions is not the empty list then
variable tX as Integer
variable tActionsCount as Integer
put the number of elements in mHeaderActions into tActionsCount
repeat with tX from 1 up to tActionsCount
if tX+2 is mSelectedAction then
set the paint of this canvas to solid paint with color [the red of mActionColor, the green of mActionColor, the blue of mActionColor, 0.5]
else
set the paint of this canvas to solid paint with mActionColor
end if
if mActionStyle is "icons" then
drawActionIcon(mHeaderActions[tX]["icon_name"])
else if mActionStyle is "names" then
drawActionName(mHeaderActions[tX]["label"])
end if
end repeat
end if
-- draw the search icon
if mShowSearchIcon is true then
set the paint of this canvas to fetchPaint("searchIcon")
fill fetchPath("searchIcon") on this canvas
end if
end handler
public handler OnMouseDown()
-- the icons change color when they are pressed down
variable tSelectedDown as Integer
put fetchSelectedItem() into tSelectedDown
if tSelectedDown > 0 then
put tSelectedDown into mSelectedAction
redraw all
end if
end handler
public handler OnMouseUp()
-- the icons change back to their original colors on mouse up
put 0 into mSelectedAction
redraw all
-- the relevant commands are dispatched to the script object
variable tSelectedUp as Integer
put fetchSelectedItem() into tSelectedUp
if tSelectedUp > 2 then
variable tActionCount as Integer
variable tNumActions as Integer
put the number of elements in element 1 of mHeaderActions into tNumActions
repeat with tActionCount from 1 up to tNumActions
if tActionCount is tSelectedUp-2 then
post "headerAction" with [mHeaderActions[tActionCount]["name"]]
end if
end repeat
else if tSelectedUp = 1 then
post "leftAction"
else if tSelectedUp = 2 then
post "searchAction"
end if
end handler
private handler updateVariables() returns nothing
if mHeaderSubtitle is empty then
put false into mShowSubtitle
else
put true into mShowSubtitle
end if
if mShowSubtitle is false then
put 17/64 into mTitleRatio
else
put 15/64 into mTitleRatio
end if
if mLeftLabel is empty then
put false into mShowLeftLabel
else
put true into mShowLeftLabel
end if
variable tH
put my height into tH
put 2*tH/64 into mTitleVAdjust
put tH*(30.5/64) into mIconTop
put tH*(51.5/64) into mIconBottom
put tH*(13/64) into mIconWidth
put tH*(9/64) into mLabelTop
put tH*(73/64) into mLabelBottom
put tH*(43/64) into mSubtitleCenter
put (my width - kMargin) into mRight
put 0 into mLetterCount
put the empty list into mActionRects
end handler
private handler drawActionIcon(in pIconName as String) returns nothing
variable tIconPath as Path
variable tIconRect as Rectangle
put path iconSVGPathFromName(pIconName) into tIconPath
put fetchRect("actionIcon") into tIconRect
setIconPath(tIconRect, tIconPath)
fill tIconPath on this canvas
push tIconRect onto back of mActionRects
end handler
private handler drawActionName(in pActionLabel as String) returns nothing
put the number of chars in pActionLabel into mLetterCount
variable tActionRect as Rectangle
put fetchRect("actionLabel") into tActionRect
set the font of this canvas to fetchFont("label")
fill text pActionLabel at right of tActionRect on this canvas
push tActionRect onto back of mActionRects
end handler
private handler setIconPath(in pTargetRect as Rectangle, inout xPath as Path)
-- Scale the icon
variable tBounds
put the bounding box of xPath into tBounds
-- Scale appropriately
variable tXScale as Real
variable tYScale as Real
put the width of pTargetRect / the width of tBounds into tXScale
put the height of pTargetRect / the height of tBounds into tYScale
if tXScale > tYScale then
put tYScale into tXScale
else
put tXScale into tYScale
end if
scale xPath by [tXScale, tYScale]
variable tXTranslate as Real
variable tYTranslate as Real
put the bounding box of xPath into tBounds
put the left of pTargetRect - the left of tBounds into tXTranslate
put the top of pTargetRect - the top of tBounds into tYTranslate
variable tXDiff as Real
variable tYDiff as Real
put the width of pTargetRect - the width of tBounds into tXDiff
put the height of pTargetRect - the height of tBounds into tYDiff
-- align center
divide tXDiff by 2
divide tYDiff by 2
translate xPath by [tXTranslate + tXDiff, tYTranslate + tYDiff]
end handler
private handler fetchPath(in pObject as String) returns Path
variable tIconPath as Path
variable tIconRect as Rectangle
variable tH as Real
variable tW as Real
put my width into tW
put my height into tH
if pObject is "background" then
return rectangle path of rectangle [0, 0, tW, tH-1]
else if pObject is "line" then
return rectangle path of rectangle [0, tH-1, tW, tH]
else if pObject is "backIcon" then
put path iconSVGPathFromName("angle left") into tIconPath
put rectangle [kMargin, mLabelTop, kMargin + mIconWidth, mLabelBottom] into tIconRect
setIconPath(tIconRect, tIconPath)
return tIconPath
else if pObject is "searchIcon" then
variable tLeft as Real
variable tRight as Real
if mHeaderActions is empty then
put tW - kMargin into tRight
else
if mActionStyle is "icons" then
put mRight into tRight
else
put mRight - kMargin into tRight
end if
end if
put tRight - mIconWidth into tLeft
put path iconSVGPathFromName("search") into tIconPath
put rectangle [tLeft-mIconWidth/4, mLabelTop-mIconWidth/4, tRight+mIconWidth/4, mLabelBottom+mIconWidth/4] into tIconRect
setIconPath(tIconRect, tIconPath)
return tIconPath
end if
end handler
private handler fetchRect(in pObject as String) returns Rectangle
variable tRect as Rectangle
variable tLeft as Real
variable tTop as Real
variable tRight as Real
variable tBottom as Real
variable tH as Real
variable tSize as Real
put my height into tH
put tH*kActionRatio/2 into tSize
if pObject is "title" then
if mShowSubtitle is false then
return rectangle [0, mLabelTop-mTitleVAdjust, my width, mLabelBottom-mTitleVAdjust]
else
put mSubtitleCenter-tH*mTitleRatio-kMargin/2 into tTop
put mSubtitleCenter-kMargin/2 into tBottom
return rectangle [0, tTop, my width, tBottom]
end if
else if pObject is "subtitle" then
put kMargin/2 + mSubtitleCenter into tTop
put kMargin/2 + mSubtitleCenter + tH*kSubtitleRatio into tBottom
return rectangle [0, tTop, my width, tBottom]
else if pObject is "leftLabel" then
if mShowBackIcon is true then
put 3*kMargin/2 + mIconWidth into tLeft
else
put kMargin into tLeft
end if
return rectangle [tLeft, mLabelTop, my width, mLabelBottom]
else if pObject is "actionIcon" then
put rectangle [mRight-5*mIconWidth/4, mLabelTop-mIconWidth/4, mRight+mIconWidth/4, mLabelBottom+mIconWidth/4] into tRect
put (mRight - 5*mIconWidth/4 - 2*kMargin) into mRight
return tRect
else if pObject is "actionLabel" then
put rectangle [mRight - mLetterCount*tSize, mLabelTop, mRight, mLabelBottom] into tRect
put (mRight - mLetterCount*tSize - kMargin) into mRight
return tRect
end if
end handler
private handler fetchPaint(in pObject as String) returns Paint
variable tPaint as Paint
if pObject is "background" then
put solid paint with color kBackgroundColor into tPaint
else if pObject is "line" then
put solid paint with color [0, 0, 0, 0.2] into tPaint
else if pObject is "title" then
put solid paint with color kBlackColor into tPaint
else if pObject is "backButton" then
if mSelectedAction is 1 then
put solid paint with color [the red of mActionColor, the green of mActionColor, the blue of mActionColor, 0.5] into tPaint
else
put solid paint with mActionColor into tPaint
end if
else if pObject is "searchIcon" then
if mSelectedAction is 2 then
put solid paint with color [the red of mActionColor, the green of mActionColor, the blue of mActionColor, 0.5] into tPaint
else
put solid paint with mActionColor into tPaint
end if
end if
return tPaint
end handler
private handler fetchFont(in pType as String) returns Font
variable tSize as Number
variable tFont as String
if pType is "title" then
put (my height)*mTitleRatio into tSize
put "Helvetica Neue Medium" into tFont
else if pType is "subtitle" then
put (my height)*kSubtitleRatio into tSize
put "Helvetica Neue Regular" into tFont
else if pType is "label" then
put (my height)*kActionRatio into tSize
put "Helvetica Neue Regular" into tFont
end if
return font tFont at size tSize
end handler
private handler fetchSelectedItem() returns Integer
variable tSelected as Integer
variable tBackRect as Rectangle
variable tSearchRect as Rectangle
put fetchBackRect() into tBackRect
put fetchSearchRect() into tSearchRect
variable tClick as Point
put the click position into tClick
if tClick is within tBackRect then
put 1 into tSelected
else if tClick is within tSearchRect then
put 2 into tSelected
else
put locToAction(tClick) into tSelected
end if
return tSelected
end handler
private handler fetchBackRect() returns Rectangle
variable tBackRect as Rectangle
if mShowLeftLabel is true then
variable tLetterCount as Integer
variable tSize as Real
variable tWidth as Real
put the number of chars in mLeftLabel into tLetterCount
put (my height)*kActionRatio/2 into tSize
put tLetterCount*tSize into tWidth
end if
if mShowBackIcon is true and mShowLeftLabel is false then
put rectangle [kMargin, mLabelTop, kMargin + mIconWidth, mLabelBottom] into tBackRect
else if mShowBackIcon is false and mShowLeftLabel is true then
put rectangle [kMargin, mLabelTop, kMargin + tWidth, mLabelBottom] into tBackRect
else if mShowBackIcon is true and mShowLeftLabel is true then
put rectangle [kMargin, mLabelTop, kMargin + mIconWidth + tWidth, mLabelBottom] into tBackRect
else
put rectangle [0,0,0,0] into tBackRect
end if
return tBackRect
end handler
private handler fetchSearchRect() returns Rectangle
variable tSearchRect as Rectangle
if mShowSearchIcon is true then
put rectangle [mRight - mIconWidth - kMargin, mLabelTop, mRight - kMargin, mLabelBottom] into tSearchRect
else
put rectangle [0,0,0,0] into tSearchRect
end if
return tSearchRect
end handler
private handler locToAction(in pLoc as Point) returns Integer
variable tX as Integer
repeat with tX from 1 up to the number of elements in mActionRects
if pLoc is within (element tX of mActionRects) then
return (tX + 2)
end if
end repeat
return 0
end handler
-- this handler converts an RGBA color to a string
private handler colorToString(in pColor as Color) returns String
variable tRed as Integer
variable tGreen as Integer
variable tBlue as Integer
variable tAlpha as Integer
put the rounded of ((the red of pColor)*255) into tRed
put the rounded of ((the green of pColor)*255) into tGreen
put the rounded of ((the blue of pColor)*255) into tBlue
put the rounded of ((the alpha of pColor)*255) into tAlpha
return stripZeros(tRed formatted as string) & "," & stripZeros(tGreen formatted as string) & \
"," & stripZeros(tBlue formatted as string) & "," & stripZeros(tAlpha formatted as string)
end handler
--
-- this handler converts a string to an RGBA color
private handler stringToColor(in pString as String) returns Color
variable tStringList as List
variable tColorList as List
variable tComponent
split pString by "," into tStringList
put the empty list into tColorList
variable tComponentCount
put the number of elements in tStringList into tComponentCount
if tComponentCount is not 3 and tComponentCount is not 4 then
-- Invalid number of components detected
throw "Invalid color"
end if
repeat for each element tComponent in tStringList
push (tComponent parsed as number)/255 onto back of tColorList
end repeat
return color tColorList
end handler
--
-- this handler strips the zeros when an integer is formatted as a string
private handler stripZeros(in pString as String) returns String
if pString contains "." then
repeat while ((the last char of pString) is in ".0")
if the last char of pString is "." then
delete the last char of pString
exit repeat
else
delete the last char of pString
end if
end repeat
end if
return pString
end handler
--
-- this handler returns an array of the default action
private handler defaultActionsArray() returns Array
variable tArray as Array
put the empty array into tArray
put "action" into tArray["name"]
put "Action" into tArray["label"]
put "circle"into tArray["icon_name"]
return tArray
end handler
--
--------------------------------------------------------------------------------
--
-- Get Handlers
--
--------------------------------------------------------------------------------
-- this handler converts mHeaderActions into a form for output in the PI
private handler getHeaderActions() returns Array
return listToArray(mHeaderActions)
end handler
private handler getActionNames() returns String
return getDataElement("name", mHeaderActions)
end handler
private handler getActionLabels() returns String
return getDataElement("label", mHeaderActions)
end handler
private handler getActionIcons() returns String
return getDataElement("icon_name", mHeaderActions)
end handler
-- these handlers convert the color properties for output in the PI
private handler getActionColor() returns String
return colorToString(mActionColor)
end handler
--------------------------------------------------------------------------------
--
-- Set Handlers
--
--------------------------------------------------------------------------------
private handler setHeaderTitle(in pTitle as String) returns nothing
put pTitle into mHeaderTitle
redraw all
end handler
private handler setHeaderSubtitle(in pSubtitle as String) returns nothing
put pSubtitle into mHeaderSubtitle
redraw all
end handler
-- this handler sets the actions, converting from a string to the correct format
private handler setHeaderActions(in pActions as Array) returns nothing
setData(pActions, the keys of defaultActionsArray(), mHeaderActions)
redraw all
end handler
private handler setActionNames(in pNames as String) returns nothing
setPrimaryDataElement("name", pNames, defaultActionsArray(), mHeaderActions)
redraw all
end handler
private handler setActionLabels(in pLabels as String) returns nothing
setDataElement("label", pLabels, defaultActionsArray(), mHeaderActions)
redraw all
end handler
private handler setActionIcons(in pIcons as String) returns nothing
setDataElement("icon_name", pIcons, defaultActionsArray(), mHeaderActions)
redraw all
end handler
private handler setActionSelectedIcons(in pSelectedIcons as String) returns nothing
setDataElement("selected_icon_name", pSelectedIcons, defaultActionsArray(), mHeaderActions)
redraw all
end handler
private handler setActionStyle(in pActionStyle as String) returns nothing
put pActionStyle into mActionStyle
redraw all
end handler
private handler setShowBackIcon(in pShow as Boolean) returns nothing
put pShow into mShowBackIcon
redraw all
end handler
private handler setLeftLabel(in pLabel as String) returns nothing
put pLabel into mLeftLabel
redraw all
end handler