databinding.rml 5.5 KB

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