forked from gen2brain/raylib-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raygui.go
1089 lines (945 loc) · 45.8 KB
/
raygui.go
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
// Package raygui - Simple and easy-to-use IMGUI (immediate mode GUI API) library
package raygui
import (
"bufio"
"fmt"
"io/ioutil"
"strconv"
"strings"
"github.com/gen2brain/raylib-go/raylib"
)
// Property - GUI property
type Property int32
// GUI properties enumeration
const (
GlobalBaseColor Property = iota
GlobalBorderColor
GlobalTextColor
GlobalTextFontsize
GlobalBorderWidth
GlobalBackgroundColor
GlobalLinesColor
LabelBorderWidth
LabelTextColor
LabelTextPadding
ButtonBorderWidth
ButtonTextPadding
ButtonDefaultBorderColor
ButtonDefaultInsideColor
ButtonDefaultTextColor
ButtonHoverBorderColor
ButtonHoverInsideColor
ButtonHoverTextColor
ButtonPressedBorderColor
ButtonPressedInsideColor
ButtonPressedTextColor
ToggleTextPadding
ToggleBorderWidth
ToggleDefaultBorderColor
ToggleDefaultInsideColor
ToggleDefaultTextColor
ToggleHoverBorderColor
ToggleHoverInsideColor
ToggleHoverTextColor
TogglePressedBorderColor
TogglePressedInsideColor
TogglePressedTextColor
ToggleActiveBorderColor
ToggleActiveInsideColor
ToggleActiveTextColor
TogglegroupPadding
SliderBorderWidth
SliderButtonBorderWidth
SliderBorderColor
SliderInsideColor
SliderDefaultColor
SliderHoverColor
SliderActiveColor
SliderbarBorderColor
SliderbarInsideColor
SliderbarDefaultColor
SliderbarHoverColor
SliderbarActiveColor
SliderbarZeroLineColor
ProgressbarBorderColor
ProgressbarInsideColor
ProgressbarProgressColor
ProgressbarBorderWidth
SpinnerLabelBorderColor
SpinnerLabelInsideColor
SpinnerDefaultButtonBorderColor
SpinnerDefaultButtonInsideColor
SpinnerDefaultSymbolColor
SpinnerDefaultTextColor
SpinnerHoverButtonBorderColor
SpinnerHoverButtonInsideColor
SpinnerHoverSymbolColor
SpinnerHoverTextColor
SpinnerPressedButtonBorderColor
SpinnerPressedButtonInsideColor
SpinnerPressedSymbolColor
SpinnerPressedTextColor
ComboboxPadding
boundsWidth
boundsHeight
ComboboxBorderWidth
ComboboxDefaultBorderColor
ComboboxDefaultInsideColor
ComboboxDefaultTextColor
ComboboxDefaultListTextColor
ComboboxHoverBorderColor
ComboboxHoverInsideColor
ComboboxHoverTextColor
ComboboxHoverListTextColor
ComboboxPressedBorderColor
ComboboxPressedInsideColor
ComboboxPressedTextColor
ComboboxPressedListBorderColor
ComboboxPressedListInsideColor
ComboboxPressedListTextColor
CheckboxDefaultBorderColor
CheckboxDefaultInsideColor
CheckboxHoverBorderColor
CheckboxHoverInsideColor
CheckboxClickBorderColor
CheckboxClickInsideColor
CheckboxDefaultActiveColor
CheckboxInsideWidth
TextboxBorderWidth
TextboxBorderColor
TextboxInsideColor
TextboxTextColor
TextboxLineColor
TextboxTextFontsize
)
// GUI controls states
const (
Disabled = iota
Normal
Focused
Pressed
)
// Current GUI style (default light)
var style = []int64{
0xf5f5f5ff, // GLOBAL_BASE_COLOR
0xf5f5f5ff, // GLOBAL_BORDER_COLOR
0xf5f5f5ff, // GLOBAL_TEXT_COLOR
10, // GLOBAL_TEXT_FONTSIZE
1, // GLOBAL_BORDER_WIDTH
0xf5f5f5ff, // BACKGROUND_COLOR
0x90abb5ff, // LINES_COLOR
1, // LABEL_BORDER_WIDTH
0x4d4d4dff, // LABEL_TEXT_COLOR
20, // LABEL_TEXT_PADDING
2, // BUTTON_BORDER_WIDTH
20, // BUTTON_TEXT_PADDING
0x828282ff, // BUTTON_DEFAULT_BORDER_COLOR
0xc8c8c8ff, // BUTTON_DEFAULT_INSIDE_COLOR
0x4d4d4dff, // BUTTON_DEFAULT_TEXT_COLOR
0xc8c8c8ff, // BUTTON_HOVER_BORDER_COLOR
0xffffffff, // BUTTON_HOVER_INSIDE_COLOR
0x868686ff, // BUTTON_HOVER_TEXT_COLOR
0x7bb0d6ff, // BUTTON_PRESSED_BORDER_COLOR
0xbcecffff, // BUTTON_PRESSED_INSIDE_COLOR
0x5f9aa7ff, // BUTTON_PRESSED_TEXT_COLOR
20, // TOGGLE_TEXT_PADDING
1, // TOGGLE_BORDER_WIDTH
0x828282ff, // TOGGLE_DEFAULT_BORDER_COLOR
0xc8c8c8ff, // TOGGLE_DEFAULT_INSIDE_COLOR
0x828282ff, // TOGGLE_DEFAULT_TEXT_COLOR
0xc8c8c8ff, // TOGGLE_HOVER_BORDER_COLOR
0xffffffff, // TOGGLE_HOVER_INSIDE_COLOR
0x828282ff, // TOGGLE_HOVER_TEXT_COLOR
0xbdd7eaff, // TOGGLE_PRESSED_BORDER_COLOR
0xddf5ffff, // TOGGLE_PRESSED_INSIDE_COLOR
0xafccd3ff, // TOGGLE_PRESSED_TEXT_COLOR
0x7bb0d6ff, // TOGGLE_ACTIVE_BORDER_COLOR
0xbcecffff, // TOGGLE_ACTIVE_INSIDE_COLOR
0x5f9aa7ff, // TOGGLE_ACTIVE_TEXT_COLOR
3, // TOGGLEGROUP_PADDING
1, // SLIDER_BORDER_WIDTH
1, // SLIDER_BUTTON_BORDER_WIDTH
0x828282ff, // SLIDER_BORDER_COLOR
0xc8c8c8ff, // SLIDER_INSIDE_COLOR
0xbcecffff, // SLIDER_DEFAULT_COLOR
0xffffffff, // SLIDER_HOVER_COLOR
0xddf5ffff, // SLIDER_ACTIVE_COLOR
0x828282ff, // SLIDERBAR_BORDER_COLOR
0xc8c8c8ff, // SLIDERBAR_INSIDE_COLOR
0xbcecffff, // SLIDERBAR_DEFAULT_COLOR
0xffffffff, // SLIDERBAR_HOVER_COLOR
0xddf5ffff, // SLIDERBAR_ACTIVE_COLOR
0x828282ff, // SLIDERBAR_ZERO_LINE_COLOR
0x828282ff, // PROGRESSBAR_BORDER_COLOR
0xc8c8c8ff, // PROGRESSBAR_INSIDE_COLOR
0xbcecffff, // PROGRESSBAR_PROGRESS_COLOR
2, // PROGRESSBAR_BORDER_WIDTH
0x828282ff, // SPINNER_LABEL_BORDER_COLOR
0xc8c8c8ff, // SPINNER_LABEL_INSIDE_COLOR
0x828282ff, // SPINNER_DEFAULT_BUTTON_BORDER_COLOR
0xc8c8c8ff, // SPINNER_DEFAULT_BUTTON_INSIDE_COLOR
0x000000ff, // SPINNER_DEFAULT_SYMBOL_COLOR
0x000000ff, // SPINNER_DEFAULT_TEXT_COLOR
0xc8c8c8ff, // SPINNER_HOVER_BUTTON_BORDER_COLOR
0xffffffff, // SPINNER_HOVER_BUTTON_INSIDE_COLOR
0x000000ff, // SPINNER_HOVER_SYMBOL_COLOR
0x000000ff, // SPINNER_HOVER_TEXT_COLOR
0x7bb0d6ff, // SPINNER_PRESSED_BUTTON_BORDER_COLOR
0xbcecffff, // SPINNER_PRESSED_BUTTON_INSIDE_COLOR
0x5f9aa7ff, // SPINNER_PRESSED_SYMBOL_COLOR
0x000000ff, // SPINNER_PRESSED_TEXT_COLOR
1, // COMBOBOX_PADDING
30, // COMBOBOX_BUTTON_WIDTH
20, // COMBOBOX_BUTTON_HEIGHT
1, // COMBOBOX_BORDER_WIDTH
0x828282ff, // COMBOBOX_DEFAULT_BORDER_COLOR
0xc8c8c8ff, // COMBOBOX_DEFAULT_INSIDE_COLOR
0x828282ff, // COMBOBOX_DEFAULT_TEXT_COLOR
0x828282ff, // COMBOBOX_DEFAULT_LIST_TEXT_COLOR
0xc8c8c8ff, // COMBOBOX_HOVER_BORDER_COLOR
0xffffffff, // COMBOBOX_HOVER_INSIDE_COLOR
0x828282ff, // COMBOBOX_HOVER_TEXT_COLOR
0x828282ff, // COMBOBOX_HOVER_LIST_TEXT_COLOR
0x7bb0d6ff, // COMBOBOX_PRESSED_BORDER_COLOR
0xbcecffff, // COMBOBOX_PRESSED_INSIDE_COLOR
0x5f9aa7ff, // COMBOBOX_PRESSED_TEXT_COLOR
0x0078acff, // COMBOBOX_PRESSED_LIST_BORDER_COLOR
0x66e7ffff, // COMBOBOX_PRESSED_LIST_INSIDE_COLOR
0x0078acff, // COMBOBOX_PRESSED_LIST_TEXT_COLOR
0x828282ff, // CHECKBOX_DEFAULT_BORDER_COLOR
0xffffffff, // CHECKBOX_DEFAULT_INSIDE_COLOR
0xc8c8c8ff, // CHECKBOX_HOVER_BORDER_COLOR
0xffffffff, // CHECKBOX_HOVER_INSIDE_COLOR
0x66e7ffff, // CHECKBOX_CLICK_BORDER_COLOR
0xddf5ffff, // CHECKBOX_CLICK_INSIDE_COLOR
0xbcecffff, // CHECKBOX_STATUS_ACTIVE_COLOR
1, // CHECKBOX_INSIDE_WIDTH
1, // TEXTBOX_BORDER_WIDTH
0x828282ff, // TEXTBOX_BORDER_COLOR
0xf5f5f5ff, // TEXTBOX_INSIDE_COLOR
0x000000ff, // TEXTBOX_TEXT_COLOR
0x000000ff, // TEXTBOX_LINE_COLOR
10, // TEXTBOX_TEXT_FONTSIZE
}
// GUI property names (to read/write style text files)
var propertyName = []string{
"GLOBAL_BASE_COLOR",
"GLOBAL_BORDER_COLOR",
"GLOBAL_TEXT_COLOR",
"GLOBAL_TEXT_FONTSIZE",
"GLOBAL_BORDER_WIDTH",
"BACKGROUND_COLOR",
"LINES_COLOR",
"LABEL_BORDER_WIDTH",
"LABEL_TEXT_COLOR",
"LABEL_TEXT_PADDING",
"BUTTON_BORDER_WIDTH",
"BUTTON_TEXT_PADDING",
"BUTTON_DEFAULT_BORDER_COLOR",
"BUTTON_DEFAULT_INSIDE_COLOR",
"BUTTON_DEFAULT_TEXT_COLOR",
"BUTTON_HOVER_BORDER_COLOR",
"BUTTON_HOVER_INSIDE_COLOR",
"BUTTON_HOVER_TEXT_COLOR",
"BUTTON_PRESSED_BORDER_COLOR",
"BUTTON_PRESSED_INSIDE_COLOR",
"BUTTON_PRESSED_TEXT_COLOR",
"TOGGLE_TEXT_PADDING",
"TOGGLE_BORDER_WIDTH",
"TOGGLE_DEFAULT_BORDER_COLOR",
"TOGGLE_DEFAULT_INSIDE_COLOR",
"TOGGLE_DEFAULT_TEXT_COLOR",
"TOGGLE_HOVER_BORDER_COLOR",
"TOGGLE_HOVER_INSIDE_COLOR",
"TOGGLE_HOVER_TEXT_COLOR",
"TOGGLE_PRESSED_BORDER_COLOR",
"TOGGLE_PRESSED_INSIDE_COLOR",
"TOGGLE_PRESSED_TEXT_COLOR",
"TOGGLE_ACTIVE_BORDER_COLOR",
"TOGGLE_ACTIVE_INSIDE_COLOR",
"TOGGLE_ACTIVE_TEXT_COLOR",
"TOGGLEGROUP_PADDING",
"SLIDER_BORDER_WIDTH",
"SLIDER_BUTTON_BORDER_WIDTH",
"SLIDER_BORDER_COLOR",
"SLIDER_INSIDE_COLOR",
"SLIDER_DEFAULT_COLOR",
"SLIDER_HOVER_COLOR",
"SLIDER_ACTIVE_COLOR",
"SLIDERBAR_BORDER_COLOR",
"SLIDERBAR_INSIDE_COLOR",
"SLIDERBAR_DEFAULT_COLOR",
"SLIDERBAR_HOVER_COLOR",
"SLIDERBAR_ACTIVE_COLOR",
"SLIDERBAR_ZERO_LINE_COLOR",
"PROGRESSBAR_BORDER_COLOR",
"PROGRESSBAR_INSIDE_COLOR",
"PROGRESSBAR_PROGRESS_COLOR",
"PROGRESSBAR_BORDER_WIDTH",
"SPINNER_LABEL_BORDER_COLOR",
"SPINNER_LABEL_INSIDE_COLOR",
"SPINNER_DEFAULT_BUTTON_BORDER_COLOR",
"SPINNER_DEFAULT_BUTTON_INSIDE_COLOR",
"SPINNER_DEFAULT_SYMBOL_COLOR",
"SPINNER_DEFAULT_TEXT_COLOR",
"SPINNER_HOVER_BUTTON_BORDER_COLOR",
"SPINNER_HOVER_BUTTON_INSIDE_COLOR",
"SPINNER_HOVER_SYMBOL_COLOR",
"SPINNER_HOVER_TEXT_COLOR",
"SPINNER_PRESSED_BUTTON_BORDER_COLOR",
"SPINNER_PRESSED_BUTTON_INSIDE_COLOR",
"SPINNER_PRESSED_SYMBOL_COLOR",
"SPINNER_PRESSED_TEXT_COLOR",
"COMBOBOX_PADDING",
"COMBOBOX_BUTTON_WIDTH",
"COMBOBOX_BUTTON_HEIGHT",
"COMBOBOX_BORDER_WIDTH",
"COMBOBOX_DEFAULT_BORDER_COLOR",
"COMBOBOX_DEFAULT_INSIDE_COLOR",
"COMBOBOX_DEFAULT_TEXT_COLOR",
"COMBOBOX_DEFAULT_LIST_TEXT_COLOR",
"COMBOBOX_HOVER_BORDER_COLOR",
"COMBOBOX_HOVER_INSIDE_COLOR",
"COMBOBOX_HOVER_TEXT_COLOR",
"COMBOBOX_HOVER_LIST_TEXT_COLOR",
"COMBOBOX_PRESSED_BORDER_COLOR",
"COMBOBOX_PRESSED_INSIDE_COLOR",
"COMBOBOX_PRESSED_TEXT_COLOR",
"COMBOBOX_PRESSED_LIST_BORDER_COLOR",
"COMBOBOX_PRESSED_LIST_INSIDE_COLOR",
"COMBOBOX_PRESSED_LIST_TEXT_COLOR",
"CHECKBOX_DEFAULT_BORDER_COLOR",
"CHECKBOX_DEFAULT_INSIDE_COLOR",
"CHECKBOX_HOVER_BORDER_COLOR",
"CHECKBOX_HOVER_INSIDE_COLOR",
"CHECKBOX_CLICK_BORDER_COLOR",
"CHECKBOX_CLICK_INSIDE_COLOR",
"CHECKBOX_STATUS_ACTIVE_COLOR",
"CHECKBOX_INSIDE_WIDTH",
"TEXTBOX_BORDER_WIDTH",
"TEXTBOX_BORDER_COLOR",
"TEXTBOX_INSIDE_COLOR",
"TEXTBOX_TEXT_COLOR",
"TEXTBOX_LINE_COLOR",
"TEXTBOX_TEXT_FONTSIZE",
}
// For spinner
var (
framesCounter int
framesCounter2 int
valueSpeed bool
)
// BackgroundColor - Get background color
func BackgroundColor() rl.Color {
return rl.GetColor(int32(style[GlobalBackgroundColor]))
}
// LinesColor - Get lines color
func LinesColor() rl.Color {
return rl.GetColor(int32(style[GlobalLinesColor]))
}
// TextColor - Get text color for normal state
func TextColor() rl.Color {
return rl.GetColor(int32(style[GlobalTextColor]))
}
// Label - Label element, show text
func Label(bounds rl.Rectangle, text string) {
LabelEx(bounds, text, rl.GetColor(int32(style[LabelTextColor])), rl.NewColor(0, 0, 0, 0), rl.NewColor(0, 0, 0, 0))
}
// LabelEx - Label element extended, configurable colors
func LabelEx(bounds rl.Rectangle, text string, textColor, border, inner rl.Color) {
b := bounds.ToInt32()
// Update control
textWidth := rl.MeasureText(text, int32(style[GlobalTextFontsize]))
textHeight := int32(style[GlobalTextFontsize])
if b.Width < textWidth {
b.Width = textWidth + int32(style[LabelTextPadding])
}
if b.Height < textHeight {
b.Height = textHeight + int32(style[LabelTextPadding])/2
}
// Draw control
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, border)
rl.DrawRectangle(b.X+int32(style[LabelBorderWidth]), b.Y+int32(style[LabelBorderWidth]), b.Width-(2*int32(style[LabelBorderWidth])), b.Height-(2*int32(style[LabelBorderWidth])), inner)
rl.DrawText(text, b.X+((b.Width/2)-(textWidth/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), textColor)
}
// Button - Button element, returns true when clicked
func Button(bounds rl.Rectangle, text string) bool {
b := bounds.ToInt32()
state := Normal
mousePoint := rl.GetMousePosition()
clicked := false
textWidth := rl.MeasureText(text, int32(style[GlobalTextFontsize]))
textHeight := int32(style[GlobalTextFontsize])
// Update control
if b.Width < textWidth {
b.Width = textWidth + int32(style[ButtonTextPadding])
}
if b.Height < textHeight {
b.Height = textHeight + int32(style[ButtonTextPadding])/2
}
if rl.CheckCollisionPointRec(mousePoint, bounds) {
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
state = Pressed
} else if rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton) {
clicked = true
} else {
state = Focused
}
}
// Draw control
switch state {
case Normal:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ButtonDefaultBorderColor])))
rl.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), rl.GetColor(int32(style[ButtonDefaultInsideColor])))
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ButtonDefaultTextColor])))
break
case Focused:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ButtonHoverBorderColor])))
rl.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), rl.GetColor(int32(style[ButtonHoverInsideColor])))
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ButtonHoverTextColor])))
break
case Pressed:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ButtonPressedBorderColor])))
rl.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), rl.GetColor(int32(style[ButtonPressedInsideColor])))
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ButtonPressedTextColor])))
break
default:
break
}
if clicked {
return true
}
return false
}
// ToggleButton - Toggle Button element, returns true when active
func ToggleButton(bounds rl.Rectangle, text string, active bool) bool {
b := bounds.ToInt32()
state := Normal
mousePoint := rl.GetMousePosition()
textWidth := rl.MeasureText(text, int32(style[GlobalTextFontsize]))
textHeight := int32(style[GlobalTextFontsize])
// Update control
if b.Width < textWidth {
b.Width = textWidth + int32(style[ToggleTextPadding])
}
if b.Height < textHeight {
b.Height = textHeight + int32(style[ToggleTextPadding])/2
}
if rl.CheckCollisionPointRec(mousePoint, bounds) {
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
state = Pressed
} else if rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton) {
state = Normal
active = !active
} else {
state = Focused
}
}
// Draw control
switch state {
case Normal:
if active {
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ToggleActiveBorderColor])))
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[ToggleActiveInsideColor])))
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ToggleDefaultTextColor])))
} else {
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ToggleDefaultBorderColor])))
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[ToggleDefaultInsideColor])))
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ToggleDefaultTextColor])))
}
break
case Focused:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ToggleHoverBorderColor])))
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[ToggleHoverInsideColor])))
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ToggleHoverTextColor])))
break
case Pressed:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[TogglePressedBorderColor])))
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[TogglePressedInsideColor])))
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[TogglePressedTextColor])))
break
default:
break
}
return active
}
// ToggleGroup - Toggle Group element, returns toggled button index
func ToggleGroup(bounds rl.Rectangle, toggleText []string, active int) int {
for i := 0; i < len(toggleText); i++ {
if i == active {
ToggleButton(rl.NewRectangle(bounds.X+float32(i)*(bounds.Width+float32(style[TogglegroupPadding])), bounds.Y, bounds.Width, bounds.Height), toggleText[i], true)
} else if ToggleButton(rl.NewRectangle(bounds.X+float32(i)*(bounds.Width+float32(style[TogglegroupPadding])), bounds.Y, bounds.Width, bounds.Height), toggleText[i], false) {
active = i
}
}
return active
}
// ComboBox - Combo Box element, returns selected item index
func ComboBox(bounds rl.Rectangle, comboText []string, active int) int {
b := bounds.ToInt32()
state := Normal
clicked := false
click := rl.NewRectangle(bounds.X+bounds.Width+float32(style[ComboboxPadding]), bounds.Y, float32(style[boundsWidth]), float32(style[boundsHeight]))
c := click.ToInt32()
mousePoint := rl.GetMousePosition()
textWidth := int32(0)
textHeight := int32(style[GlobalTextFontsize])
comboCount := len(comboText)
for i := 0; i < comboCount; i++ {
if i == active {
// Update control
textWidth = rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))
if b.Width < textWidth {
b.Width = textWidth + int32(style[ToggleTextPadding])
}
if b.Height < textHeight {
b.Height = textHeight + int32(style[ToggleTextPadding])/2
}
if rl.CheckCollisionPointRec(mousePoint, bounds) || rl.CheckCollisionPointRec(mousePoint, click) {
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
state = Pressed
} else if rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton) {
clicked = true
} else {
state = Focused
}
}
// Draw control
switch state {
case Normal:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ComboboxDefaultBorderColor])))
rl.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxDefaultInsideColor])))
rl.DrawRectangle(c.X, c.Y, c.Width, c.Height, rl.GetColor(int32(style[ComboboxDefaultBorderColor])))
rl.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxDefaultInsideColor])))
rl.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(rl.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxDefaultListTextColor])))
rl.DrawText(comboText[i], b.X+((b.Width/2)-(rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxDefaultTextColor])))
break
case Focused:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ComboboxHoverBorderColor])))
rl.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxHoverInsideColor])))
rl.DrawRectangle(c.X, c.Y, c.Width, c.Height, rl.GetColor(int32(style[ComboboxHoverBorderColor])))
rl.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxHoverInsideColor])))
rl.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(rl.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxHoverListTextColor])))
rl.DrawText(comboText[i], b.X+((b.Width/2)-(rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxHoverTextColor])))
break
case Pressed:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ComboboxPressedBorderColor])))
rl.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxPressedInsideColor])))
rl.DrawRectangle(c.X, c.Y, c.Width, c.Height, rl.GetColor(int32(style[ComboboxPressedListBorderColor])))
rl.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxPressedListInsideColor])))
rl.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(rl.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxPressedListTextColor])))
rl.DrawText(comboText[i], b.X+((b.Width/2)-(rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxPressedTextColor])))
break
default:
break
}
if clicked {
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ComboboxPressedBorderColor])))
rl.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxPressedInsideColor])))
rl.DrawRectangle(c.X, c.Y, c.Width, c.Height, rl.GetColor(int32(style[ComboboxPressedListBorderColor])))
rl.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxPressedListInsideColor])))
rl.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(rl.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxPressedListTextColor])))
rl.DrawText(comboText[i], b.X+((b.Width/2)-(rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxPressedTextColor])))
}
}
}
if rl.CheckCollisionPointRec(mousePoint, bounds) || rl.CheckCollisionPointRec(mousePoint, click) {
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
active++
if active >= comboCount {
active = 0
}
}
}
return active
}
// CheckBox - Check Box element, returns true when active
func CheckBox(bounds rl.Rectangle, checked bool) bool {
b := bounds.ToInt32()
state := Normal
mousePoint := rl.GetMousePosition()
// Update control
if rl.CheckCollisionPointRec(mousePoint, bounds) {
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
state = Pressed
} else if rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton) {
state = Normal
checked = !checked
} else {
state = Focused
}
}
// Draw control
switch state {
case Normal:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[CheckboxDefaultBorderColor])))
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[CheckboxDefaultInsideColor])))
break
case Focused:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[CheckboxHoverBorderColor])))
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[CheckboxHoverInsideColor])))
break
case Pressed:
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[CheckboxClickBorderColor])))
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[CheckboxClickInsideColor])))
break
default:
break
}
if checked {
rl.DrawRectangle(b.X+int32(style[CheckboxInsideWidth]), b.Y+int32(style[CheckboxInsideWidth]), b.Width-(2*int32(style[CheckboxInsideWidth])), b.Height-(2*int32(style[CheckboxInsideWidth])), rl.GetColor(int32(style[CheckboxDefaultActiveColor])))
}
return checked
}
// Slider - Slider element, returns selected value
func Slider(bounds rl.Rectangle, value, minValue, maxValue float32) float32 {
b := bounds.ToInt32()
sliderPos := float32(0)
state := Normal
buttonTravelDistance := float32(0)
mousePoint := rl.GetMousePosition()
// Update control
if value < minValue {
value = minValue
} else if value >= maxValue {
value = maxValue
}
sliderPos = (value - minValue) / (maxValue - minValue)
sliderButton := rl.RectangleInt32{}
sliderButton.Width = (b.Width-(2*int32(style[SliderButtonBorderWidth])))/10 - 8
sliderButton.Height = b.Height - (2 * int32(style[SliderBorderWidth]+2*style[SliderButtonBorderWidth]))
sliderButtonMinPos := b.X + int32(style[SliderBorderWidth]) + int32(style[SliderButtonBorderWidth])
sliderButtonMaxPos := b.X + b.Width - (int32(style[SliderBorderWidth]) + int32(style[SliderButtonBorderWidth]) + sliderButton.Width)
buttonTravelDistance = float32(sliderButtonMaxPos - sliderButtonMinPos)
sliderButton.X = b.X + int32(style[SliderBorderWidth]) + int32(style[SliderButtonBorderWidth]) + int32(sliderPos*buttonTravelDistance)
sliderButton.Y = b.Y + int32(style[SliderBorderWidth]) + int32(style[SliderButtonBorderWidth])
if rl.CheckCollisionPointRec(mousePoint, bounds) {
state = Focused
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
state = Pressed
}
if state == Pressed && rl.IsMouseButtonDown(rl.MouseLeftButton) {
sliderButton.X = int32(mousePoint.X) - sliderButton.Width/2
if sliderButton.X <= sliderButtonMinPos {
sliderButton.X = sliderButtonMinPos
} else if sliderButton.X >= sliderButtonMaxPos {
sliderButton.X = sliderButtonMaxPos
}
sliderPos = float32(sliderButton.X-sliderButtonMinPos) / buttonTravelDistance
}
} else {
state = Normal
}
// Draw control
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[SliderBorderColor])))
rl.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), rl.GetColor(int32(style[SliderInsideColor])))
switch state {
case Normal:
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderDefaultColor])))
break
case Focused:
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderHoverColor])))
break
case Pressed:
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderActiveColor])))
break
default:
break
}
return minValue + (maxValue-minValue)*sliderPos
}
// SliderBar - Slider Bar element, returns selected value
func SliderBar(bounds rl.Rectangle, value, minValue, maxValue float32) float32 {
b := bounds.ToInt32()
state := Normal
mousePoint := rl.GetMousePosition()
fixedValue := float32(0)
fixedMinValue := float32(0)
fixedValue = value - minValue
maxValue = maxValue - minValue
fixedMinValue = 0
// Update control
if fixedValue <= fixedMinValue {
fixedValue = fixedMinValue
} else if fixedValue >= maxValue {
fixedValue = maxValue
}
sliderBar := rl.RectangleInt32{}
sliderBar.X = b.X + int32(style[SliderBorderWidth])
sliderBar.Y = b.Y + int32(style[SliderBorderWidth])
sliderBar.Width = int32((fixedValue * (float32(b.Width) - 2*float32(style[SliderBorderWidth]))) / (maxValue - fixedMinValue))
sliderBar.Height = b.Height - 2*int32(style[SliderBorderWidth])
if rl.CheckCollisionPointRec(mousePoint, bounds) {
state = Focused
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
state = Pressed
sliderBar.Width = (int32(mousePoint.X) - b.X - int32(style[SliderBorderWidth]))
if int32(mousePoint.X) <= (b.X + int32(style[SliderBorderWidth])) {
sliderBar.Width = 0
} else if int32(mousePoint.X) >= (b.X + b.Width - int32(style[SliderBorderWidth])) {
sliderBar.Width = b.Width - 2*int32(style[SliderBorderWidth])
}
}
} else {
state = Normal
}
fixedValue = (float32(sliderBar.Width) * (maxValue - fixedMinValue)) / (float32(b.Width) - 2*float32(style[SliderBorderWidth]))
// Draw control
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[SliderbarBorderColor])))
rl.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), rl.GetColor(int32(style[SliderbarInsideColor])))
switch state {
case Normal:
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarDefaultColor])))
break
case Focused:
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarHoverColor])))
break
case Pressed:
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarActiveColor])))
break
default:
break
}
if minValue < 0 && maxValue > 0 {
rl.DrawRectangle((b.X+int32(style[SliderBorderWidth]))-int32(minValue*(float32(b.Width-(int32(style[SliderBorderWidth])*2))/maxValue)), sliderBar.Y, 1, sliderBar.Height, rl.GetColor(int32(style[SliderbarZeroLineColor])))
}
return fixedValue + minValue
}
// ProgressBar - Progress Bar element, shows current progress value
func ProgressBar(bounds rl.Rectangle, value float32) {
b := bounds.ToInt32()
if value > 1.0 {
value = 1.0
} else if value < 0.0 {
value = 0.0
}
progressBar := rl.RectangleInt32{b.X + int32(style[ProgressbarBorderWidth]), b.Y + int32(style[ProgressbarBorderWidth]), b.Width - (int32(style[ProgressbarBorderWidth]) * 2), b.Height - (int32(style[ProgressbarBorderWidth]) * 2)}
progressValue := rl.RectangleInt32{b.X + int32(style[ProgressbarBorderWidth]), b.Y + int32(style[ProgressbarBorderWidth]), int32(value * float32(b.Width-int32(style[ProgressbarBorderWidth])*2)), b.Height - (int32(style[ProgressbarBorderWidth]) * 2)}
// Draw control
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ProgressbarBorderColor])))
rl.DrawRectangle(progressBar.X, progressBar.Y, progressBar.Width, progressBar.Height, rl.GetColor(int32(style[ProgressbarInsideColor])))
rl.DrawRectangle(progressValue.X, progressValue.Y, progressValue.Width, progressValue.Height, rl.GetColor(int32(style[ProgressbarProgressColor])))
}
// Spinner - Spinner element, returns selected value
func Spinner(bounds rl.Rectangle, value, minValue, maxValue int) int {
b := bounds.ToInt32()
state := Normal
mousePoint := rl.GetMousePosition()
labelBoxBound := rl.RectangleInt32{b.X + b.Width/4 + 1, b.Y, b.Width / 2, b.Height}
leftButtonBound := rl.RectangleInt32{b.X, b.Y, b.Width / 4, b.Height}
rightButtonBound := rl.RectangleInt32{b.X + b.Width - b.Width/4 + 1, b.Y, b.Width / 4, b.Height}
textWidth := rl.MeasureText(fmt.Sprintf("%d", value), int32(style[GlobalTextFontsize]))
buttonSide := 0
// Update control
if rl.CheckCollisionPointRec(mousePoint, leftButtonBound.ToFloat32()) || rl.CheckCollisionPointRec(mousePoint, rightButtonBound.ToFloat32()) || rl.CheckCollisionPointRec(mousePoint, labelBoxBound.ToFloat32()) {
if rl.IsKeyDown(rl.KeyLeft) {
state = Pressed
buttonSide = 1
if value > minValue {
value--
}
} else if rl.IsKeyDown(rl.KeyRight) {
state = Pressed
buttonSide = 2
if value < maxValue {
value++
}
}
}
if rl.CheckCollisionPointRec(mousePoint, leftButtonBound.ToFloat32()) {
buttonSide = 1
state = Focused
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
if !valueSpeed {
if value > minValue {
value--
}
valueSpeed = true
} else {
framesCounter++
}
state = Pressed
if value > minValue {
if framesCounter >= 30 {
value--
}
}
}
} else if rl.CheckCollisionPointRec(mousePoint, rightButtonBound.ToFloat32()) {
buttonSide = 2
state = Focused
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
if !valueSpeed {
if value < maxValue {
value++
}
valueSpeed = true
} else {
framesCounter++
}
state = Pressed
if value < maxValue {
if framesCounter >= 30 {
value++
}
}
}
} else if !rl.CheckCollisionPointRec(mousePoint, labelBoxBound.ToFloat32()) {
buttonSide = 0
}
if rl.IsMouseButtonUp(rl.MouseLeftButton) {
valueSpeed = false
framesCounter = 0
}
// Draw control
switch state {
case Normal:
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor])))
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor])))
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultTextColor])))
break
case Focused:
if buttonSide == 1 {
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerHoverButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerHoverButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerHoverSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
} else if buttonSide == 2 {
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerHoverButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerHoverButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerHoverSymbolColor])))
}
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor])))
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor])))
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerHoverTextColor])))
break
case Pressed:
if buttonSide == 1 {
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerPressedButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerPressedButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerPressedSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
} else if buttonSide == 2 {
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerPressedButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerPressedButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerPressedSymbolColor])))
}
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor])))
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor])))
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerPressedTextColor])))
break
default:
break
}
return value
}
// TextBox - Text Box element, updates input text
func TextBox(bounds rl.Rectangle, text string) string {
b := bounds.ToInt32()
state := Normal
mousePoint := rl.GetMousePosition()
letter := int32(-1)
// Update control
if rl.CheckCollisionPointRec(mousePoint, bounds) {
state = Focused // NOTE: PRESSED state is not used on this control
framesCounter2++
letter = rl.GetKeyPressed()
if letter != -1 {
if letter >= 32 && letter < 127 {
text = fmt.Sprintf("%s%c", text, letter)
}
}
if rl.IsKeyPressed(rl.KeyBackspace) {
if len(text) > 0 {
text = text[:len(text)-1]