2015-08-16 16:14:46 -05:00
// 6 april 2015
2016-04-24 12:32:20 -05:00
// TODO add a uiVerifyControlType() function that can be used by control implementations to verify controls
2017-06-18 19:10:42 -05:00
// TODOs
// - make getters that return whether something exists accept a NULL pointer to discard the value (and thus only return that the thing exists?)
2017-06-19 13:50:03 -05:00
// - const-correct everything
2017-06-19 21:00:46 -05:00
// - normalize documentation between typedefs and structs
2017-06-18 19:10:42 -05:00
2015-08-16 16:14:46 -05:00
# ifndef __LIBUI_UI_H__
# define __LIBUI_UI_H__
# include <stddef.h>
# include <stdint.h>
2015-11-16 09:55:44 -06:00
# ifdef __cplusplus
extern " C " {
# endif
2016-06-03 21:19:33 -05:00
// 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
2015-08-16 16:14:46 -05:00
# define _UI_EXTERN extern
# endif
2016-04-23 20:38:51 -05:00
// 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
2016-05-22 11:00:44 -05:00
// 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
2016-06-13 19:55:50 -05:00
// TODO uiBool?
2017-06-06 11:47:07 -05:00
// uiForEach represents the return value from one of libui's various ForEach functions.
_UI_ENUM ( uiForEach ) {
uiForEachContinue ,
uiForEachStop ,
} ;
2015-08-16 16:14:46 -05:00
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 ) ;
2016-06-17 08:22:31 -05:00
_UI_EXTERN void uiMainSteps ( void ) ;
2016-05-24 21:14:05 -05:00
_UI_EXTERN int uiMainStep ( int wait ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiQuit ( void ) ;
2015-12-04 22:42:03 -06:00
_UI_EXTERN void uiQueueMain ( void ( * f ) ( void * data ) , void * data ) ;
2018-04-18 20:09:24 -05:00
// 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
2018-04-18 20:11:23 -05:00
// TODO also add a comment about how useful this could be in bindings, depending on the language being bound to
2017-08-19 17:32:52 -05:00
_UI_EXTERN void uiTimer ( int milliseconds , int ( * f ) ( void * data ) , void * data ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiOnShouldQuit ( int ( * f ) ( void * data ) , void * data ) ;
_UI_EXTERN void uiFreeText ( char * text ) ;
typedef struct uiControl uiControl ;
struct uiControl {
2016-04-24 12:31:33 -05:00
uint32_t Signature ;
uint32_t OSSignature ;
uint32_t TypeSignature ;
2016-04-24 17:46:03 -05:00
void ( * Destroy ) ( uiControl * ) ;
2015-08-16 16:14:46 -05:00
uintptr_t ( * Handle ) ( uiControl * ) ;
2016-04-24 17:46:03 -05:00
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 * ) ;
2015-08-16 16:14:46 -05:00
} ;
2016-04-24 20:51:08 -05:00
// TOOD add argument names to all arguments
2016-04-24 12:31:33 -05:00
# define uiControl(this) ((uiControl *) (this))
2015-08-16 21:19:15 -05:00
_UI_EXTERN void uiControlDestroy ( uiControl * ) ;
2015-08-16 22:16:42 -05:00
_UI_EXTERN uintptr_t uiControlHandle ( uiControl * ) ;
2015-08-17 18:11:35 -05:00
_UI_EXTERN uiControl * uiControlParent ( uiControl * ) ;
2015-08-16 21:19:15 -05:00
_UI_EXTERN void uiControlSetParent ( uiControl * , uiControl * ) ;
2016-04-24 17:46:03 -05:00
_UI_EXTERN int uiControlToplevel ( uiControl * ) ;
_UI_EXTERN int uiControlVisible ( uiControl * ) ;
2015-08-16 21:19:15 -05:00
_UI_EXTERN void uiControlShow ( uiControl * ) ;
_UI_EXTERN void uiControlHide ( uiControl * ) ;
2016-04-24 17:46:03 -05:00
_UI_EXTERN int uiControlEnabled ( uiControl * ) ;
2015-08-16 21:19:15 -05:00
_UI_EXTERN void uiControlEnable ( uiControl * ) ;
_UI_EXTERN void uiControlDisable ( uiControl * ) ;
2015-08-16 16:14:46 -05:00
2016-04-24 17:49:28 -05:00
_UI_EXTERN uiControl * uiAllocControl ( size_t n , uint32_t OSsig , uint32_t typesig , const char * typenamestr ) ;
_UI_EXTERN void uiFreeControl ( uiControl * ) ;
2016-04-25 12:38:17 -05:00
// TODO make sure all controls have these
_UI_EXTERN void uiControlVerifySetParent ( uiControl * , uiControl * ) ;
2016-04-24 18:22:21 -05:00
_UI_EXTERN int uiControlEnabledToUser ( uiControl * ) ;
2016-05-22 19:02:47 -05:00
_UI_EXTERN void uiUserBugCannotSetParentOnToplevel ( const char * type ) ;
2015-08-16 16:14:46 -05:00
typedef struct uiWindow uiWindow ;
2016-04-24 12:31:33 -05:00
# define uiWindow(this) ((uiWindow *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN char * uiWindowTitle ( uiWindow * w ) ;
_UI_EXTERN void uiWindowSetTitle ( uiWindow * w , const char * title ) ;
2016-06-15 21:28:44 -05:00
_UI_EXTERN void uiWindowContentSize ( uiWindow * w , int * width , int * height ) ;
_UI_EXTERN void uiWindowSetContentSize ( uiWindow * w , int width , int height ) ;
2016-06-16 07:07:50 -05:00
_UI_EXTERN int uiWindowFullscreen ( uiWindow * w ) ;
_UI_EXTERN void uiWindowSetFullscreen ( uiWindow * w , int fullscreen ) ;
2016-06-15 21:28:44 -05:00
_UI_EXTERN void uiWindowOnContentSizeChanged ( uiWindow * w , void ( * f ) ( uiWindow * , void * ) , void * data ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiWindowOnClosing ( uiWindow * w , int ( * f ) ( uiWindow * w , void * data ) , void * data ) ;
2016-06-16 10:20:28 -05:00
_UI_EXTERN int uiWindowBorderless ( uiWindow * w ) ;
_UI_EXTERN void uiWindowSetBorderless ( uiWindow * w , int borderless ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiWindowSetChild ( uiWindow * w , uiControl * child ) ;
_UI_EXTERN int uiWindowMargined ( uiWindow * w ) ;
_UI_EXTERN void uiWindowSetMargined ( uiWindow * w , int margined ) ;
_UI_EXTERN uiWindow * uiNewWindow ( const char * title , int width , int height , int hasMenubar ) ;
typedef struct uiButton uiButton ;
2016-04-24 12:31:33 -05:00
# define uiButton(this) ((uiButton *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN char * uiButtonText ( uiButton * b ) ;
_UI_EXTERN void uiButtonSetText ( uiButton * b , const char * text ) ;
_UI_EXTERN void uiButtonOnClicked ( uiButton * b , void ( * f ) ( uiButton * b , void * data ) , void * data ) ;
_UI_EXTERN uiButton * uiNewButton ( const char * text ) ;
typedef struct uiBox uiBox ;
2016-04-24 12:31:33 -05:00
# define uiBox(this) ((uiBox *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiBoxAppend ( uiBox * b , uiControl * child , int stretchy ) ;
2016-06-13 19:46:11 -05:00
_UI_EXTERN void uiBoxDelete ( uiBox * b , int index ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN int uiBoxPadded ( uiBox * b ) ;
_UI_EXTERN void uiBoxSetPadded ( uiBox * b , int padded ) ;
_UI_EXTERN uiBox * uiNewHorizontalBox ( void ) ;
_UI_EXTERN uiBox * uiNewVerticalBox ( void ) ;
typedef struct uiCheckbox uiCheckbox ;
2016-04-24 12:31:33 -05:00
# define uiCheckbox(this) ((uiCheckbox *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN char * uiCheckboxText ( uiCheckbox * c ) ;
_UI_EXTERN void uiCheckboxSetText ( uiCheckbox * c , const char * text ) ;
_UI_EXTERN void uiCheckboxOnToggled ( uiCheckbox * c , void ( * f ) ( uiCheckbox * c , void * data ) , void * data ) ;
_UI_EXTERN int uiCheckboxChecked ( uiCheckbox * c ) ;
_UI_EXTERN void uiCheckboxSetChecked ( uiCheckbox * c , int checked ) ;
_UI_EXTERN uiCheckbox * uiNewCheckbox ( const char * text ) ;
2016-05-28 21:35:40 -05:00
typedef struct uiEntry uiEntry ;
# define uiEntry(this) ((uiEntry *) (this))
_UI_EXTERN char * uiEntryText ( uiEntry * e ) ;
_UI_EXTERN void uiEntrySetText ( uiEntry * e , const char * text ) ;
_UI_EXTERN void uiEntryOnChanged ( uiEntry * e , void ( * f ) ( uiEntry * e , void * data ) , void * data ) ;
_UI_EXTERN int uiEntryReadOnly ( uiEntry * e ) ;
_UI_EXTERN void uiEntrySetReadOnly ( uiEntry * e , int readonly ) ;
_UI_EXTERN uiEntry * uiNewEntry ( void ) ;
2016-06-05 19:26:44 -05:00
_UI_EXTERN uiEntry * uiNewPasswordEntry ( void ) ;
_UI_EXTERN uiEntry * uiNewSearchEntry ( void ) ;
2016-05-28 21:35:40 -05:00
2015-08-16 16:14:46 -05:00
typedef struct uiLabel uiLabel ;
2016-04-24 12:31:33 -05:00
# define uiLabel(this) ((uiLabel *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN char * uiLabelText ( uiLabel * l ) ;
_UI_EXTERN void uiLabelSetText ( uiLabel * l , const char * text ) ;
2015-08-16 22:08:00 -05:00
_UI_EXTERN uiLabel * uiNewLabel ( const char * text ) ;
2015-08-16 16:14:46 -05:00
typedef struct uiTab uiTab ;
2016-04-24 12:31:33 -05:00
# define uiTab(this) ((uiTab *) (this))
2015-08-16 22:08:00 -05:00
_UI_EXTERN void uiTabAppend ( uiTab * t , const char * name , uiControl * c ) ;
2016-06-13 19:55:50 -05:00
_UI_EXTERN void uiTabInsertAt ( uiTab * t , const char * name , int before , uiControl * c ) ;
_UI_EXTERN void uiTabDelete ( uiTab * t , int index ) ;
_UI_EXTERN int uiTabNumPages ( uiTab * t ) ;
_UI_EXTERN int uiTabMargined ( uiTab * t , int page ) ;
_UI_EXTERN void uiTabSetMargined ( uiTab * t , int page , int margined ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN uiTab * uiNewTab ( void ) ;
typedef struct uiGroup uiGroup ;
2016-04-24 12:31:33 -05:00
# define uiGroup(this) ((uiGroup *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN char * uiGroupTitle ( uiGroup * g ) ;
_UI_EXTERN void uiGroupSetTitle ( uiGroup * g , const char * title ) ;
_UI_EXTERN void uiGroupSetChild ( uiGroup * g , uiControl * c ) ;
_UI_EXTERN int uiGroupMargined ( uiGroup * g ) ;
_UI_EXTERN void uiGroupSetMargined ( uiGroup * g , int margined ) ;
_UI_EXTERN uiGroup * uiNewGroup ( const char * title ) ;
// spinbox/slider rules:
// setting value outside of range will automatically clamp
// initial value is minimum
// complaint if min >= max?
typedef struct uiSpinbox uiSpinbox ;
2016-04-24 12:31:33 -05:00
# define uiSpinbox(this) ((uiSpinbox *) (this))
2016-06-13 19:55:50 -05:00
_UI_EXTERN int uiSpinboxValue ( uiSpinbox * s ) ;
_UI_EXTERN void uiSpinboxSetValue ( uiSpinbox * s , int value ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiSpinboxOnChanged ( uiSpinbox * s , void ( * f ) ( uiSpinbox * s , void * data ) , void * data ) ;
2016-06-13 19:55:50 -05:00
_UI_EXTERN uiSpinbox * uiNewSpinbox ( int min , int max ) ;
2015-08-16 16:14:46 -05:00
typedef struct uiSlider uiSlider ;
2016-04-24 12:31:33 -05:00
# define uiSlider(this) ((uiSlider *) (this))
2016-06-13 19:55:50 -05:00
_UI_EXTERN int uiSliderValue ( uiSlider * s ) ;
_UI_EXTERN void uiSliderSetValue ( uiSlider * s , int value ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiSliderOnChanged ( uiSlider * s , void ( * f ) ( uiSlider * s , void * data ) , void * data ) ;
2016-06-13 19:55:50 -05:00
_UI_EXTERN uiSlider * uiNewSlider ( int min , int max ) ;
2015-08-16 16:14:46 -05:00
2016-05-28 21:35:40 -05:00
typedef struct uiProgressBar uiProgressBar ;
# define uiProgressBar(this) ((uiProgressBar *) (this))
2016-06-15 11:51:12 -05:00
_UI_EXTERN int uiProgressBarValue ( uiProgressBar * p ) ;
2016-05-28 21:35:40 -05:00
_UI_EXTERN void uiProgressBarSetValue ( uiProgressBar * p , int n ) ;
_UI_EXTERN uiProgressBar * uiNewProgressBar ( void ) ;
2015-08-16 16:14:46 -05:00
typedef struct uiSeparator uiSeparator ;
2016-04-24 12:31:33 -05:00
# define uiSeparator(this) ((uiSeparator *) (this))
2015-08-16 22:44:23 -05:00
_UI_EXTERN uiSeparator * uiNewHorizontalSeparator ( void ) ;
2016-06-17 10:02:17 -05:00
_UI_EXTERN uiSeparator * uiNewVerticalSeparator ( void ) ;
2015-08-16 16:14:46 -05:00
typedef struct uiCombobox uiCombobox ;
2016-04-24 12:31:33 -05:00
# define uiCombobox(this) ((uiCombobox *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiComboboxAppend ( uiCombobox * c , const char * text ) ;
2016-06-13 20:05:40 -05:00
_UI_EXTERN int uiComboboxSelected ( uiCombobox * c ) ;
_UI_EXTERN void uiComboboxSetSelected ( uiCombobox * c , int n ) ;
2015-10-08 13:23:04 -05:00
_UI_EXTERN void uiComboboxOnSelected ( uiCombobox * c , void ( * f ) ( uiCombobox * c , void * data ) , void * data ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN uiCombobox * uiNewCombobox ( void ) ;
2016-05-23 16:41:15 -05:00
typedef struct uiEditableCombobox uiEditableCombobox ;
# define uiEditableCombobox(this) ((uiEditableCombobox *) (this))
_UI_EXTERN void uiEditableComboboxAppend ( uiEditableCombobox * c , const char * text ) ;
_UI_EXTERN char * uiEditableComboboxText ( uiEditableCombobox * c ) ;
2016-05-23 17:50:02 -05:00
_UI_EXTERN void uiEditableComboboxSetText ( uiEditableCombobox * c , const char * text ) ;
2016-05-23 16:41:15 -05:00
// TODO what do we call a function that sets the currently selected item and fills the text field with it? editable comboboxes have no consistent concept of selected item
_UI_EXTERN void uiEditableComboboxOnChanged ( uiEditableCombobox * c , void ( * f ) ( uiEditableCombobox * c , void * data ) , void * data ) ;
_UI_EXTERN uiEditableCombobox * uiNewEditableCombobox ( void ) ;
2015-08-16 16:14:46 -05:00
typedef struct uiRadioButtons uiRadioButtons ;
2016-04-24 12:31:33 -05:00
# define uiRadioButtons(this) ((uiRadioButtons *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN void uiRadioButtonsAppend ( uiRadioButtons * r , const char * text ) ;
2016-06-13 20:05:40 -05:00
_UI_EXTERN int uiRadioButtonsSelected ( uiRadioButtons * r ) ;
_UI_EXTERN void uiRadioButtonsSetSelected ( uiRadioButtons * r , int n ) ;
2016-06-06 17:56:58 -05:00
_UI_EXTERN void uiRadioButtonsOnSelected ( uiRadioButtons * r , void ( * f ) ( uiRadioButtons * , void * ) , void * data ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN uiRadioButtons * uiNewRadioButtons ( void ) ;
typedef struct uiDateTimePicker uiDateTimePicker ;
2016-04-24 12:31:33 -05:00
# define uiDateTimePicker(this) ((uiDateTimePicker *) (this))
2015-08-16 16:14:46 -05:00
_UI_EXTERN uiDateTimePicker * uiNewDateTimePicker ( void ) ;
_UI_EXTERN uiDateTimePicker * uiNewDatePicker ( void ) ;
_UI_EXTERN uiDateTimePicker * uiNewTimePicker ( void ) ;
2015-12-06 00:18:32 -06:00
// TODO provide a facility for entering tab stops?
typedef struct uiMultilineEntry uiMultilineEntry ;
2016-04-24 12:31:33 -05:00
# define uiMultilineEntry(this) ((uiMultilineEntry *) (this))
2015-12-06 00:18:32 -06:00
_UI_EXTERN char * uiMultilineEntryText ( uiMultilineEntry * e ) ;
_UI_EXTERN void uiMultilineEntrySetText ( uiMultilineEntry * e , const char * text ) ;
_UI_EXTERN void uiMultilineEntryAppend ( uiMultilineEntry * e , const char * text ) ;
_UI_EXTERN void uiMultilineEntryOnChanged ( uiMultilineEntry * e , void ( * f ) ( uiMultilineEntry * e , void * data ) , void * data ) ;
_UI_EXTERN int uiMultilineEntryReadOnly ( uiMultilineEntry * e ) ;
_UI_EXTERN void uiMultilineEntrySetReadOnly ( uiMultilineEntry * e , int readonly ) ;
_UI_EXTERN uiMultilineEntry * uiNewMultilineEntry ( void ) ;
2016-05-22 12:56:36 -05:00
_UI_EXTERN uiMultilineEntry * uiNewNonWrappingMultilineEntry ( void ) ;
2015-12-06 00:18:32 -06:00
2015-08-16 16:14:46 -05:00
typedef struct uiMenuItem uiMenuItem ;
2016-04-24 15:20:57 -05:00
# define uiMenuItem(this) ((uiMenuItem *) (this))
_UI_EXTERN void uiMenuItemEnable ( uiMenuItem * m ) ;
_UI_EXTERN void uiMenuItemDisable ( uiMenuItem * m ) ;
_UI_EXTERN void uiMenuItemOnClicked ( uiMenuItem * m , void ( * f ) ( uiMenuItem * sender , uiWindow * window , void * data ) , void * data ) ;
_UI_EXTERN int uiMenuItemChecked ( uiMenuItem * m ) ;
_UI_EXTERN void uiMenuItemSetChecked ( uiMenuItem * m , int checked ) ;
2016-04-24 12:31:33 -05:00
2016-04-24 15:20:57 -05:00
typedef struct uiMenu uiMenu ;
# define uiMenu(this) ((uiMenu *) (this))
2015-08-16 22:44:23 -05:00
_UI_EXTERN uiMenuItem * uiMenuAppendItem ( uiMenu * m , const char * name ) ;
2015-08-16 16:14:46 -05:00
_UI_EXTERN uiMenuItem * uiMenuAppendCheckItem ( uiMenu * m , const char * name ) ;
_UI_EXTERN uiMenuItem * uiMenuAppendQuitItem ( uiMenu * m ) ;
_UI_EXTERN uiMenuItem * uiMenuAppendPreferencesItem ( uiMenu * m ) ;
_UI_EXTERN uiMenuItem * uiMenuAppendAboutItem ( uiMenu * m ) ;
_UI_EXTERN void uiMenuAppendSeparator ( uiMenu * m ) ;
_UI_EXTERN uiMenu * uiNewMenu ( const char * name ) ;
2015-11-27 22:23:54 -06:00
_UI_EXTERN char * uiOpenFile ( uiWindow * parent ) ;
_UI_EXTERN char * uiSaveFile ( uiWindow * parent ) ;
_UI_EXTERN void uiMsgBox ( uiWindow * parent , const char * title , const char * description ) ;
_UI_EXTERN void uiMsgBoxError ( uiWindow * parent , const char * title , const char * description ) ;
2015-08-16 16:14:46 -05:00
2015-10-08 17:03:24 -05:00
typedef struct uiArea uiArea ;
typedef struct uiAreaHandler uiAreaHandler ;
typedef struct uiAreaDrawParams uiAreaDrawParams ;
typedef struct uiAreaMouseEvent uiAreaMouseEvent ;
typedef struct uiAreaKeyEvent uiAreaKeyEvent ;
typedef struct uiDrawContext uiDrawContext ;
struct uiAreaHandler {
void ( * Draw ) ( uiAreaHandler * , uiArea * , uiAreaDrawParams * ) ;
2015-12-17 12:50:07 -06:00
// TODO document that resizes cause a full redraw for non-scrolling areas; implementation-defined for scrolling areas
2015-10-08 17:03:24 -05:00
void ( * MouseEvent ) ( uiAreaHandler * , uiArea * , uiAreaMouseEvent * ) ;
2015-12-17 12:50:07 -06:00
// TODO document that on first show if the mouse is already in the uiArea then one gets sent with left=0
// TODO what about when the area is hidden and then shown again?
2015-12-17 13:20:17 -06:00
void ( * MouseCrossed ) ( uiAreaHandler * , uiArea * , int left ) ;
2015-10-08 17:03:24 -05:00
void ( * DragBroken ) ( uiAreaHandler * , uiArea * ) ;
int ( * KeyEvent ) ( uiAreaHandler * , uiArea * , uiAreaKeyEvent * ) ;
} ;
2016-10-24 22:35:18 -05:00
// TODO RTL layouts?
// TODO reconcile edge and corner naming
_UI_ENUM ( uiWindowResizeEdge ) {
uiWindowResizeEdgeLeft ,
uiWindowResizeEdgeTop ,
uiWindowResizeEdgeRight ,
uiWindowResizeEdgeBottom ,
uiWindowResizeEdgeTopLeft ,
uiWindowResizeEdgeTopRight ,
uiWindowResizeEdgeBottomLeft ,
uiWindowResizeEdgeBottomRight ,
// TODO have one for keyboard resizes?
2016-10-24 23:34:12 -05:00
// TODO GDK doesn't seem to have any others, including for keyboards...
// TODO way to bring up the system menu instead?
2016-10-24 22:35:18 -05:00
} ;
2016-04-24 12:31:33 -05:00
# define uiArea(this) ((uiArea *) (this))
2015-12-17 12:50:07 -06:00
// TODO give a better name
2015-12-17 18:16:30 -06:00
// TODO document the types of width and height
2016-06-13 20:05:40 -05:00
_UI_EXTERN void uiAreaSetSize ( uiArea * a , int width , int height ) ;
2015-10-09 14:27:57 -05:00
// TODO uiAreaQueueRedraw()
_UI_EXTERN void uiAreaQueueRedrawAll ( uiArea * a ) ;
2016-01-24 20:50:10 -06:00
_UI_EXTERN void uiAreaScrollTo ( uiArea * a , double x , double y , double width , double height ) ;
2016-10-24 22:35:18 -05:00
// TODO document these can only be called within Mouse() handlers
// TODO should these be allowed on scrolling areas?
2016-10-24 23:34:12 -05:00
// TODO decide which mouse events should be accepted; Down is the only one guaranteed to work right now
2016-10-25 00:11:03 -05:00
// TODO what happens to events after calling this up to and including the next mouse up?
2016-10-25 22:24:13 -05:00
// TODO release capture?
2016-10-24 22:35:18 -05:00
_UI_EXTERN void uiAreaBeginUserWindowMove ( uiArea * a ) ;
_UI_EXTERN void uiAreaBeginUserWindowResize ( uiArea * a , uiWindowResizeEdge edge ) ;
2015-10-08 17:03:24 -05:00
_UI_EXTERN uiArea * uiNewArea ( uiAreaHandler * ah ) ;
2016-06-13 20:05:40 -05:00
_UI_EXTERN uiArea * uiNewScrollingArea ( uiAreaHandler * ah , int width , int height ) ;
2015-10-08 17:03:24 -05:00
struct uiAreaDrawParams {
uiDrawContext * Context ;
2015-12-17 12:50:07 -06:00
// TODO document that this is only defined for nonscrolling areas
2015-12-17 12:54:54 -06:00
double AreaWidth ;
double AreaHeight ;
2015-10-08 17:03:24 -05:00
2015-12-17 12:54:54 -06:00
double ClipX ;
double ClipY ;
double ClipWidth ;
double ClipHeight ;
2015-10-08 17:03:24 -05:00
} ;
typedef struct uiDrawPath uiDrawPath ;
typedef struct uiDrawBrush uiDrawBrush ;
typedef struct uiDrawStrokeParams uiDrawStrokeParams ;
2015-10-11 10:13:01 -05:00
typedef struct uiDrawMatrix uiDrawMatrix ;
2015-10-08 17:03:24 -05:00
typedef struct uiDrawBrushGradientStop uiDrawBrushGradientStop ;
2016-04-23 20:38:51 -05:00
_UI_ENUM ( uiDrawBrushType ) {
2015-10-08 17:03:24 -05:00
uiDrawBrushTypeSolid ,
uiDrawBrushTypeLinearGradient ,
uiDrawBrushTypeRadialGradient ,
uiDrawBrushTypeImage ,
2016-04-23 20:38:51 -05:00
} ;
2015-10-08 17:03:24 -05:00
2016-04-23 20:38:51 -05:00
_UI_ENUM ( uiDrawLineCap ) {
2015-10-08 17:03:24 -05:00
uiDrawLineCapFlat ,
uiDrawLineCapRound ,
uiDrawLineCapSquare ,
2016-04-23 20:38:51 -05:00
} ;
2015-10-08 17:03:24 -05:00
2016-04-23 20:38:51 -05:00
_UI_ENUM ( uiDrawLineJoin ) {
2015-10-08 17:03:24 -05:00
uiDrawLineJoinMiter ,
uiDrawLineJoinRound ,
uiDrawLineJoinBevel ,
2016-04-23 20:38:51 -05:00
} ;
2015-10-08 17:03:24 -05:00
2015-10-10 12:01:48 -05:00
// this is the default for botoh cairo and Direct2D (in the latter case, from the C++ helper functions)
2015-10-08 17:03:24 -05:00
// Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value
// so we're good to use it too!
# define uiDrawDefaultMiterLimit 10.0
2016-04-23 20:38:51 -05:00
_UI_ENUM ( uiDrawFillMode ) {
2015-10-08 17:03:24 -05:00
uiDrawFillModeWinding ,
uiDrawFillModeAlternate ,
2016-04-23 20:38:51 -05:00
} ;
2015-10-08 17:03:24 -05:00
2015-10-11 10:13:01 -05:00
struct uiDrawMatrix {
double M11 ;
double M12 ;
double M21 ;
double M22 ;
double M31 ;
double M32 ;
} ;
2015-10-08 17:03:24 -05:00
struct uiDrawBrush {
uiDrawBrushType Type ;
// solid brushes
double R ;
double G ;
double B ;
double A ;
// gradient brushes
double X0 ; // linear: start X, radial: start X
double Y0 ; // linear: start Y, radial: start Y
double X1 ; // linear: end X, radial: outer circle center X
double Y1 ; // linear: end Y, radial: outer circle center Y
double OuterRadius ; // radial gradients only
uiDrawBrushGradientStop * Stops ;
size_t NumStops ;
// TODO extend mode
// cairo: none, repeat, reflect, pad; no individual control
// Direct2D: repeat, reflect, pad; no individual control
// Core Graphics: none, pad; before and after individually
// TODO cairo documentation is inconsistent about pad
// TODO images
// TODO transforms
} ;
struct uiDrawBrushGradientStop {
double Pos ;
double R ;
double G ;
double B ;
double A ;
} ;
struct uiDrawStrokeParams {
uiDrawLineCap Cap ;
uiDrawLineJoin Join ;
2015-10-16 09:46:26 -05:00
// TODO what if this is 0? on windows there will be a crash with dashing
2015-10-08 17:03:24 -05:00
double Thickness ;
double MiterLimit ;
2015-10-16 09:09:41 -05:00
double * Dashes ;
// TOOD what if this is 1 on Direct2D?
// TODO what if a dash is 0 on Cairo or Quartz?
size_t NumDashes ;
double DashPhase ;
2015-10-08 17:03:24 -05:00
} ;
_UI_EXTERN uiDrawPath * uiDrawNewPath ( uiDrawFillMode fillMode ) ;
_UI_EXTERN void uiDrawFreePath ( uiDrawPath * p ) ;
_UI_EXTERN void uiDrawPathNewFigure ( uiDrawPath * p , double x , double y ) ;
2015-10-11 20:15:08 -05:00
_UI_EXTERN void uiDrawPathNewFigureWithArc ( uiDrawPath * p , double xCenter , double yCenter , double radius , double startAngle , double sweep , int negative ) ;
2015-10-08 17:03:24 -05:00
_UI_EXTERN void uiDrawPathLineTo ( uiDrawPath * p , double x , double y ) ;
// notes: angles are both relative to 0 and go counterclockwise
// TODO is the initial line segment on cairo and OS X a proper join?
2015-10-09 22:19:21 -05:00
// TODO what if sweep < 0?
2015-10-11 20:15:08 -05:00
_UI_EXTERN void uiDrawPathArcTo ( uiDrawPath * p , double xCenter , double yCenter , double radius , double startAngle , double sweep , int negative ) ;
2015-10-08 17:03:24 -05:00
_UI_EXTERN void uiDrawPathBezierTo ( uiDrawPath * p , double c1x , double c1y , double c2x , double c2y , double endX , double endY ) ;
// TODO quadratic bezier
_UI_EXTERN void uiDrawPathCloseFigure ( uiDrawPath * p ) ;
// TODO effect of these when a figure is already started
_UI_EXTERN void uiDrawPathAddRectangle ( uiDrawPath * p , double x , double y , double width , double height ) ;
_UI_EXTERN void uiDrawPathEnd ( uiDrawPath * p ) ;
_UI_EXTERN void uiDrawStroke ( uiDrawContext * c , uiDrawPath * path , uiDrawBrush * b , uiDrawStrokeParams * p ) ;
_UI_EXTERN void uiDrawFill ( uiDrawContext * c , uiDrawPath * path , uiDrawBrush * b ) ;
// TODO primitives:
// - rounded rectangles
// - elliptical arcs
// - quadratic bezier curves
2015-10-11 10:13:01 -05:00
_UI_EXTERN void uiDrawMatrixSetIdentity ( uiDrawMatrix * m ) ;
_UI_EXTERN void uiDrawMatrixTranslate ( uiDrawMatrix * m , double x , double y ) ;
2015-10-12 00:43:12 -05:00
_UI_EXTERN void uiDrawMatrixScale ( uiDrawMatrix * m , double xCenter , double yCenter , double x , double y ) ;
2015-10-11 10:13:01 -05:00
_UI_EXTERN void uiDrawMatrixRotate ( uiDrawMatrix * m , double x , double y , double amount ) ;
2015-10-11 11:36:48 -05:00
_UI_EXTERN void uiDrawMatrixSkew ( uiDrawMatrix * m , double x , double y , double xamount , double yamount ) ;
2015-10-11 10:13:01 -05:00
_UI_EXTERN void uiDrawMatrixMultiply ( uiDrawMatrix * dest , uiDrawMatrix * src ) ;
_UI_EXTERN int uiDrawMatrixInvertible ( uiDrawMatrix * m ) ;
_UI_EXTERN int uiDrawMatrixInvert ( uiDrawMatrix * m ) ;
_UI_EXTERN void uiDrawMatrixTransformPoint ( uiDrawMatrix * m , double * x , double * y ) ;
_UI_EXTERN void uiDrawMatrixTransformSize ( uiDrawMatrix * m , double * x , double * y ) ;
2015-10-12 20:11:42 -05:00
_UI_EXTERN void uiDrawTransform ( uiDrawContext * c , uiDrawMatrix * m ) ;
2015-10-13 10:16:06 -05:00
// TODO add a uiDrawPathStrokeToFill() or something like that
_UI_EXTERN void uiDrawClip ( uiDrawContext * c , uiDrawPath * path ) ;
2015-10-12 20:11:42 -05:00
2015-10-11 10:13:01 -05:00
_UI_EXTERN void uiDrawSave ( uiDrawContext * c ) ;
_UI_EXTERN void uiDrawRestore ( uiDrawContext * c ) ;
2018-03-18 14:49:44 -05:00
// uiAttribute stores information about an attribute in a
// uiAttributedString.
//
// You do not create uiAttributes directly; instead, you create a
// uiAttribute of a given type using the specialized constructor
// functions. For every Unicode codepoint in the uiAttributedString,
// at most one value of each attribute type can be applied.
//
// uiAttributes are immutable and the uiAttributedString takes
// ownership of the uiAttribute object once assigned, copying its
// contents as necessary.
typedef struct uiAttribute uiAttribute ;
// uiFreeAttribute() frees a uiAttribute. You generally do not need to
// call this yourself, as uiAttributedString does this for you. In fact,
// it is an error to call this function on a uiAttribute that has been
// given to a uiAttributedString. You can call this, however, if you
// created a uiAttribute that you aren't going to use later.
_UI_EXTERN void uiFreeAttribute ( uiAttribute * a ) ;
// uiAttributeType holds the possible uiAttribute types that may be
// returned by uiAttributeGetType(). Refer to the documentation for
// each type's constructor function for details on each type.
_UI_ENUM ( uiAttributeType ) {
uiAttributeTypeFamily ,
uiAttributeTypeSize ,
uiAttributeTypeWeight ,
uiAttributeTypeItalic ,
uiAttributeTypeStretch ,
uiAttributeTypeColor ,
uiAttributeTypeBackground ,
uiAttributeTypeUnderline ,
uiAttributeTypeUnderlineColor ,
uiAttributeTypeFeatures ,
} ;
// uiAttributeGetType() returns the type of a.
// TODO I don't like this name
_UI_EXTERN uiAttributeType uiAttributeGetType ( const uiAttribute * a ) ;
// uiNewFamilyAttribute() creates a new uiAttribute that changes the
// font family of the text it is applied to. family is copied; you do not
// need to keep it alive after uiNewFamilyAttribute() returns. Font
// family names are case-insensitive.
_UI_EXTERN uiAttribute * uiNewFamilyAttribute ( const char * family ) ;
// uiAttributeFamily() returns the font family stored in a. The
// returned string is owned by a. It is an error to call this on a
// uiAttribute that does not hold a font family.
_UI_EXTERN const char * uiAttributeFamily ( const uiAttribute * a ) ;
// uiNewSizeAttribute() creates a new uiAttribute that changes the
// size of the text it is applied to, in typographical points.
_UI_EXTERN uiAttribute * uiNewSizeAttribute ( double size ) ;
// uiAttributeSize() returns the font size stored in a. It is an error to
// call this on a uiAttribute that does not hold a font size.
_UI_EXTERN double uiAttributeSize ( const uiAttribute * a ) ;
// uiTextWeight represents possible text weights. These roughly
// map to the OSx2 text weight field of TrueType and OpenType
// fonts, or to CSS weight numbers. The named constants are
// nominal values; the actual values may vary by font and by OS,
// though this isn't particularly likely. Any value between
// uiTextWeightMinimum and uiDrawTextWeightMaximum,
// inclusive, is allowed.
//
// Note that due to restrictions in early versions of Windows, some
// fonts have "special" weights be exposed in many programs as
// separate font families. This is perhaps most notable with
// Arial Black. libui does not do this, even on Windows (because the
// DirectWrite API libui uses on Windows does not do this); to
// specify Arial Black, use family Arial and weight uiTextWeightBlack.
_UI_ENUM ( uiTextWeight ) {
uiTextWeightMinimum = 0 ,
uiTextWeightThin = 100 ,
uiTextWeightUltraLight = 200 ,
uiTextWeightLight = 300 ,
uiTextWeightBook = 350 ,
uiTextWeightNormal = 400 ,
uiTextWeightMedium = 500 ,
uiTextWeightSemiBold = 600 ,
uiTextWeightBold = 700 ,
uiTextWeightUltraBold = 800 ,
uiTextWeightHeavy = 900 ,
uiTextWeightUltraHeavy = 950 ,
uiTextWeightMaximum = 1000 ,
} ;
// uiNewWeightAttribute() creates a new uiAttribute that changes the
// weight of the text it is applied to. It is an error to specify a weight
// outside the range [uiTextWeightMinimum,
// uiTextWeightMaximum].
_UI_EXTERN uiAttribute * uiNewWeightAttribute ( uiTextWeight weight ) ;
// uiAttributeWeight() returns the font weight stored in a. It is an error
// to call this on a uiAttribute that does not hold a font weight.
_UI_EXTERN uiTextWeight uiAttributeWeight ( const uiAttribute * a ) ;
// uiTextItalic represents possible italic modes for a font. Italic
// represents "true" italics where the slanted glyphs have custom
// shapes, whereas oblique represents italics that are merely slanted
// versions of the normal glyphs. Most fonts usually have one or the
// other.
_UI_ENUM ( uiTextItalic ) {
uiTextItalicNormal ,
uiTextItalicOblique ,
uiTextItalicItalic ,
} ;
// uiNewItalicAttribute() creates a new uiAttribute that changes the
// italic mode of the text it is applied to. It is an error to specify an
// italic mode not specified in uiTextItalic.
_UI_EXTERN uiAttribute * uiNewItalicAttribute ( uiTextItalic italic ) ;
// uiAttributeItalic() returns the font italic mode stored in a. It is an
// error to call this on a uiAttribute that does not hold a font italic
// mode.
_UI_EXTERN uiTextItalic uiAttributeItalic ( const uiAttribute * a ) ;
// uiTextStretch represents possible stretches (also called "widths")
// of a font.
//
// Note that due to restrictions in early versions of Windows, some
// fonts have "special" stretches be exposed in many programs as
// separate font families. This is perhaps most notable with
// Arial Condensed. libui does not do this, even on Windows (because
// the DirectWrite API libui uses on Windows does not do this); to
// specify Arial Condensed, use family Arial and stretch
// uiTextStretchCondensed.
_UI_ENUM ( uiTextStretch ) {
uiTextStretchUltraCondensed ,
uiTextStretchExtraCondensed ,
uiTextStretchCondensed ,
uiTextStretchSemiCondensed ,
uiTextStretchNormal ,
uiTextStretchSemiExpanded ,
uiTextStretchExpanded ,
uiTextStretchExtraExpanded ,
uiTextStretchUltraExpanded ,
} ;
// uiNewStretchAttribute() creates a new uiAttribute that changes the
// stretch of the text it is applied to. It is an error to specify a strech
// not specified in uiTextStretch.
_UI_EXTERN uiAttribute * uiNewStretchAttribute ( uiTextStretch stretch ) ;
// uiAttributeStretch() returns the font stretch stored in a. It is an
// error to call this on a uiAttribute that does not hold a font stretch.
_UI_EXTERN uiTextStretch uiAttributeStretch ( const uiAttribute * a ) ;
// uiNewColorAttribute() creates a new uiAttribute that changes the
// color of the text it is applied to. It is an error to specify an invalid
// color.
_UI_EXTERN uiAttribute * uiNewColorAttribute ( double r , double g , double b , double a ) ;
// uiAttributeColor() returns the text color stored in a. It is an
// error to call this on a uiAttribute that does not hold a text color.
_UI_EXTERN void uiAttributeColor ( const uiAttribute * a , double * r , double * g , double * b , double * alpha ) ;
// uiNewBackgroundAttribute() creates a new uiAttribute that
// changes the background color of the text it is applied to. It is an
// error to specify an invalid color.
_UI_EXTERN uiAttribute * uiNewBackgroundAttribute ( double r , double g , double b , double a ) ;
// TODO reuse uiAttributeColor() for background colors, or make a new function...
// uiUnderline specifies a type of underline to use on text.
_UI_ENUM ( uiUnderline ) {
uiUnderlineNone ,
uiUnderlineSingle ,
uiUnderlineDouble ,
uiUnderlineSuggestion , // wavy or dotted underlines used for spelling/grammar checkers
} ;
// uiNewUnderlineAttribute() creates a new uiAttribute that changes
// the type of underline on the text it is applied to. It is an error to
// specify an underline type not specified in uiUnderline.
_UI_EXTERN uiAttribute * uiNewUnderlineAttribute ( uiUnderline u ) ;
// uiAttributeUnderline() returns the underline type stored in a. It is
// an error to call this on a uiAttribute that does not hold an underline
// style.
_UI_EXTERN uiUnderline uiAttributeUnderline ( const uiAttribute * a ) ;
// uiUnderlineColor specifies the color of any underline on the text it
// is applied to, regardless of the type of underline. In addition to
// being able to specify a custom color, you can explicitly specify
// platform-specific colors for suggestion underlines; to use them
// correctly, pair them with uiUnderlineSuggestion (though they can
// be used on other types of underline as well).
//
// If an underline type is applied but no underline color is
// specified, the text color is used instead. If an underline color
// is specified without an underline type, the underline color
// attribute is ignored, but not removed from the uiAttributedString.
_UI_ENUM ( uiUnderlineColor ) {
uiUnderlineColorCustom ,
uiUnderlineColorSpelling ,
uiUnderlineColorGrammar ,
uiUnderlineColorAuxiliary , // for instance, the color used by smart replacements on macOS or in Microsoft Office
} ;
// uiNewUnderlineColorAttribute() creates a new uiAttribute that
// changes the color of the underline on the text it is applied to.
// It is an error to specify an underline color not specified in
// uiUnderlineColor.
//
// If the specified color type is uiUnderlineColorCustom, it is an
// error to specify an invalid color value. Otherwise, the color values
// are ignored and should be specified as zero.
_UI_EXTERN uiAttribute * uiNewUnderlineColorAttribute ( uiUnderlineColor u , double r , double g , double b , double a ) ;
// uiAttributeUnderlineColor() returns the underline color stored in
// a. It is an error to call this on a uiAttribute that does not hold an
// underline color.
_UI_EXTERN void uiAttributeUnderlineColor ( const uiAttribute * a , uiUnderlineColor * u , double * r , double * g , double * b , double * alpha ) ;
// uiOpenTypeFeatures represents a set of OpenType feature
// tag-value pairs, for applying OpenType features to text.
// OpenType feature tags are four-character codes defined by
// OpenType that cover things from design features like small
// caps and swashes to language-specific glyph shapes and
// beyond. Each tag may only appear once in any given
// uiOpenTypeFeatures instance. Each value is a 32-bit integer,
// often used as a Boolean flag, but sometimes as an index to choose
// a glyph shape to use.
//
// If a font does not support a certain feature, that feature will be
// ignored. (TODO verify this on all OSs)
//
// See the OpenType specification at
// https://www.microsoft.com/typography/otspec/featuretags.htm
// for the complete list of available features, information on specific
// features, and how to use them.
// TODO invalid features
typedef struct uiOpenTypeFeatures uiOpenTypeFeatures ;
// uiOpenTypeFeaturesForEachFunc is the type of the function
// invoked by uiOpenTypeFeaturesForEach() for every OpenType
// feature in otf. Refer to that function's documentation for more
// details.
typedef uiForEach ( * uiOpenTypeFeaturesForEachFunc ) ( const uiOpenTypeFeatures * otf , char a , char b , char c , char d , uint32_t value , void * data ) ;
// @role uiOpenTypeFeatures constructor
// uiNewOpenTypeFeatures() returns a new uiOpenTypeFeatures
// instance, with no tags yet added.
_UI_EXTERN uiOpenTypeFeatures * uiNewOpenTypeFeatures ( void ) ;
// @role uiOpenTypeFeatures destructor
// uiFreeOpenTypeFeatures() frees otf.
_UI_EXTERN void uiFreeOpenTypeFeatures ( uiOpenTypeFeatures * otf ) ;
// uiOpenTypeFeaturesClone() makes a copy of otf and returns it.
// Changing one will not affect the other.
_UI_EXTERN uiOpenTypeFeatures * uiOpenTypeFeaturesClone ( const uiOpenTypeFeatures * otf ) ;
// uiOpenTypeFeaturesAdd() adds the given feature tag and value
// to otf. The feature tag is specified by a, b, c, and d. If there is
// already a value associated with the specified tag in otf, the old
// value is removed.
_UI_EXTERN void uiOpenTypeFeaturesAdd ( uiOpenTypeFeatures * otf , char a , char b , char c , char d , uint32_t value ) ;
// uiOpenTypeFeaturesRemove() removes the given feature tag
// and value from otf. If the tag is not present in otf,
// uiOpenTypeFeaturesRemove() does nothing.
_UI_EXTERN void uiOpenTypeFeaturesRemove ( uiOpenTypeFeatures * otf , char a , char b , char c , char d ) ;
// uiOpenTypeFeaturesGet() determines whether the given feature
// tag is present in otf. If it is, *value is set to the tag's value and
// nonzero is returned. Otherwise, zero is returned.
//
// Note that if uiOpenTypeFeaturesGet() returns zero, value isn't
// changed. This is important: if a feature is not present in a
// uiOpenTypeFeatures, the feature is NOT treated as if its
// value was zero anyway. Script-specific font shaping rules and
// font-specific feature settings may use a different default value
// for a feature. You should likewise not treat a missing feature as
// having a value of zero either. Instead, a missing feature should
// be treated as having some unspecified default value.
_UI_EXTERN int uiOpenTypeFeaturesGet ( const uiOpenTypeFeatures * otf , char a , char b , char c , char d , uint32_t * value ) ;
// uiOpenTypeFeaturesForEach() executes f for every tag-value
// pair in otf. The enumeration order is unspecified. You cannot
// modify otf while uiOpenTypeFeaturesForEach() is running.
_UI_EXTERN void uiOpenTypeFeaturesForEach ( const uiOpenTypeFeatures * otf , uiOpenTypeFeaturesForEachFunc f , void * data ) ;
// uiNewFeaturesAttribute() creates a new uiAttribute that changes
// the font family of the text it is applied to. otf is copied; you may
// free it after uiNewFeaturesAttribute() returns.
_UI_EXTERN uiAttribute * uiNewFeaturesAttribute ( const uiOpenTypeFeatures * otf ) ;
// uiAttributeFeatures() returns the OpenType features stored in a.
// The returned uiOpenTypeFeatures object is owned by a. It is an
// error to call this on a uiAttribute that does not hold OpenType
// features.
_UI_EXTERN const uiOpenTypeFeatures * uiAttributeFeatures ( const uiAttribute * a ) ;
// uiAttributedString represents a string of UTF-8 text that can
// optionally be embellished with formatting attributes. libui
// provides the list of formatting attributes, which cover common
// formatting traits like boldface and color as well as advanced
// typographical features provided by OpenType like superscripts
// and small caps. These attributes can be combined in a variety of
// ways.
//
// Attributes are applied to runs of Unicode codepoints in the string.
// Zero-length runs are elided. Consecutive runs that have the same
// attribute type and value are merged. Each attribute is independent
// of each other attribute; overlapping attributes of different types
// do not split each other apart, but different values of the same
// attribute type do.
//
// The empty string can also be represented by uiAttributedString,
// but because of the no-zero-length-attribute rule, it will not have
// attributes.
//
// A uiAttributedString takes ownership of all attributes given to
// it, as it may need to duplicate or delete uiAttribute objects at
// any time. By extension, when you free a uiAttributedString,
// all uiAttributes within will also be freed. Each method will
// describe its own rules in more details.
//
// In addition, uiAttributedString provides facilities for moving
// between grapheme clusters, which represent a character
// from the point of view of the end user. The cursor of a text editor
// is always placed on a grapheme boundary, so you can use these
// features to move the cursor left or right by one "character".
// TODO does uiAttributedString itself need this
//
// uiAttributedString does not provide enough information to be able
// to draw itself onto a uiDrawContext or respond to user actions.
// In order to do that, you'll need to use a uiDrawTextLayout, which
// is built from the combination of a uiAttributedString and a set of
// layout-specific properties.
typedef struct uiAttributedString uiAttributedString ;
// uiAttributedStringForEachAttributeFunc is the type of the function
// invoked by uiAttributedStringForEachAttribute() for every
// attribute in s. Refer to that function's documentation for more
// details.
typedef uiForEach ( * uiAttributedStringForEachAttributeFunc ) ( const uiAttributedString * s , const uiAttribute * a , size_t start , size_t end , void * data ) ;
// @role uiAttributedString constructor
// uiNewAttributedString() creates a new uiAttributedString from
// initialString. The string will be entirely unattributed.
_UI_EXTERN uiAttributedString * uiNewAttributedString ( const char * initialString ) ;
// @role uiAttributedString destructor
// uiFreeAttributedString() destroys the uiAttributedString s.
// It will also free all uiAttributes within.
_UI_EXTERN void uiFreeAttributedString ( uiAttributedString * s ) ;
// uiAttributedStringString() returns the textual content of s as a
// '\0'-terminated UTF-8 string. The returned pointer is valid until
// the next change to the textual content of s.
_UI_EXTERN const char * uiAttributedStringString ( const uiAttributedString * s ) ;
// uiAttributedStringLength() returns the number of UTF-8 bytes in
// the textual content of s, excluding the terminating '\0'.
_UI_EXTERN size_t uiAttributedStringLen ( const uiAttributedString * s ) ;
// uiAttributedStringAppendUnattributed() adds the '\0'-terminated
// UTF-8 string str to the end of s. The new substring will be
// unattributed.
_UI_EXTERN void uiAttributedStringAppendUnattributed ( uiAttributedString * s , const char * str ) ;
// uiAttributedStringInsertAtUnattributed() adds the '\0'-terminated
// UTF-8 string str to s at the byte position specified by at. The new
// substring will be unattributed; existing attributes will be moved
// along with their text.
_UI_EXTERN void uiAttributedStringInsertAtUnattributed ( uiAttributedString * s , const char * str , size_t at ) ;
// TODO add the Append and InsertAtExtendingAttributes functions
// TODO and add functions that take a string + length
// uiAttributedStringDelete() deletes the characters and attributes of
// s in the byte range [start, end).
_UI_EXTERN void uiAttributedStringDelete ( uiAttributedString * s , size_t start , size_t end ) ;
// TODO add a function to uiAttributedString to get an attribute's value at a specific index or in a specific range, so we can edit
// uiAttributedStringSetAttribute() sets a in the byte range [start, end)
// of s. Any existing attributes in that byte range of the same type are
// removed. s takes ownership of a; you should not use it after
// uiAttributedStringSetAttribute() returns.
_UI_EXTERN void uiAttributedStringSetAttribute ( uiAttributedString * s , uiAttribute * a , size_t start , size_t end ) ;
// uiAttributedStringForEachAttribute() enumerates all the
// uiAttributes in s. It is an error to modify s in f. Within f, s still
// owns the attribute; you can neither free it nor save it for later
// use.
// TODO reword the above for consistency (TODO and find out what I meant by that)
// TODO define an enumeration order (or mark it as undefined); also define how consecutive runs of identical attributes are handled here and sync with the definition of uiAttributedString itself
_UI_EXTERN void uiAttributedStringForEachAttribute ( const uiAttributedString * s , uiAttributedStringForEachAttributeFunc f , void * data ) ;
// TODO const correct this somehow (the implementation needs to mutate the structure)
_UI_EXTERN size_t uiAttributedStringNumGraphemes ( uiAttributedString * s ) ;
// TODO const correct this somehow (the implementation needs to mutate the structure)
_UI_EXTERN size_t uiAttributedStringByteIndexToGrapheme ( uiAttributedString * s , size_t pos ) ;
// TODO const correct this somehow (the implementation needs to mutate the structure)
_UI_EXTERN size_t uiAttributedStringGraphemeToByteIndex ( uiAttributedString * s , size_t pos ) ;
// uiFontDescriptor provides a complete description of a font where
// one is needed. Currently, this means as the default font of a
// uiDrawTextLayout and as the data returned by uiFontButton.
// All the members operate like the respective uiAttributes.
typedef struct uiFontDescriptor uiFontDescriptor ;
struct uiFontDescriptor {
// TODO const-correct this or figure out how to deal with this when getting a value
char * Family ;
double Size ;
uiTextWeight Weight ;
uiTextItalic Italic ;
uiTextStretch Stretch ;
} ;
// uiDrawTextLayout is a concrete representation of a
// uiAttributedString that can be displayed in a uiDrawContext.
// It includes information important for the drawing of a block of
// text, including the bounding box to wrap the text within, the
// alignment of lines of text within that box, areas to mark as
// being selected, and other things.
//
// Unlike uiAttributedString, the content of a uiDrawTextLayout is
// immutable once it has been created.
//
// TODO talk about OS-specific differences with text drawing that libui can't account for...
typedef struct uiDrawTextLayout uiDrawTextLayout ;
// uiDrawTextAlign specifies the alignment of lines of text in a
// uiDrawTextLayout.
// TODO should this really have Draw in the name?
_UI_ENUM ( uiDrawTextAlign ) {
uiDrawTextAlignLeft ,
uiDrawTextAlignCenter ,
uiDrawTextAlignRight ,
} ;
// uiDrawTextLayoutParams describes a uiDrawTextLayout.
// DefaultFont is used to render any text that is not attributed
// sufficiently in String. Width determines the width of the bounding
// box of the text; the height is determined automatically.
typedef struct uiDrawTextLayoutParams uiDrawTextLayoutParams ;
// TODO const-correct this somehow
struct uiDrawTextLayoutParams {
uiAttributedString * String ;
uiFontDescriptor * DefaultFont ;
double Width ;
uiDrawTextAlign Align ;
} ;
// @role uiDrawTextLayout constructor
// uiDrawNewTextLayout() creates a new uiDrawTextLayout from
// the given parameters.
//
// TODO
// - allow creating a layout out of a substring
// - allow marking compositon strings
// - allow marking selections, even after creation
// - add the following functions:
// - uiDrawTextLayoutHeightForWidth() (returns the height that a layout would need to be to display the entire string at a given width)
// - uiDrawTextLayoutRangeForSize() (returns what substring would fit in a given size)
// - uiDrawTextLayoutNewWithHeight() (limits amount of string used by the height)
// - some function to fix up a range (for text editing)
_UI_EXTERN uiDrawTextLayout * uiDrawNewTextLayout ( uiDrawTextLayoutParams * params ) ;
// @role uiDrawFreeTextLayout destructor
// uiDrawFreeTextLayout() frees tl. The underlying
// uiAttributedString is not freed.
_UI_EXTERN void uiDrawFreeTextLayout ( uiDrawTextLayout * tl ) ;
// uiDrawText() draws tl in c with the top-left point of tl at (x, y).
_UI_EXTERN void uiDrawText ( uiDrawContext * c , uiDrawTextLayout * tl , double x , double y ) ;
// uiDrawTextLayoutExtents() returns the width and height of tl
// in width and height. The returned width may be smaller than
// the width passed into uiDrawNewTextLayout() depending on
// how the text in tl is wrapped. Therefore, you can use this
// function to get the actual size of the text layout.
_UI_EXTERN void uiDrawTextLayoutExtents ( uiDrawTextLayout * tl , double * width , double * height ) ;
// TODO metrics functions
// TODO number of lines visible for clipping rect, range visible for clipping rect?
// uiFontButton is a button that allows users to choose a font when they click on it.
typedef struct uiFontButton uiFontButton ;
# define uiFontButton(this) ((uiFontButton *) (this))
// uiFontButtonFont() returns the font currently selected in the uiFontButton in desc.
// uiFontButtonFont() allocates resources in desc; when you are done with the font, call uiFreeFontButtonFont() to release them.
// uiFontButtonFont() does not allocate desc itself; you must do so.
// TODO have a function that sets an entire font descriptor to a range in a uiAttributedString at once, for SetFont?
_UI_EXTERN void uiFontButtonFont ( uiFontButton * b , uiFontDescriptor * desc ) ;
// TOOD SetFont, mechanics
// uiFontButtonOnChanged() sets the function that is called when the font in the uiFontButton is changed.
_UI_EXTERN void uiFontButtonOnChanged ( uiFontButton * b , void ( * f ) ( uiFontButton * , void * ) , void * data ) ;
// uiNewFontButton() creates a new uiFontButton. The default font selected into the uiFontButton is OS-defined.
_UI_EXTERN uiFontButton * uiNewFontButton ( void ) ;
// uiFreeFontButtonFont() frees resources allocated in desc by uiFontButtonFont().
// After calling uiFreeFontButtonFont(), the contents of desc should be assumed to be undefined (though since you allocate desc itself, you can safely reuse desc for other font descriptors).
// Calling uiFreeFontButtonFont() on a uiFontDescriptor not returned by uiFontButtonFont() results in undefined behavior.
_UI_EXTERN void uiFreeFontButtonFont ( uiFontDescriptor * desc ) ;
2016-01-07 17:37:43 -06:00
2016-04-23 20:38:51 -05:00
_UI_ENUM ( uiModifiers ) {
2015-10-08 17:03:24 -05:00
uiModifierCtrl = 1 < < 0 ,
uiModifierAlt = 1 < < 1 ,
uiModifierShift = 1 < < 2 ,
uiModifierSuper = 1 < < 3 ,
2016-04-23 20:38:51 -05:00
} ;
2015-10-08 17:03:24 -05:00
2015-12-17 12:54:54 -06:00
// TODO document drag captures
2015-10-08 17:03:24 -05:00
struct uiAreaMouseEvent {
2015-12-17 12:54:54 -06:00
// TODO document what these mean for scrolling areas
2015-10-14 07:49:06 -05:00
double X ;
double Y ;
2015-10-08 17:03:24 -05:00
2015-12-17 12:54:54 -06:00
// TODO see draw above
double AreaWidth ;
double AreaHeight ;
2015-10-08 17:03:24 -05:00
2016-06-13 20:20:20 -05:00
int Down ;
int Up ;
2015-10-08 17:03:24 -05:00
2016-06-13 20:20:20 -05:00
int Count ;
2015-10-08 17:03:24 -05:00
uiModifiers Modifiers ;
uint64_t Held1To64 ;
} ;
2016-04-23 20:38:51 -05:00
_UI_ENUM ( uiExtKey ) {
2015-10-08 17:03:24 -05:00
uiExtKeyEscape = 1 ,
uiExtKeyInsert , // equivalent to "Help" on Apple keyboards
uiExtKeyDelete ,
uiExtKeyHome ,
uiExtKeyEnd ,
uiExtKeyPageUp ,
uiExtKeyPageDown ,
uiExtKeyUp ,
uiExtKeyDown ,
uiExtKeyLeft ,
uiExtKeyRight ,
uiExtKeyF1 , // F1..F12 are guaranteed to be consecutive
uiExtKeyF2 ,
uiExtKeyF3 ,
uiExtKeyF4 ,
uiExtKeyF5 ,
uiExtKeyF6 ,
uiExtKeyF7 ,
uiExtKeyF8 ,
uiExtKeyF9 ,
uiExtKeyF10 ,
uiExtKeyF11 ,
uiExtKeyF12 ,
uiExtKeyN0 , // numpad keys; independent of Num Lock state
uiExtKeyN1 , // N0..N9 are guaranteed to be consecutive
uiExtKeyN2 ,
uiExtKeyN3 ,
uiExtKeyN4 ,
uiExtKeyN5 ,
uiExtKeyN6 ,
uiExtKeyN7 ,
uiExtKeyN8 ,
uiExtKeyN9 ,
uiExtKeyNDot ,
uiExtKeyNEnter ,
uiExtKeyNAdd ,
uiExtKeyNSubtract ,
uiExtKeyNMultiply ,
uiExtKeyNDivide ,
2016-04-23 20:38:51 -05:00
} ;
2015-10-08 17:03:24 -05:00
struct uiAreaKeyEvent {
char Key ;
uiExtKey ExtKey ;
uiModifiers Modifier ;
uiModifiers Modifiers ;
int Up ;
} ;
2016-05-15 19:06:57 -05:00
typedef struct uiColorButton uiColorButton ;
# define uiColorButton(this) ((uiColorButton *) (this))
_UI_EXTERN void uiColorButtonColor ( uiColorButton * b , double * r , double * g , double * bl , double * a ) ;
2016-05-15 19:51:33 -05:00
_UI_EXTERN void uiColorButtonSetColor ( uiColorButton * b , double r , double g , double bl , double a ) ;
2016-05-15 19:06:57 -05:00
_UI_EXTERN void uiColorButtonOnChanged ( uiColorButton * b , void ( * f ) ( uiColorButton * , void * ) , void * data ) ;
_UI_EXTERN uiColorButton * uiNewColorButton ( void ) ;
2016-06-07 08:56:53 -05:00
typedef struct uiForm uiForm ;
# define uiForm(this) ((uiForm *) (this))
2016-06-07 10:29:49 -05:00
_UI_EXTERN void uiFormAppend ( uiForm * f , const char * label , uiControl * c , int stretchy ) ;
2016-06-14 15:41:37 -05:00
_UI_EXTERN void uiFormDelete ( uiForm * f , int index ) ;
2016-06-07 08:56:53 -05:00
_UI_EXTERN int uiFormPadded ( uiForm * f ) ;
_UI_EXTERN void uiFormSetPadded ( uiForm * f , int padded ) ;
_UI_EXTERN uiForm * uiNewForm ( void ) ;
2016-06-09 16:15:59 -05:00
_UI_ENUM ( uiAlign ) {
uiAlignFill ,
uiAlignStart ,
uiAlignCenter ,
uiAlignEnd ,
} ;
_UI_ENUM ( uiAt ) {
uiAtLeading ,
uiAtTop ,
uiAtTrailing ,
uiAtBottom ,
} ;
typedef struct uiGrid uiGrid ;
# define uiGrid(this) ((uiGrid *) (this))
2016-06-13 20:20:20 -05:00
_UI_EXTERN void uiGridAppend ( uiGrid * g , uiControl * c , int left , int top , int xspan , int yspan , int hexpand , uiAlign halign , int vexpand , uiAlign valign ) ;
_UI_EXTERN void uiGridInsertAt ( uiGrid * g , uiControl * c , uiControl * existing , uiAt at , int xspan , int yspan , int hexpand , uiAlign halign , int vexpand , uiAlign valign ) ;
2016-06-09 16:15:59 -05:00
_UI_EXTERN int uiGridPadded ( uiGrid * g ) ;
_UI_EXTERN void uiGridSetPadded ( uiGrid * g , int padded ) ;
_UI_EXTERN uiGrid * uiNewGrid ( void ) ;
2015-11-16 09:55:44 -06:00
# ifdef __cplusplus
}
# endif
2015-08-16 16:14:46 -05:00
# endif