fst_api.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. Formspec toolkit api 0.0.3
  2. ==========================
  3. Formspec toolkit is a set of functions to create basic ui elements.
  4. File: fst/ui.lua
  5. ----------------
  6. ui.lua adds base ui interface to add additional components to.
  7. ui.add(component) -> returns name of added component
  8. ^ add component to ui
  9. ^ component: component to add
  10. ui.delete(component) -> true/false if a component was deleted or not
  11. ^ remove a component from ui
  12. ^ component: component to delete
  13. ui.set_default(name)
  14. ^ set component to show if not a single component is set visible
  15. ^ name: name of component to set as default
  16. ui.find_by_name(name) --> returns component or nil
  17. ^ find a component within ui
  18. ^ name: name of component to look for
  19. File: fst/tabview.lua
  20. ---------------------
  21. tabview_create(name, size, tabheaderpos) --> returns tabview component
  22. ^ create a new tabview component
  23. ^ name: name of tabview (has to be unique per ui)
  24. ^ size: size of tabview
  25. {
  26. x,
  27. y
  28. }
  29. ^ tabheaderpos: upper left position of tabheader (relative to upper left fs corner)
  30. {
  31. x,
  32. y
  33. }
  34. Class reference tabview:
  35. methods:
  36. - add_tab(tab)
  37. ^ add a tab to this tabview
  38. ^ tab:
  39. {
  40. name = "tabname", -- name of tab to create
  41. caption = "tab caption", -- text to show for tab header
  42. cbf_button_handler = function(tabview, fields, tabname, tabdata), -- callback for button events
  43. --TODO cbf_events = function(tabview, event, tabname), -- callback for events
  44. cbf_formspec = function(tabview, name, tabdata), -- get formspec
  45. tabsize =
  46. {
  47. x, -- x width
  48. y -- y height
  49. }, -- special size for this tab (only relevant if no parent for tabview set)
  50. on_change = function(type,old_tab,new_tab) -- called on tab change, type is "ENTER" or "LEAVE"
  51. }
  52. - set_autosave_tab(value)
  53. ^ tell tabview to automatically save current tabname as "tabview_name"_LAST
  54. ^ value: true/false
  55. - set_tab(name)
  56. ^ set's tab to tab named "name", returns true/false on success
  57. ^ name: name of tab to set
  58. - set_global_event_handler(handler)
  59. ^ set a handler to be called prior calling tab specific event handler
  60. ^ handler: function(tabview,event) --> returns true to finish event processing false to continue
  61. - set_global_button_handler(handler)
  62. ^ set a handler to be called prior calling tab specific button handler
  63. ^ handler: function(tabview,fields) --> returns true to finish button processing false to continue
  64. - set_parent(parent)
  65. ^ set parent to attach tabview to. TV's with parent are hidden if their parent
  66. is hidden and they don't set their specified size.
  67. ^ parent: component to attach to
  68. - show()
  69. ^ show tabview
  70. - hide()
  71. ^ hide tabview
  72. - delete()
  73. ^ delete tabview
  74. - set_fixed_size(state)
  75. ^ true/false set to fixed size, variable size
  76. File: fst/dialog.lua
  77. ---------------------
  78. Only one dialog can be shown at a time. If a dialog is closed it's parent is
  79. gonna be activated and shown again.
  80. dialog_create(name, cbf_formspec, cbf_button_handler, cbf_events)
  81. ^ create a dialog component
  82. ^ name: name of component (unique per ui)
  83. ^ cbf_formspec: function to be called to get formspec
  84. function(dialogdata)
  85. ^ cbf_button_handler: function to handle buttons
  86. function(dialog, fields)
  87. ^ cbf_events: function to handle events
  88. function(dialog, event)
  89. messagebox(name, message)
  90. ^ creates a message dialog
  91. Class reference dialog:
  92. methods:
  93. - set_parent(parent)
  94. ^ set parent to attach a dialog to
  95. ^ parent: component to attach to
  96. - show()
  97. ^ show dialog
  98. - hide()
  99. ^ hide dialog
  100. - delete()
  101. ^ delete dialog from ui
  102. members:
  103. - data
  104. ^ variable data attached to this dialog
  105. - parent
  106. ^ parent component to return to on exit
  107. File: fst/buttonbar.lua
  108. -----------------------
  109. buttonbar_create(name, cbf_buttonhandler, pos, orientation, size)
  110. ^ create a buttonbar
  111. ^ name: name of component (unique per ui)
  112. ^ cbf_buttonhandler: function to be called on button pressed
  113. function(buttonbar,buttonname,buttondata)
  114. ^ pos: position relative to upper left of current shown formspec
  115. {
  116. x,
  117. y
  118. }
  119. ^ orientation: "vertical" or "horizontal"
  120. ^ size: size of bar
  121. {
  122. width,
  123. height
  124. }
  125. Class reference buttonbar:
  126. methods:
  127. - add_button(btn_id, caption, button_image)
  128. - set_parent(parent)
  129. ^ set parent to attach a buttonbar to
  130. ^ parent: component to attach to
  131. - show()
  132. ^ show buttonbar
  133. - hide()
  134. ^ hide buttonbar
  135. - delete()
  136. ^ delete buttonbar from ui
  137. Developer doc:
  138. ==============
  139. Skeleton for any component:
  140. {
  141. name = "some id", -- unique id
  142. type = "toplevel", -- type of component
  143. -- toplevel: component can be show without additional components
  144. -- addon: component is an addon to be shown along toplevel component
  145. hide = function(this) end, -- called to hide the component
  146. show = function(this) end, -- called to show the component
  147. delete = function(this) end, -- called to delete component from ui
  148. handle_buttons = function(this,fields) -- called upon button press
  149. handle_events = function(this,event) -- called upon event reception
  150. get_formspec = function(this) -- has to return formspec to be displayed
  151. }