Advertisement
awsumben13

Flare demo

Aug 18th, 2015
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.60 KB | None | 0 0
  1. if not fs.exists "Flare" then
  2.     print "Downloading Flare"
  3.     local h = http.get "http://pastebin.com/raw.php?i=SD25GhYf"
  4.     if h then
  5.         local f, err = load( h.readAll(), "installer", nil, _ENV or getfenv() )
  6.         h.close()
  7.         f()
  8.     else
  9.         return error( "Cannot install Flare", 0 )
  10.     end
  11. end
  12. local files = {
  13.     ["init"] = "\
  14. require \"UIButton\"\
  15. require \"UICheckbox\"\
  16. require \"UIColourSelector\"\
  17. require \"UIContainer\"\
  18. require \"UILabel\"\
  19. require \"UIPanel\"\
  20. require \"UIRadioButton\"\
  21. require \"UITabs\"\
  22. require \"UITerminal\"\
  23. require \"UIText\"\
  24. require \"UITextInput\"\
  25. require \"UIToggle\"\
  26. \
  27. application.view:createShortcut( \"terminate\", \"ctrl-t\", function()\
  28. \9application:stop()\
  29. end )\
  30. \
  31. local text = application.view:addChild( UIText( 0, 0, term.getSize(), 1, \"@acFlare demo @t8(use the tabs below to navigate)\" ) )\
  32. function text:onParentResized()\
  33. \9self.width = self.parent.width\
  34. end\
  35. \
  36. local options = {\
  37. \9\"Button\";\
  38. \9\"Checkbox\";\
  39. \9\"ColourSelector\";\
  40. \9\"Container\";\
  41. \9\"FileDialogue\";\
  42. \9\"Image\";\
  43. \9\"Label\";\
  44. \9\"Panel\";\
  45. \9\"RadioButton\";\
  46. \9\"Tabs\";\
  47. \9\"Terminal\";\
  48. \9\"Text\";\
  49. \9\"TextInput\";\
  50. \9\"Toggle\";\
  51. \9\"View\";\
  52. \9\"Window\";\
  53. }\
  54. \
  55. local tabs = application.view:addChild( UITabs( 0, 1, term.getSize(), options ) )\
  56. function tabs:onParentResized()\
  57. \9self.width = self.parent.width\
  58. end\
  59. \
  60. local frames = {}\
  61. local prev, previ\
  62. \
  63. function tabs:onSelect()\
  64. \9if prev then\
  65. \9\9text.text = \"@acFlare demo @t8- \" .. self.options[self.selected]\
  66. \9\9if self.selected > previ then\
  67. \9\9\9prev:transitionOutLeft()\
  68. \9\9else\
  69. \9\9\9prev:transitionOutRight()\
  70. \9\9end\
  71. \9end\
  72. \9frames[self.selected].width = application.view.width\
  73. \9frames[self.selected].height = application.view.height - 2\
  74. \9if prev and self.selected < previ then\
  75. \9\9frames[self.selected].parent = application.view\
  76. \9\9frames[self.selected]:transitionInLeft()\
  77. \9else\
  78. \9\9frames[self.selected].parent = application.view\
  79. \9\9frames[self.selected]:transitionInRight()\
  80. \9end\
  81. \9prev = frames[self.selected]\
  82. \9previ = self.selected\
  83. end\
  84. \
  85. for i = 1, #options do\
  86. \9frames[i] = UIContainer( 0, 2, application.view.width, application.view.height - 2 )\
  87. \9frames[options[i]] = frames[i]\
  88. \
  89. \9frames[i].onParentResized = function( self )\
  90. \9\9self.width, self.height = application.view.width, application.view.height - 2\
  91. \9end\
  92. end\
  93. \
  94. tabs:select( 1 )\
  95. \
  96. --[ Button demo ]---------------------------------------------------------------------------------------------------\
  97. \
  98. local button1 = frames.Button:addChild( UIButton( math.floor( application.view.width / 2 - 10 ), 1, 20, 3, \"Hello world!\" ) )\
  99. button1.colour = colours.cyan\
  100. button1.textColour = colours.white\
  101. \
  102. local button2 = frames.Button:addChild( UIButton( math.floor( application.view.width / 2 - 10 ), 5, 20, 3, \"Click to animate\" ) )\
  103. button2.colour = colours.red\
  104. button2.textColour = colours.white\
  105. \
  106. function button1:onParentResized()\
  107. \9self.x = math.floor( self.parent.width / 2 - 10 )\
  108. end\
  109. \
  110. function button1:onClick()\
  111. \9self.colour = 2 ^ math.random( 1, 14 )\
  112. end\
  113. \
  114. local s = false\
  115. function button2:onClick()\
  116. \9self.animatedY = s and 5 or self.parent.height - 4\
  117. \9s = not s\
  118. end\
  119. \
  120. function button2:onParentResized()\
  121. \9self.x = math.floor( self.parent.width / 2 - 10 )\
  122. \9if s then\
  123. \9\9self.y = self.parent.height - 4\
  124. \9end\
  125. end\
  126. \
  127. --[ Checkbox demo ]-------------------------------------------------------------------------------------------------\
  128. \
  129. for i = 1, 7 do\
  130. \9local checkbox = frames.Checkbox:addChild( UICheckbox( 1, 2 * i - 1 ) )\
  131. \9local label = frames.Checkbox:addChild( UILabel( 3, 2 * i - 1, \"Option \" .. i, checkbox ) )\
  132. \
  133. \9function checkbox:onToggle()\
  134. \9\9if i % 2 == 1 then\
  135. \9\9\9label.animatedX = self.toggled and 10 or 3\
  136. \9\9else\
  137. \9\9\9label.textColour = self.toggled and colours.blue or colours.lightGrey\
  138. \9\9end\
  139. \9end\
  140. end\
  141. \
  142. --[ ColourSelector demo ]-------------------------------------------------------------------------------------------\
  143. \
  144. frames.ColourSelector:addChild( UIText( 1, 1, 34, 1, \"@ac@t8Click the colours\" ) )\
  145. \
  146. local selectors = {\
  147. \9frames.ColourSelector:addChild( UIColourSelector(  3,  3, 32,  2, 16/1 ) );\
  148. \9frames.ColourSelector:addChild( UIColourSelector(  3,  6, 16,  4,  8/2 ) );\
  149. \9frames.ColourSelector:addChild( UIColourSelector(  3, 11, 12,  8,  4/4 ) );\
  150. \9frames.ColourSelector:addChild( UIColourSelector( 16, 11,  4,  2,  2/8 ) );\
  151. \9frames.ColourSelector:addChild( UIColourSelector(  1,  3,  1, 16, 1/16 ) );\
  152. }\
  153. \
  154. local panel = frames.ColourSelector:addChild( UIPanel( 21, 6, 14, 13 ) )\
  155. \
  156. for i = 1, #selectors do\
  157. \9selectors[i].onSelect = function( _, colour )\
  158. \9\9panel.colour = colour\
  159. \9end\
  160. end\
  161. \
  162. --[ Container demo ]------------------------------------------------------------------------------------------------\
  163. \
  164. local frame = frames.Container:addChild( UIContainer( 0, 0, frames.Container.width, frames.Container.height ) )\
  165. for i = 1, 40 do\
  166. \9local button = frame:addChild( UIButton( 1, i - 1, frame.width - 3, 1, i ) )\
  167. \9button.colour = i % 2 == 1 and colours.lightGrey or colours.white\
  168. end\
  169. \
  170. local expl = frames.Container:addChild( UIText( math.floor( frames.Container.width / 2 - 10 ), math.floor( frames.Container.height / 2 - 3.5 ), 20, 7, \"@acThis demo is showing how a container automatically adds scrollbars when the content size overflows the display size.\" ) )\
  171. expl.colour = colours.cyan\
  172. expl.textColour = colours.white\
  173. \
  174. function frame:onParentResized()\
  175. \9self.width = self.parent.width\
  176. \9self.height = self.parent.height\
  177. \9for i = 1, #self.children do\
  178. \9\9self.children[i].width = self.width - 3\
  179. \9end\
  180. \9expl.x = math.floor( self.width / 2 - expl.width / 2 )\
  181. \9expl.y = math.floor( self.height / 2 - expl.height / 2 )\
  182. end\
  183. \
  184. --[ FileDialogue demo ]---------------------------------------------------------------------------------------------\
  185. \
  186. \
  187. --[ Image demo ]----------------------------------------------------------------------------------------------------\
  188. \
  189. \
  190. --[ Label demo ]----------------------------------------------------------------------------------------------------\
  191. \
  192. local label = frames.Label:addChild( UIText( 1, 1, frames.Label.width - 2, 2, \"@acClick the label of each one to see it do something\" ) )\
  193. \
  194. local checkbox = frames.Label:addChild( UICheckbox( 2, 4 ) )\
  195. local checkboxl = frames.Label:addChild( UILabel( 5, 4, \"Checkbox\", checkbox ) )\
  196. \
  197. local radio = frames.Label:addChild( UIRadioButton( 2, 6 ) )\
  198. local radiol = frames.Label:addChild( UILabel( 5, 6, \"RadioButton\", radio ) )\
  199. \
  200. local toggle = frames.Label:addChild( UIToggle( 1, 8, 3, 1 ) )\
  201. local togglel = frames.Label:addChild( UILabel( 5, 8, \"Toggle\", toggle ) )\
  202. \
  203. function label:onParentResized()\
  204. \9self.width = self.parent.width - 2\
  205. end\
  206. \
  207. --[ Panel demo ]----------------------------------------------------------------------------------------------------\
  208. \
  209. local left = frames.Panel:addChild( UIPanel( 0, 0, math.floor( frames.Panel.width / 2 ), frames.Panel.height, colours.blue ) )\
  210. local right = frames.Panel:addChild( UIPanel( left.width, 0, frames.Panel.width - left.width, frames.Panel.height, colours.red ) )\
  211. \
  212. function left:onParentResized()\
  213. \9self.width = math.floor( self.parent.width / 2 )\
  214. \9self.height = self.parent.height\
  215. end\
  216. function right:onParentResized()\
  217. \9self.x = left.width\
  218. \9self.width = self.parent.width - left.width\
  219. \9self.height = self.parent.height\
  220. end\
  221. \
  222. --[ RadioButton demo ]----------------------------------------------------------------------------------------------\
  223. \
  224. for i = 1, 10 do\
  225. \9local group = i < 6 and \"One\" or \"Two\"\
  226. \9local y = i < 6 and 2 * i + 1 or 2 * i + 3\
  227. \9local button = frames.RadioButton:addChild( UIRadioButton( 3, y ) )\
  228. \9button.group = group\
  229. \9frames.RadioButton:addChild( UILabel( 5, y, \"Button \" .. i, button ) )\
  230. end\
  231. frames.RadioButton:addChild( UILabel( 1, 1, \"Group 1\" ) )\
  232. frames.RadioButton:addChild( UILabel( 1, 13, \"Group 2\" ) )\
  233. \
  234. --[ Tabs demo ]-----------------------------------------------------------------------------------------------------\
  235. \
  236. local longoptions = {}\
  237. for i = 1, 20 do\
  238. \9math.randomseed( i )\
  239. \9longoptions[i] = \"Number \" .. math.random( 0, 99 )\
  240. end\
  241. \
  242. local label1 = frames.Tabs:addChild( UIText( 1, 1, frames.Tabs.width - 2, 1, \"@t8Tabs that don't overflow look like this.\" ) )\
  243. local tabs1 = frames.Tabs:addChild( UITabs( 1, 3, frames.Tabs.width - 2, { \"Option 1\",\9\"Option 2\",\9\"Option 3\" } ) )\
  244. tabs1:select( 1 )\
  245. \
  246. local label2 = frames.Tabs:addChild( UIText( 1, 5, frames.Tabs.width - 2, 2, \"@t8Tabs that overflow look like this.\\nUse the arrows or click and drag to scroll.\" ) )\
  247. local tabs2 = frames.Tabs:addChild( UITabs( 1, 8, frames.Tabs.width - 2, longoptions ) )\
  248. tabs2:select( 1 )\
  249. \
  250. local label3 = frames.Tabs:addChild( UIText( 1, 10, frames.Tabs.width - 2, 1, \"@t8They have dynamic resizing too.\" ) )\
  251. local tabs3 = frames.Tabs:addChild( UITabs( 1, 12, 32, { \"Option 1\", \"Option 2\", \"Option 3\" } ) )\
  252. tabs3:select( 1 )\
  253. \
  254. local s = false\
  255. local toggletab = frames.Tabs:addChild( UIButton( 1, 14, 20, 3, \"Shrink\" ) )\
  256. toggletab.colour = colours.cyan\
  257. toggletab.textColour = colours.white\
  258. \
  259. function toggletab:onClick()\
  260. \9tabs3.animatedWidth = s and 32 or 20\
  261. \9self.text = s and \"Shrink\" or \"Expand\"\
  262. \9s = not s\
  263. end\
  264. \
  265. function label1:onParentResized()\
  266. \9self.width = self.parent.width - 2\
  267. end\
  268. \
  269. function label2:onParentResized()\
  270. \9self.width = self.parent.width - 2\
  271. end\
  272. \
  273. function label3:onParentResized()\
  274. \9self.width = self.parent.width - 2\
  275. end\
  276. \
  277. function tabs2:onParentResized()\
  278. \9self.width = self.parent.width - 2\
  279. end\
  280. \
  281. --[ Terminal demo ]------------------------------------------------------------------------------------------------\
  282. \
  283. local terminal = frames.Terminal:addChild( UITerminal( 0, 0, frames.Terminal.width, frames.Terminal.height ) )\
  284. local co = coroutine.create( loadfile \"rom/programs/shell\" )\
  285. local running = true\
  286. \
  287. function terminal:onEvent( ... )\
  288. \9if not running then return end\
  289. \9local old = self:wrap()\
  290. \9coroutine.resume( co, ... )\
  291. \9running = coroutine.status( co ) ~= \"dead\"\
  292. \9term.redirect( old )\
  293. end\
  294. \
  295. terminal:onEvent()\
  296. \
  297. local old = terminal:wrap()\
  298. print \"This is just an example, this can run any program or function, not just the shell.\"\
  299. term.setTextColour( colours.yellow )\
  300. term.write \"> \"\
  301. term.setTextColour( colours.white )\
  302. term.redirect( old )\
  303. \
  304. function terminal:onParentResized()\
  305. \9self.width = self.parent.width\
  306. \9self.height = self.parent.height\
  307. end\
  308. \
  309. --[ Text demo ]----------------------------------------------------------------------------------------------------\
  310. \
  311. local text = frames.Text:addChild( UIText( 1, 1, math.min( frames.Text.width - 2, 49 ), math.min( frames.Text.height - 2, 15 ), [[\
  312. Ok, here's a challenge, let's make a text object with multiple @t9text colour@t7 and @b1@t0background colour@t7@b0 that word wraps, and also allows\
  313. \
  314. @acmultiple alignments\
  315. \
  316. @arthat is loaded from a single string.\
  317. \
  318. @alDifficult? Nah.\
  319. \
  320. Oh, did I mention you can select text here? Yeah, you can select text here, and copy it in fact. Just use @t8ctrl-c@t7 to copy it, then you can go and put it in something else, for example the text input boxes in the TextInput demo.\
  321. \
  322. Nearly forgot, you have to use @t8ctrl-b@t7 to paste from the CC clipboard because ctrl-v pastes from your actual clipboard.\
  323. \
  324. Hey, look, you found the text down here eh? Text objects have automatic scrollbars too!\
  325. ]] ) )\
  326. \
  327. function text:onParentResized()\
  328. \9self.width = math.min( self.parent.width - 2, 49 )\
  329. \9self.height = math.min( self.parent.height - 2, 15 )\
  330. end\
  331. \
  332. --[ TextInput demo ]-----------------------------------------------------------------------------------------------\
  333. \
  334. local usrin = frames.TextInput:addChild( UITextInput( 1, 2, frames.TextInput.width - 2, 1 ) )\
  335. usrin.focussedColour = colours.lightGrey\
  336. local usrlb = frames.TextInput:addChild( UILabel( 1, 1, \"username\", usrin ) )\
  337. \
  338. local passin = frames.TextInput:addChild( UITextInput( 1, 5, frames.TextInput.width - 2, 1 ) )\
  339. passin.focussedColour = colours.lightGrey\
  340. local passlb = frames.TextInput:addChild( UILabel( 1, 4, \"password\", passin ) )\
  341. \
  342. passin.mask = \"*\"\
  343. \
  344. function usrin:onTab()\
  345. \9passin:focusOn()\
  346. end\
  347. function usrin:onEnter()\
  348. \9passin:focusOn()\
  349. end\
  350. function passin:onTab()\
  351. \9usrin:focusOn()\
  352. end\
  353. \
  354. function usrin:onParentResized()\
  355. \9self.width = self.parent.width - 2\
  356. end\
  357. \
  358. function passin:onParentResized()\
  359. \9self.width = self.parent.width - 2\
  360. end\
  361. \
  362. local inputlower = frames.TextInput:addChild( UITextInput( 1, 7, 24, 1 ) )\
  363. inputlower.focussedColour = colours.cyan\
  364. inputlower.focussedTextColour = colours.red\
  365. inputlower.colour = colours.pink\
  366. inputlower.textColour = colours.green\
  367. inputlower.selectedColour = colours.brown\
  368. inputlower.selectedTextColour = colours.orange\
  369. \
  370. local expl = frames.TextInput:addChild( UIText( 1, 9, frames.TextInput.width - 2, frames.TextInput.height - 10, \"Note there are some keyboard shortcuts with these. @t8ctrl-c@t7,@t8 ctrl-x@t7,@t8 ctrl-v@t7,@t8 @t7and@t8 ctrl-b@t7, for pasting tools. @t8shift-left/right@t7 to select text, enter, backspace, tab, delete, left and right for changing text and moving around, home and end for jumping to the start or end. Remember you can click and drag to select text, or use @t8ctrl-a@t7 to select everything.\" ) )\
  371. function expl:onParentResized()\
  372. \9self.width = self.parent.width - 2\
  373. \9self.height = self.parent.height - self.y - 1\
  374. end";
  375. }
  376. loadfile "Flare/run.lua" ( files, "init" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement