forked from libui-ng/libui-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.h
3999 lines (3592 loc) · 129 KB
/
ui.h
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
// 6 april 2015
// TODO add a uiVerifyControlType() function that can be used by control implementations to verify controls
// TODOs
// - make getters that return whether something exists accept a NULL pointer to discard the value (and thus only return that the thing exists?)
// - const-correct everything
// - normalize documentation between typedefs and structs
/**
* @defgroup container Container controls
* @defgroup dataEntry Data entry controls
* @defgroup static Static controls
* @defgroup button Buttons
* @defgroup dialogWindow Dialog windows
* @defgroup menu Menus
* @defgroup table Tables
*/
#ifndef __LIBUI_UI_H__
#define __LIBUI_UI_H__
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// this macro is generated by cmake
#ifdef libui_EXPORTS
#ifdef _WIN32
#define _UI_EXTERN __declspec(dllexport) extern
#else
#define _UI_EXTERN __attribute__((visibility("default"))) extern
#endif
#else
// TODO add __declspec(dllimport) on windows, but only if not static
#define _UI_EXTERN extern
#endif
// C++ is really really really really really really dumb about enums, so screw that and just make them anonymous
// This has the advantage of being ABI-able should we ever need an ABI...
#define _UI_ENUM(s) typedef unsigned int s; enum
// This constant is provided because M_PI is nonstandard.
// This comes from Go's math.Pi, which in turn comes from http://oeis.org/A000796.
#define uiPi 3.14159265358979323846264338327950288419716939937510582097494459
// TODO uiBool?
// uiForEach represents the return value from one of libui's various ForEach functions.
_UI_ENUM(uiForEach) {
uiForEachContinue,
uiForEachStop,
};
typedef struct uiInitOptions uiInitOptions;
struct uiInitOptions {
size_t Size;
};
_UI_EXTERN const char *uiInit(uiInitOptions *options);
_UI_EXTERN void uiUninit(void);
_UI_EXTERN void uiFreeInitError(const char *err);
_UI_EXTERN void uiMain(void);
_UI_EXTERN void uiMainSteps(void);
_UI_EXTERN int uiMainStep(int wait);
_UI_EXTERN void uiQuit(void);
_UI_EXTERN void uiQueueMain(void (*f)(void *data), void *data);
// TODO standardize the looping behavior return type, either with some enum or something, and the test expressions throughout the code
// TODO figure out what to do about looping and the exact point that the timer is rescheduled so we can document it; see https://github.com/andlabs/libui/pull/277
// TODO (also in the above link) document that this cannot be called from any thread, unlike uiQueueMain()
// TODO document that the minimum exact timing, either accuracy (timer burst, etc.) or granularity (15ms on Windows, etc.), is OS-defined
// TODO also figure out how long until the initial tick is registered on all platforms to document
// TODO also add a comment about how useful this could be in bindings, depending on the language being bound to
_UI_EXTERN void uiTimer(int milliseconds, int (*f)(void *data), void *data);
_UI_EXTERN void uiOnShouldQuit(int (*f)(void *data), void *data);
_UI_EXTERN void uiFreeText(char *text);
/**
* Base class for GUI controls providing common methods.
*
* @struct uiControl
*/
typedef struct uiControl uiControl;
struct uiControl {
uint32_t Signature;
uint32_t OSSignature;
uint32_t TypeSignature;
void (*Destroy)(uiControl *);
uintptr_t (*Handle)(uiControl *);
uiControl *(*Parent)(uiControl *);
void (*SetParent)(uiControl *, uiControl *);
int (*Toplevel)(uiControl *);
int (*Visible)(uiControl *);
void (*Show)(uiControl *);
void (*Hide)(uiControl *);
int (*Enabled)(uiControl *);
void (*Enable)(uiControl *);
void (*Disable)(uiControl *);
};
// TOOD add argument names to all arguments
#define uiControl(this) ((uiControl *) (this))
/**
* Dispose and free all allocated resources.
*
* @param c uiControl instance.
* @todo Document ownership.
* @memberof uiControl
*/
_UI_EXTERN void uiControlDestroy(uiControl *c);
/**
* Returns the control's OS-level handle.
*
* @param c uiControl instance.
* @returns OS-level handle.
* @memberof uiControl
*/
_UI_EXTERN uintptr_t uiControlHandle(uiControl *c);
/**
* Returns the parent control.
*
* @param c uiControl instance.
* @returns The parent control, `NULL` if detached.
* @memberof uiControl
*/
_UI_EXTERN uiControl *uiControlParent(uiControl *c);
/**
* Sets the control's parent.
*
* @param c uiControl instance.
* @param parent The parent control, `NULL` to detach.
* @todo Document ownership.
* @memberof uiControl
*/
_UI_EXTERN void uiControlSetParent(uiControl *c, uiControl *parent);
/**
* Returns whether or not the control is a top level control.
*
* @param c uiControl instance.
* @returns `TRUE` if top level control, `FALSE` otherwise.
* @memberof uiControl
*/
_UI_EXTERN int uiControlToplevel(uiControl *c);
/**
* Returns whether or not the control is visible.
*
* @param c uiControl instance.
* @returns `TRUE` if visible, `FALSE` otherwise.
* @memberof uiControl
*/
_UI_EXTERN int uiControlVisible(uiControl *c);
/**
* Shows the control.
*
* @param c uiControl instance.
* @memberof uiControl
*/
_UI_EXTERN void uiControlShow(uiControl *c);
/**
* Hides the control.
*
* @param c uiControl instance.
* @note Hidden controls do not take up space within the layout.
* @memberof uiControl
*/
_UI_EXTERN void uiControlHide(uiControl *c);
/**
* Returns whether or not the control is enabled.
*
* Defaults to `true`.
*
* @param c uiControl instance.
* @see uiControlEnabledToUser
* @memberof uiControl
*/
_UI_EXTERN int uiControlEnabled(uiControl *c);
/**
* Enables the control.
*
* @param c uiControl instance.
* @memberof uiControl
*/
_UI_EXTERN void uiControlEnable(uiControl *c);
/**
* Disables the control.
*
* @param c uiControl instance.
* @memberof uiControl
*/
_UI_EXTERN void uiControlDisable(uiControl *c);
/**
* Allocates a uiControl.
*
* Helper to allocate new controls.
*
* @param n Size of type to allocate.
* @todo Document parameters
* @memberof uiControl @static
*/
_UI_EXTERN uiControl *uiAllocControl(size_t n, uint32_t OSsig, uint32_t typesig, const char *typenamestr);
/**
* Frees the control.
*
* @param c uiControl instance.
* @memberof uiControl
*/
_UI_EXTERN void uiFreeControl(uiControl *c);
/**
* Makes sure the control's parent can be set to @p parent.
*
* @param c uiControl instance.
* @param parent uiControl instance.
* @todo Make sure all controls have these
* @warning This will crash the application if `FALSE`.
* @memberof uiControl
*/
_UI_EXTERN void uiControlVerifySetParent(uiControl *c, uiControl *parent);
/**
* Returns whether or not the control can be interacted with by the user.
*
* Checks if the control and all it's parents are enabled to make sure it can
* be interacted with by the user.
*
* @param c uiControl instance.
* @returns `TRUE` if enabled, `FALSE` otherwise.
* @see uiControlEnabled
* @memberof uiControl
*/
_UI_EXTERN int uiControlEnabledToUser(uiControl *c);
// TODO Move this to private API? According to old/new.md this should be used by toplevel controls.
_UI_EXTERN void uiUserBugCannotSetParentOnToplevel(const char *type);
/**
* A control that represents a top-level window.
*
* A window contains exactly one child control that occupied the entire window.
*
* @note Many of the uiWindow methods should be regarded as mere hints.
* The underlying system may override these or even choose to ignore them
* completely. This is especially true for many Unix systems.
*
* @warning A uiWindow can NOT be a child of another uiControl.
*
* @struct uiWindow
* @extends uiControl
* @ingroup container
*/
typedef struct uiWindow uiWindow;
#define uiWindow(this) ((uiWindow *) (this))
/**
* Returns the window title.
*
* @param w uiWindow instance.
* @returns The window title text.\n
* A `NUL` terminated UTF-8 string.\n
* Caller is responsible for freeing the data with `uiFreeText()`.
* @memberof uiWindow
*/
_UI_EXTERN char *uiWindowTitle(uiWindow *w);
/**
* Sets the window title.
*
* @param w uiWindow instance.
* @param title Window title text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @note This method is merely a hint and may be ignored on unix platforms.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowSetTitle(uiWindow *w, const char *title);
/**
* Gets the window position.
*
* Coordinates are measured from the top left corner of the screen.
*
* @param w uiWindow instance.
* @param[out] x X position of the window.
* @param[out] y Y position of the window.
* @note This method may return inaccurate or dummy values on Unix platforms.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowPosition(uiWindow *w, int *x, int *y);
/**
* Moves the window to the specified position.
*
* Coordinates are measured from the top left corner of the screen.
*
* @param w uiWindow instance.
* @param x New x position of the window.
* @param y New y position of the window.
* @note This method is merely a hint and may be ignored on Unix platforms.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowSetPosition(uiWindow *w, int x, int y);
/**
* Registers a callback for when the window moved.
*
* @param w uiWindow instance.
* @param f Callback function.\n
* @p sender Back reference to the instance that triggered the callback.\n
* @p senderData User data registered with the sender instance.\n
* @param data User data to be passed to the callback.
*
* @note Only one callback can be registered at a time.
* @note The callback is not triggered when calling uiWindowSetPosition().
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowOnPositionChanged(uiWindow *w,
void (*f)(uiWindow *sender, void *senderData), void *data);
/**
* Gets the window content size.
*
* @param w uiWindow instance.
* @param[out] width Window content width.
* @param[out] height Window content height.
* @note The content size does NOT include window decorations like menus or title bars.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowContentSize(uiWindow *w, int *width, int *height);
/**
* Sets the window content size.
*
* @param w uiWindow instance.
* @param width Window content width to set.
* @param height Window content height to set.
* @note The content size does NOT include window decorations like menus or title bars.
* @note This method is merely a hint and may be ignored by the system.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowSetContentSize(uiWindow *w, int width, int height);
/**
* Returns whether or not the window is full screen.
*
* @param w uiWindow instance.
* @returns `TRUE` if full screen, `FALSE` otherwise. [Default: `FALSE`]
* @memberof uiWindow
*/
_UI_EXTERN int uiWindowFullscreen(uiWindow *w);
/**
* Sets whether or not the window is full screen.
*
* @param w uiWindow instance.
* @param fullscreen `TRUE` to make window full screen, `FALSE` otherwise.
* @note This method is merely a hint and may be ignored by the system.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowSetFullscreen(uiWindow *w, int fullscreen);
/**
* Registers a callback for when the window content size is changed.
*
* @param w uiWindow instance.
* @param f Callback function.\n
* @p sender Back reference to the instance that triggered the callback.\n
* @p senderData User data registered with the sender instance.
* @param data User data to be passed to the callback.
*
* @note The callback is not triggered when calling uiWindowSetContentSize().
* @note Only one callback can be registered at a time.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowOnContentSizeChanged(uiWindow *w,
void (*f)(uiWindow *sender, void *senderData), void *data);
/**
* Registers a callback for when the window is to be closed.
*
* @param w uiWindow instance.
* @param f Callback function.\n
* @p sender Back reference to the instance that triggered the callback.\n
* @p senderData User data registered with the sender instance.\n
* Return:\n
* `TRUE` to destroys the window.\n
* `FALSE` to abort closing and keep the window alive and visible.
* @param data User data to be passed to the callback.
*
* @note Only one callback can be registered at a time.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowOnClosing(uiWindow *w,
int (*f)(uiWindow *sender, void *senderData), void *data);
/**
* Registers a callback for when the window focus changes.
*
* @param w uiWindow instance.
* @param f Callback function.\n
* @p sender Back reference to the instance that triggered the callback.\n
* @p senderData User data registered with the sender instance.
* @param data User data to be passed to the callback.
*
* @note Only one callback can be registered at a time.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowOnFocusChanged(uiWindow *w,
void (*f)(uiWindow *sender, void *senderData), void *data);
/**
* Returns whether or not the window is focused.
*
* @param w uiWindow instance.
* @returns `TRUE` if window is focused, `FALSE` otherwise.
* @memberof uiWindow
*/
_UI_EXTERN int uiWindowFocused(uiWindow *w);
/**
* Returns whether or not the window is borderless.
*
* @param w uiWindow instance.
* @returns `TRUE` if window is borderless, `FALSE` otherwise. [Default: `TODO`]
* @memberof uiWindow
*/
_UI_EXTERN int uiWindowBorderless(uiWindow *w);
/**
* Sets whether or not the window is borderless.
*
* @param w uiWindow instance.
* @param borderless `TRUE` to make window borderless, `FALSE` otherwise.
* @note This method is merely a hint and may be ignored by the system.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowSetBorderless(uiWindow *w, int borderless);
/**
* Sets the window's child.
*
* @param w uiWindow instance.
* @param child Control to be made child.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child);
/**
* Returns whether or not the window has a margin.
*
* @param w uiWindow instance.
* @returns `TRUE` if window has a margin, `FALSE` otherwise. [Default: `TODO`]
* @memberof uiWindow
*/
_UI_EXTERN int uiWindowMargined(uiWindow *w);
/**
* Sets whether or not the window has a margin.
*
* The margin size is determined by the OS defaults.
*
* @param w uiWindow instance.
* @param margined `TRUE` to set a window margin, `FALSE` otherwise.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined);
/**
* Returns whether or not the window is user resizeable.
*
* @param w uiWindow instance.
* @returns `TRUE` if window is resizable, `FALSE` otherwise. [Default: `TRUE`]
* @memberof uiWindow
*/
_UI_EXTERN int uiWindowResizeable(uiWindow *w);
/**
* Sets whether or not the window is user resizeable.
*
* @param w uiWindow instance.
* @param resizeable `TRUE` to make window resizable, `FALSE` otherwise.
* @note This method is merely a hint and may be ignored by the system.
* @memberof uiWindow
*/
_UI_EXTERN void uiWindowSetResizeable(uiWindow *w, int resizeable);
/**
* Creates a new uiWindow.
*
* @param title Window title text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @param width Window width.
* @param height Window height.
* @param hasMenubar Whether or not the window should display a menu bar.
* @returns A new uiWindow instance.
* @memberof uiWindow @static
*/
_UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar);
/**
* A control that visually represents a button to be clicked by the user to trigger an action.
*
* @struct uiButton
* @extends uiControl
* @ingroup button
*/
typedef struct uiButton uiButton;
#define uiButton(this) ((uiButton *) (this))
/**
* Returns the button label text.
*
* @param b uiButton instance.
* @returns The text of the label.\n
* A `NUL` terminated UTF-8 string.\n
* Caller is responsible for freeing the data with `uiFreeText()`.
* @memberof uiButton
*/
_UI_EXTERN char *uiButtonText(uiButton *b);
/**
* Sets the button label text.
*
* @param b uiButton instance.
* @param text Label text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @memberof uiButton
*/
_UI_EXTERN void uiButtonSetText(uiButton *b, const char *text);
/**
* Registers a callback for when the button is clicked.
*
* @param b uiButton instance.
* @param f Callback function.\n
* @p sender Back reference to the instance that triggered the callback.\n
* @p senderData User data registered with the sender instance.
* @param data User data to be passed to the callback.
*
* @note Only one callback can be registered at a time.
* @memberof uiButton
*/
_UI_EXTERN void uiButtonOnClicked(uiButton *b,
void (*f)(uiButton *sender, void *senderData), void *data);
/**
* Creates a new button.
*
* @param text Label text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @returns A new uiButton instance.
* @memberof uiButton @static
*/
_UI_EXTERN uiButton *uiNewButton(const char *text);
/**
* A boxlike container that holds a group of controls.
*
* The contained controls are arranged to be displayed either horizontally or
* vertically next to each other.
*
* @struct uiBox
* @extends uiControl
* @ingroup container
*/
typedef struct uiBox uiBox;
#define uiBox(this) ((uiBox *) (this))
/**
* Appends a control to the box.
*
* Stretchy items expand to use the remaining space within the box.
* In the case of multiple stretchy items the space is shared equally.
*
* @param b uiBox instance.
* @param child Control instance to append.
* @param stretchy `TRUE` to stretch control, `FALSE` otherwise.
* @memberof uiBox
*/
_UI_EXTERN void uiBoxAppend(uiBox *b, uiControl *child, int stretchy);
/**
* Returns the number of controls contained within the box.
*
* @param b uiBox instance.
* @returns Number of children.
* @memberof uiBox
*/
_UI_EXTERN int uiBoxNumChildren(uiBox *b);
/**
* Removes the control at @p index from the box.
*
* @param b uiBox instance.
* @param index Index of control to be removed.
* @note The control neither destroyed nor freed.
* @memberof uiBox
*/
_UI_EXTERN void uiBoxDelete(uiBox *b, int index);
/**
* Returns whether or not controls within the box are padded.
*
* Padding is defined as space between individual controls.
*
* @param b uiBox instance.
* @returns `TRUE` if controls are padded, `FALSE` otherwise. [Default: `TODO`]
* @memberof uiBox
*/
_UI_EXTERN int uiBoxPadded(uiBox *b);
/**
* Sets whether or not controls within the box are padded.
*
* Padding is defined as space between individual controls.
* The padding size is determined by the OS defaults.
*
* @param b uiBox instance.
* @param padded `TRUE` to make controls padded, `FALSE` otherwise.
* @memberof uiBox
*/
_UI_EXTERN void uiBoxSetPadded(uiBox *b, int padded);
/**
* Creates a new horizontal box.
*
* Controls within the box are placed next to each other horizontally.
*
* @returns A new uiBox instance.
* @memberof uiBox @static
*/
_UI_EXTERN uiBox *uiNewHorizontalBox(void);
/**
* Creates a new vertical box.
*
* Controls within the box are placed next to each other vertically.
*
* @returns A new uiBox instance.
* @memberof uiBox @static
*/
_UI_EXTERN uiBox *uiNewVerticalBox(void);
/**
* A control with a user checkable box accompanied by a text label.
*
* @struct uiCheckbox
* @extends uiControl
* @ingroup dataEntry
*/
typedef struct uiCheckbox uiCheckbox;
#define uiCheckbox(this) ((uiCheckbox *) (this))
/**
* Returns the checkbox label text.
*
* @param c uiCheckbox instance.
* @returns The text of the label.\n
* A `NUL` terminated UTF-8 string.\n
* Caller is responsible for freeing the data with `uiFreeText()`.
* @memberof uiCheckbox
*/
_UI_EXTERN char *uiCheckboxText(uiCheckbox *c);
/**
* Sets the checkbox label text.
*
* @param c uiCheckbox instance.
* @param text Label text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @memberof uiCheckbox
*/
_UI_EXTERN void uiCheckboxSetText(uiCheckbox *c, const char *text);
/**
* Registers a callback for when the checkbox is toggled by the user.
*
* @param c uiCheckbox instance.
* @param f Callback function.\n
* @p sender Back reference to the instance that initiated the callback.\n
* @p senderData User data registered with the sender instance.\n
* @param data User data to be passed to the callback.
*
* @note The callback is not triggered when calling uiCheckboxSetChecked().
* @note Only one callback can be registered at a time.
* @memberof uiCheckbox
*/
_UI_EXTERN void uiCheckboxOnToggled(uiCheckbox *c,
void (*f)(uiCheckbox *sender, void *senderData), void *data);
/**
* Returns whether or the checkbox is checked.
*
* @param c uiCheckbox instance.
* @returns `TRUE` if checked, `FALSE` otherwise. [Default: `FALSE`]
* @memberof uiCheckbox
*/
_UI_EXTERN int uiCheckboxChecked(uiCheckbox *c);
/**
* Sets whether or not the checkbox is checked.
*
* @param c uiCheckbox instance.
* @param checked `TRUE` to check box, `FALSE` otherwise.
* @memberof uiCheckbox
*/
_UI_EXTERN void uiCheckboxSetChecked(uiCheckbox *c, int checked);
/**
* Creates a new checkbox.
*
* @param text Label text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @returns A new uiCheckbox instance.
* @memberof uiCheckbox @static
*/
_UI_EXTERN uiCheckbox *uiNewCheckbox(const char *text);
/**
* A control with a single line text entry field.
*
* @struct uiEntry
* @extends uiControl
* @ingroup dataEntry
*/
typedef struct uiEntry uiEntry;
#define uiEntry(this) ((uiEntry *) (this))
/**
* Returns the entry's text.
*
* @param e uiEntry instance.
* @returns The text of the entry.\n
* A `NUL` terminated UTF-8 string.\n
* Caller is responsible for freeing the data with `uiFreeText()`.
* @memberof uiEntry
*/
_UI_EXTERN char *uiEntryText(uiEntry *e);
/**
* Sets the entry's text.
*
* @param e uiEntry instance.
* @param text Entry text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @memberof uiEntry
*/
_UI_EXTERN void uiEntrySetText(uiEntry *e, const char *text);
/**
* Registers a callback for when the user changes the entry's text.
*
* @param e uiEntry instance.
* @param f Callback function.\n
* @p sender Back reference to the instance that initiated the callback.\n
* @p senderData User data registered with the sender instance.\n
* @param data User data to be passed to the callback.
*
* @note The callback is not triggered when calling uiEntrySetText().
* @memberof uiEntry
*/
_UI_EXTERN void uiEntryOnChanged(uiEntry *e,
void (*f)(uiEntry *sender, void *senderData), void *data);
/**
* Returns whether or not the entry's text can be changed.
*
* @param e uiEntry instance.
* @returns `TRUE` if read only, `FALSE` otherwise. [Default: `FALSE`]
* @memberof uiEntry
*/
_UI_EXTERN int uiEntryReadOnly(uiEntry *e);
/**
* Sets whether or not the entry's text is read only.
*
* @param e uiEntry instance.
* @param readonly `TRUE` to make read only, `FALSE` otherwise.
* @memberof uiEntry
*/
_UI_EXTERN void uiEntrySetReadOnly(uiEntry *e, int readonly);
/**
* Creates a new entry.
*
* @returns A new uiEntry instance.
* @memberof uiEntry @static
*/
_UI_EXTERN uiEntry *uiNewEntry(void);
/**
* Creates a new entry suitable for sensitive inputs like passwords.
*
* The entered text is NOT readable by the user but masked as *******.
*
* @returns A new uiEntry instance.
* @memberof uiEntry @static
*/
_UI_EXTERN uiEntry *uiNewPasswordEntry(void);
/**
* Creates a new entry suitable for search.
*
* Some systems will deliberately delay the uiEntryOnChanged() callback for
* a more natural feel.
*
* @returns A new uiEntry instance.
* @memberof uiEntry @static
*/
_UI_EXTERN uiEntry *uiNewSearchEntry(void);
/**
* A control that displays non interactive text.
*
* @struct uiLabel
* @extends uiControl
* @ingroup static
*/
typedef struct uiLabel uiLabel;
#define uiLabel(this) ((uiLabel *) (this))
/**
* Returns the label text.
*
* @param l uiLabel instance.
* @returns The text of the label.\n
* A `NUL` terminated UTF-8 string.\n
* Caller is responsible for freeing the data with `uiFreeText()`.
* @memberof uiLabel
*/
_UI_EXTERN char *uiLabelText(uiLabel *l);
/**
* Sets the label text.
*
* @param l uiLabel instance.
* @param text Label text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @memberof uiLabel
*/
_UI_EXTERN void uiLabelSetText(uiLabel *l, const char *text);
/**
* Creates a new label.
*
* @param text Label text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @returns A new uiLabel instance.
* @memberof uiLabel @static
*/
_UI_EXTERN uiLabel *uiNewLabel(const char *text);
/**
* A multi page control interface that displays one page at a time.
*
* Each page/tab has an associated label that can be selected to switch
* between pages/tabs.
*
* @struct uiTab
* @extends uiControl
* @ingroup container
*/
typedef struct uiTab uiTab;
#define uiTab(this) ((uiTab *) (this))
/**
* Appends a control in form of a page/tab with label.
*
* @param t uiTab instance.
* @param name Label text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @param c Control to append.
* @memberof uiTab
*/
_UI_EXTERN void uiTabAppend(uiTab *t, const char *name, uiControl *c);
/**
* Inserts a control in form of a page/tab with label at @p index.
*
* @param t uiTab instance.
* @param name Label text.\n
* A valid, `NUL` terminated UTF-8 string.\n
* Data is copied internally. Ownership is not transferred.
* @param index Index at which to insert the control.
* @param c Control to insert.
* @memberof uiTab
*/
_UI_EXTERN void uiTabInsertAt(uiTab *t, const char *name, int index, uiControl *c);
/**
* Removes the control at @p index.
*
* @param t uiTab instance.
* @param index Index of the control to be removed.
* @note The control is neither destroyed nor freed.
* @memberof uiTab
*/
_UI_EXTERN void uiTabDelete(uiTab *t, int index);
/**
* Returns the number of pages contained.
*
* @param t uiTab instance.
* @returns Number of pages.
* @memberof uiTab
*/
_UI_EXTERN int uiTabNumPages(uiTab *t);
/**
* Returns whether or not the page/tab at @p index has a margin.
*
* @param t uiTab instance.
* @param index Index to check if it has a margin.
* @returns `TRUE` if the tab has a margin, `FALSE` otherwise. [Default: `TODO`]
* @memberof uiTab
*/
_UI_EXTERN int uiTabMargined(uiTab *t, int index);
/**
* Sets whether or not the page/tab at @p index has a margin.
*
* The margin size is determined by the OS defaults.
*
* @param t uiTab instance.
* @param index Index of the tab/page to un/set margin for.
* @param margined `TRUE` to set a margin for tab at @p index, `FALSE` otherwise.
* @memberof uiTab
*/
_UI_EXTERN void uiTabSetMargined(uiTab *t, int index, int margined);
/**
* Creates a new tab container.
*
* @return A new uiTab instance.
* @memberof uiTab @static
*/
_UI_EXTERN uiTab *uiNewTab(void);
/**
* A control container that adds a label to the contained child control.
*
* This control is a great way of grouping related controls in combination with
* uiBox.
*
* A visual box will or will not be drawn around the child control dependent
* on the underlying OS implementation.
*
* @struct uiGroup
* @extends uiControl
* @ingroup container
*/
typedef struct uiGroup uiGroup;
#define uiGroup(this) ((uiGroup *) (this))
/**
* Returns the group title.
*
* @param g uiGroup instance.
* @returns The group title text.\n
* A `NUL` terminated UTF-8 string.\n
* Caller is responsible for freeing the data with `uiFreeText()`.
* @memberof uiGroup