databinding.rml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <rml>
  2. <head>
  3. <link type="text/template" href="../../../assets/window.rml"/>
  4. <title>Data Binding Sample</title>
  5. <style>
  6. body.window
  7. {
  8. width: 1300px;
  9. height: 750px;
  10. min-width: 1090px;
  11. min-height: 300px;
  12. max-width: -1px;
  13. max-height: -1px;
  14. }
  15. div#title_bar div#icon
  16. {
  17. display: none;
  18. }
  19. div#content
  20. {
  21. position: relative;
  22. }
  23. tabset
  24. {
  25. display: block;
  26. }
  27. tabs
  28. {
  29. display: block;
  30. position: fixed;
  31. clip: none;
  32. text-align: right;
  33. top: -47px;
  34. left: 205px;
  35. right: 10px;
  36. }
  37. tab
  38. {
  39. display: inline-block;
  40. width: 100px;
  41. padding: 0px 20px;
  42. line-height: 40px;
  43. font-size: 16px;
  44. color: #ddd;
  45. text-align: center;
  46. decorator: tiled-horizontal( datagridheader-l, datagridheader-c, datagridheader-r );
  47. image-color: #cffc;
  48. }
  49. tab:hover
  50. {
  51. image-color: #fffe;
  52. color: #fff;
  53. }
  54. tab:active, tab:selected
  55. {
  56. image-color: #fff;
  57. color: #fff;
  58. }
  59. panels
  60. {
  61. display: block;
  62. }
  63. panel
  64. {
  65. display: block;
  66. padding: 30px;
  67. margin-left: auto;
  68. margin-right: auto;
  69. max-width: 500px;
  70. }
  71. h1
  72. {
  73. margin: 1.4em 0 0.7em;
  74. font-size: 18px;
  75. }
  76. p.title
  77. {
  78. font-size: 35px;
  79. color: #b33;
  80. font-effect: glow(2px #ed5);
  81. }
  82. .center {
  83. text-align: center;
  84. }
  85. .clickable
  86. {
  87. cursor: pointer;
  88. }
  89. .red {
  90. color: #e44;
  91. }
  92. .big {
  93. font-size: 1.8em;
  94. }
  95. .mouse_detector {
  96. width: 300px;
  97. min-height: 2em;
  98. line-height: 30px;
  99. background-color: #909090;
  100. border: 1px #666;
  101. margin: 2em auto;
  102. cursor: pointer;
  103. }
  104. /*** Forms ***/
  105. form {
  106. display: block;
  107. text-align: left;
  108. }
  109. form input, form select {
  110. margin-left: 0;
  111. }
  112. form input.text, form input.password {
  113. width: 35%;
  114. }
  115. input.text.two-wide {
  116. width: 70%;
  117. }
  118. form h2 {
  119. display: block;
  120. font-size: 16px;
  121. font-weight: bold;
  122. margin-top: 8px;
  123. }
  124. #rating {
  125. display: inline-block;
  126. width: 40px;
  127. padding-left: 1em;
  128. }
  129. #rating_emoji {
  130. color: #ffd40f;
  131. font-size: 1.7em;
  132. }
  133. #controls textarea
  134. {
  135. font-size: 18px;
  136. font-effect: outline(2px #006600);
  137. color: #ddd;
  138. }
  139. </style>
  140. </head>
  141. <body template="window">
  142. <tabset id="menu">
  143. <tab>Basics</tab>
  144. <panel data-model="basics">
  145. <h1>{{title}}</h1>
  146. <p data-if="show_text">The quick brown fox jumps over the lazy {{animal}}.</p>
  147. <input type="text" data-value="animal"/>
  148. </panel>
  149. <tab>Events</tab>
  150. <panel id="welcome" data-model="events">
  151. <p class="title" style="margin-top: 1.8em;">{{hello_world}}<span style="color: blue;"> Rated: {{rating}}</span></p>
  152. <p>Data binding demo. We rate this a good old {{rating}}!</p>
  153. <input type="range" name="rating" min="0" max="100" step="1" value="50" data-value="rating"/>
  154. <div data-visible="rating > 50">Thanks for the <span data-if="rating < 80">good</span><span data-if="rating >= 80">awesome</span> rating!</div>
  155. <div class="mouse_detector" style="height: 70px;"
  156. data-event-mousemove="mouse_detector = 'x: ' + ev.mouse_x + '<br/>y: ' + ev.mouse_y"
  157. data-event-click="add_mouse_pos(); hello_world = 'Hello click!'"
  158. data-rml="mouse_detector">
  159. </div>
  160. <div class="mouse_detector" data-if="positions.size > 0" data-event-click="clear_positions">
  161. Recorded mouse positions.<br/>
  162. <span data-for="pos : positions"> x: {{ pos.x }}, y: {{ pos.y }}<br/></span>
  163. </div>
  164. <img sprite="icon-invader" data-style-image-color="rating < 80 ? 'black' : 'green'"/>
  165. <p>
  166. For loop with data expressions:<br/>
  167. <span style="padding-left: 1em;" data-for="i : list"> {{ i * 2 + (!(i < 10) ? ' wow!' | to_upper : '') }}</span>
  168. </p>
  169. </panel>
  170. <tab>Invaders</tab>
  171. <panel id="invaders" data-model="invaders">
  172. <p>
  173. Incoming invaders:
  174. <input type="range" name="rating" min="0" max="20" step="5" data-value="incoming_invaders_rate"/>
  175. {{ incoming_invaders_rate }} / min.
  176. </p>
  177. <button data-event-click="launch_weapons">Launch weapons!</button>
  178. <div data-for="invader : invaders">
  179. <h1 data-class-red="invader.danger_rating > 70">{{invader.name}}</h1>
  180. <p>Invader {{it_index + 1}} of {{ invaders.size }}.</p>
  181. <img data-attr-sprite="invader.sprite" data-style-image-color="invader.color"/>
  182. <p>
  183. Shots fired (damage): <span data-for="invader.damage"> {{it}} </span>
  184. </p>
  185. </div>
  186. <h1 data-if="invaders.size == 0">It's all safe and sound, sir!</h1>
  187. </panel>
  188. <tab>Forms</tab>
  189. <panel id="controls">
  190. <h1>Todo</h1>
  191. <form onsubmit="submit_form">
  192. <h2>Full name</h2>
  193. <div>
  194. <input class="two-wide" type="text" name="name"/>
  195. </div>
  196. <h2>Email and password</h2>
  197. <div>
  198. <input type="text" name="email"/>
  199. <input type="password" name="password"/>
  200. </div>
  201. <h2>Favorite animal</h2>
  202. <div>
  203. <input type="radio" name="animal" value="dog" checked/> Dog
  204. <input type="radio" name="animal" value="cat"/> Cat
  205. <input type="radio" name="animal" value="narwhal"/> Narwhal
  206. <input type="radio" name="animal" value="no"/> I don't like animals
  207. </div>
  208. <h2>Favorite meals</h2>
  209. <div>
  210. <input type="checkbox" name="meals" value="pizza" checked/> Pizza
  211. <input type="checkbox" name="meals" value="pasta" checked/> Pasta
  212. <input type="checkbox" name="meals" value="lasagne" checked/> Lasagne
  213. </div>
  214. <h2>Rating</h2>
  215. <div>
  216. <input type="range" name="rating" min="0" max="100" step="1" value="50" onchange="rating"/> <span id="rating"/><span id="rating_emoji">&nbsp;</span>
  217. </div>
  218. <h2>Subject</h2>
  219. <div>
  220. <select name="subject">
  221. <option value="none" selected>Choose your subject</option>
  222. <option value="feature">Feature request</option>
  223. <option value="bug">Bug report</option>
  224. <option value="praise">Praise</option>
  225. <option value="criticism">Criticism</option>
  226. </select>
  227. </div>
  228. <h2>Message</h2>
  229. <div>
  230. <textarea cols="25" rows="4" wrap="nowrap" name="message">😍 Hello 🌐 World! 😎</textarea>
  231. </div>
  232. <div style="margin-bottom: 15px;">
  233. <input type="submit">Submit</input>
  234. </div>
  235. </form>
  236. </panel>
  237. </tabset>
  238. </body>
  239. </rml>