libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmUi.h 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. //| Copyright: (C) 2009-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #ifndef cmUi_h
  4. #define cmUi_h
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /*( { file_desc:"UI control manager for rtSys." kw:[rtSys]}
  9. cmUI implements a platform independent UI control manager
  10. for multiple simultaneous applications. In this context
  11. an 'application' can be seen as a plug-in style program.
  12. The goal of the manager is to support the easy construction
  13. of panels of graphic user interface controls.
  14. Operation:
  15. 1) A cmUi manager is allocated by the master program. See cmUiAlloc().
  16. 2) The master program then assigns a 'driver' to implmenent
  17. the commands issued by cmUi. All commands can be
  18. described using the cmUiDriverArg_t record.
  19. 3) The master program then registers client applications with
  20. the cmUi manager by calling cmUiCreateApp().
  21. 4) Prior to calling any of the client application functions
  22. the master or client app. must call cmUiSetAppId(). This
  23. function sets the current application id and thereby slightly
  24. simplifies the client app interface by not requiring the
  25. app id be passed with every client app. function call.
  26. 5) Once the current app. id is set with cmUiSetAppId()
  27. the client app can make multiple calls to the cmUi manager
  28. to create or query controls.
  29. 6) Calls to create controls result in callbacks to the
  30. driver function which manages the actual windowing and
  31. initial event handling.
  32. 7) Events generated by the driver based graphic controls
  33. are routed back to the cmUi manager through calls to
  34. cmUiOnDriverEvent().
  35. 8) The cmUiOnDriverEvent() internally caches the
  36. state/value of the control based on the event information
  37. and calls the 'cbFunc' function registered with the
  38. cmUi manager by cmUiAlloc(). This call is intended to
  39. notify the client applications of changes in the state/value
  40. of a user interface control.
  41. Notes:
  42. 1) Application id's must be unique among all applications.
  43. Control id's must be unique among all controls assigned
  44. to the same application. Both application and control id's
  45. are used internally as array indexes they should therefore
  46. be the low, positive, and densely packed integers.
  47. 2) All communication between the cmUi and the driver,
  48. and all callbacks from the cmUi to the master app.
  49. use the cmUiDriverArg_t structure
  50. 3) The panel tabs act like radio buttons. When a tab is
  51. selected the clicked tab generates one event for each
  52. tab (cId=kPanelUiCId usrId=panelId) w/ ival=1 for the
  53. selected tab and ival=0 for all other tabs.
  54. TODO:
  55. 0) [DONE] Remove the 'cbArg' from the cmUiDriverArg_t record and
  56. pass it as a separate paramenter in the cmUiDriverFunc_t calls.
  57. 1) The controls should be based on a multilevel tree model
  58. not the simple two layer panel->controls framework used now.
  59. 2) Given that access to the control values can be non-blocked
  60. and fast many controls won't need to report changes back to
  61. the client - the client can simply read the control value
  62. as necessary directly from the cmUi manager. To decrease
  63. event processing overhead controls should therefore be
  64. flagged as 'callback/no-callback'. Some controls like
  65. buttons should default to turning the flag on, while other
  66. controls, like numbers, should default to turning it off.
  67. 3) Implement support for the creation of arrays of controls.
  68. This can be implemented with a scheme similar to 'next rect'.
  69. cmUiSetupArray(uiH,panelId,baseCtlId,cnt).
  70. 4) Come up with a threading model. For example maybe
  71. control creation should use a blocking scheme since it is
  72. generally too time consuming to do during real-time operation
  73. anyway. If the control flow generated from driver event
  74. callbacks then allows value, but not structural changes,
  75. then non blocking will be necessary.
  76. 5) The cmUiDriverArg_t structure is used for both
  77. commands to the driver and callbacks from the driver.
  78. Many of the fields are not use for event callbacks.
  79. Which fields are used under which circumstances should
  80. be documented. This would allow decreasing the size
  81. of the record during serialization.
  82. 6) [DONE] Write a serialization/deserialization routines for cmUiDriverArg_t.
  83. unsigned cmUiDriverArgSerialBufByteCount(const cmUiDriverArg_t* a);
  84. cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, char* buf, bufByteCnt );
  85. cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, const char* buf, bufByteCnt );
  86. 7) There is no duplex model for validating and then displaying the
  87. value of a control.
  88. */
  89. //)
  90. //(
  91. typedef cmHandle_t cmUiH_t;
  92. extern cmUiH_t cmUiNullHandle;
  93. //=============================================================================================
  94. //
  95. // Master program API
  96. //
  97. // Allocate the cmUi manager. If the driver function is not
  98. // yet available then set drvrFunc to NULL and use
  99. // cmUiSetDriver() to set the driver function at a later
  100. // time. cmUiAlloc() stores but does not call the driver
  101. // and so it is not needed when the cmUI manager is
  102. // constructed - however it must be set prior to making
  103. // any other calls to the manager.
  104. cmUiRC_t cmUiAlloc(
  105. cmCtx_t* ctx,
  106. cmUiH_t* hp,
  107. cmUiDriverFunc_t drvrFunc, // UI driver function
  108. void* drvrArg,
  109. cmUiDriverFunc_t cbFunc, // client event callback function
  110. void* cbArg );
  111. // Release all apps but assume that the driver has already
  112. // been released.
  113. cmUiRC_t cmUiFree( cmUiH_t* hp );
  114. // Validate the cmUiH_t handle.
  115. bool cmUiIsValid( cmUiH_t h );
  116. // Set the driver function. This function allows the driver
  117. // set in cmUiAlloc() to be replaced or set following the
  118. // call to cmUiAlloc().
  119. //
  120. // By setting the driver function to
  121. // NULL the application can prevent callback to the driver.
  122. // This is useful if the driver has been release prior
  123. // to the UI manager begining destroyed.
  124. void cmUiSetDriver( cmUiH_t h, cmUiDriverFunc_t drvrFunc, void* drvrArg );
  125. // Register a client application with the cmUi manager.
  126. // 'appId' must not have been used by any other previously registered.
  127. // application.
  128. // Automatically sets and restores the ambient appId.
  129. // In a plug-in context this function is generally called
  130. // just prior a instantiating a plug-in object.
  131. cmUiRC_t cmUiCreateApp( cmUiH_t uiH, unsigned appId, unsigned asSubIdx );
  132. // Return true if 'appId' is active.
  133. bool cmUiAppIsActive( cmUiH_t uiH, unsigned appId );
  134. // Notify the cmUi manager that the resources associated
  135. // with a client application can be released.
  136. // Automatically sets and restores the ambient appId.
  137. cmUiRC_t cmUiDestroyApp( cmUiH_t uiH, unsigned appId );
  138. // Release all apps.
  139. // Automatically sets and restores the ambient appId.
  140. cmUiRC_t cmUiDestroyAllApps( cmUiH_t h );
  141. // The master program sets the ambient 'appId' prior to passing control
  142. // to a client which will make User API calls. By making the
  143. // 'appId' an ambient parameter the User API calls are slightly
  144. // simplified because they do not have to include it in each of the
  145. // function calls.
  146. //cmUiRC_t cmUiSetAppId( cmUiH_t uiH, unsigned appId );
  147. //unsigned cmUiAppId( cmUiH_t uiH );
  148. unsigned cmUiAppIdToAsSubIndex( cmUiH_t uiH, unsigned appId );
  149. // Return the count of app's.
  150. unsigned cmUiAppCount( cmUiH_t uiH );
  151. // Callbacks from the driver arrive via this function.
  152. cmUiRC_t cmUiOnDriverEvent( cmUiH_t uiH, const cmUiDriverArg_t* p );
  153. //=============================================================================================
  154. //
  155. // Client Application API
  156. //
  157. // See above note on panel tabs acting like radio buttons.
  158. cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned appId, unsigned newPanelId, const cmChar_t* label, unsigned flags );
  159. cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  160. cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, bool dflt );
  161. cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  162. cmUiRC_t cmUiCreateString( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text );
  163. cmUiRC_t cmUiCreateConsole( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text );
  164. cmUiRC_t cmUiCreateNumber( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt );
  165. cmUiRC_t cmUiCreateHSlider( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt );
  166. cmUiRC_t cmUiCreateVSlider( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt );
  167. cmUiRC_t cmUiCreateProgress( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  168. cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  169. cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  170. cmUiRC_t cmUiCreateFileBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir, const cmChar_t* patStr );
  171. cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir );
  172. cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  173. cmUiRC_t cmUiCreateMenuBtnV( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, va_list vl );
  174. cmUiRC_t cmUiCreateMenuBtnA( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, ... );
  175. cmUiRC_t cmUiCreateMenuBtnJson( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmJsonNode_t* root, const cmChar_t* memberLabel );
  176. cmUiRC_t cmUiCreateList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt );
  177. cmUiRC_t cmUiCreateListV( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, va_list vl );
  178. cmUiRC_t cmUiCreateListA( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, ... );
  179. cmUiRC_t cmUiCreateListJson( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmJsonNode_t* root, const cmChar_t* memberLabel );
  180. // If 'id' identifies a 'list' control use tabs as column separators.
  181. cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* text, unsigned eleId );
  182. // Remove all the elements of a list control.
  183. cmUiRC_t cmUiClearList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id );
  184. // Enable/Disable a control
  185. cmUiRC_t cmUiEnableCtl( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, bool enableFl );
  186. // Enable/disable all controls on a panel except those included in the var args list.
  187. // Terminate the var args list with cmInvalidId.
  188. cmUiRC_t cmUiEnableAllExceptV( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, va_list vl );
  189. cmUiRC_t cmUiEnableAllExcept( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, ... );
  190. // If 'id' identifies a panel then all control belonging to the panel
  191. // will also be destroyed.
  192. cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned appId, unsigned id );
  193. // Returns true if the control exists.
  194. // For panels set id=panelId.
  195. //bool cmUiCtlExists( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id );
  196. // Destroy all the controls in a panel.
  197. cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned appId, unsigned panelId );
  198. cmUiRC_t cmUiSelectPanel( cmUiH_t uiH, const cmChar_t* label );
  199. //------------------------------------------------------------------------------------------
  200. // Location:
  201. // 1) If a 'next rect' is set the control will be placed according to it.
  202. // 2) If cmUiSetBaseCol() was set then the control will be placed at the
  203. // base col and base row.
  204. // 3) If cmUiPlaceRight() or cmUIPlaceBelow() have been called since the
  205. // previous control was created then the new control will be placed
  206. // accordingly.
  207. // 4) The control will be placed according to the 'fill rows' flag.
  208. // If not set (default) the new control will be placed in the
  209. // base column below the previous control.
  210. // If 'fill rows' is set the new control will be placed on the
  211. // same row to the right of the previous control.
  212. // If there is no previous control then it will be placed
  213. // in the base column and base row.
  214. // Get/Set the fill directions. If the 'fill columns' flag is enabled
  215. // then the next control is placed below the previous control otherwise
  216. // the next control is placed to the right of the next control.
  217. bool cmUiFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId );
  218. bool cmUiSetFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl );
  219. // Place the next control to the right/below of the previous ctl.
  220. // These flags override the current fill row/col setting.
  221. // Note that 'place right' and 'place below' are mutually
  222. // exclusive. Enabling one disables the other.
  223. void cmUiPlaceRight( cmUiH_t uiH, unsigned appId, unsigned panelId );
  224. void cmUiPlaceBelow( cmUiH_t uiH, unsigned appId, unsigned panelId );
  225. // Place the next control at the base column below the previous ctl.
  226. void cmUiNewLine( cmUiH_t uiH, unsigned appId, unsigned panelId );
  227. // Set/Get current base col and return previous value. Place the next
  228. // control on the base row.
  229. int cmUiBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId );
  230. int cmUiSetBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId, int x );
  231. // Set/Get current base row and return previous value.
  232. int cmUiBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId );
  233. int cmUiSetBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId, int y );
  234. // Size:
  235. // 1) If a 'next rect' is set the control will be placed according
  236. // to it.
  237. // 2) If a 'next w/h' is set the control will be placed according
  238. // to it. The 'next w/h' setting is only active for the
  239. // next control created.
  240. // 3) The w/h of the new control will be set to the default w/h.
  241. //
  242. // Get/Set the default control width and height.
  243. // Set returns previous value.
  244. int cmUiW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  245. int cmUiH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  246. int cmUiSetW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  247. int cmUiSetH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  248. void cmUiSetWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h );
  249. // Get/Set the control width and height for only the next control.
  250. // Set returns previous value.
  251. int cmUiNextW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  252. int cmUiNextH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  253. void cmUiSetNextW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  254. void cmUiSetNextH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  255. void cmUiSetNextWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h );
  256. // Get/Set the default inter-control borders
  257. // Set returns previous value.
  258. int cmUiHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  259. int cmUiVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  260. int cmUiSetHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  261. int cmUiSetVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  262. // Get/Set the 'next' inter-control borders
  263. // Set returns previous value.
  264. int cmUiNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  265. int cmUiNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  266. int cmUiSetNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  267. int cmUiSetNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  268. // Place the next control at the following coordinates. The
  269. // specified coordinates are only active during the next
  270. // cmUiCreateXXX() call. Setting the 'next rect' overrides all
  271. // other layout directives.
  272. cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int x, int y, int w, int h );
  273. // Get the location/size of the previously created control.
  274. // All ref. args are optional.
  275. cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int* xRef, int* yRef, int* wRef, int* hRef );
  276. int cmUiPrevL( cmUiH_t uiH, unsigned appId, unsigned panelId );
  277. int cmUiPrevT( cmUiH_t uiH, unsigned appId, unsigned panelId );
  278. int cmUiPrevR( cmUiH_t uiH, unsigned appId, unsigned panelId );
  279. int cmUiPrevB( cmUiH_t uiH, unsigned appId, unsigned panelId );
  280. int cmUiPrevW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  281. int cmUiPrevH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  282. //------------------------------------------------------------------------------------------
  283. //
  284. // Get/set the value of UI control.
  285. //
  286. // TODO:
  287. // + Need functions for setting auxilliary values like
  288. // min,max,etc..
  289. // Set the value associated with a control.
  290. // Set the local value of the specified control and then
  291. // send the value to the UI driver so that the UI reflects this value.
  292. cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned appId, unsigned id, int v );
  293. cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned appId, unsigned id, unsigned v );
  294. cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned appId, unsigned id, double v );
  295. cmUiRC_t cmUiSetString( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* v );
  296. cmUiRC_t cmUiSetVPrintf(cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, va_list vl );
  297. cmUiRC_t cmUiSetPrintf( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, ... );
  298. // Get the value associated with a control. These functions return
  299. // the control value cached in the local control, they do not need
  300. // to call the driver and are therefore very fast.
  301. int cmUiInt( cmUiH_t uiH, unsigned appId, unsigned id );
  302. unsigned cmUiUInt( cmUiH_t uiH, unsigned appId, unsigned id );
  303. double cmUiDouble( cmUiH_t uiH, unsigned appId, unsigned id );
  304. const cmChar_t* cmUiString( cmUiH_t uiH, unsigned appId, unsigned id );
  305. unsigned cmUiListEleCount( cmUiH_t uiH, unsigned appId, unsigned id );
  306. unsigned cmUiListEleId( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index );
  307. const cmChar_t* cmUiListEleLabel( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index );
  308. unsigned cmUiListEleLabelToIndex( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* label );
  309. // Query/set the current error state.
  310. cmUiRC_t cmUiLastRC( cmUiH_t uiH );
  311. cmUiRC_t cmUiSetRC( cmUiH_t uiH, cmUiRC_t rc );
  312. //)
  313. #ifdef __cplusplus
  314. }
  315. #endif
  316. #endif