Domkit.hx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. @:uiComp("view")
  2. // Naming scheme of component classes can be customized with domkit.Macros.registerComponentsPath();
  3. class ViewComp extends h2d.Flow implements h2d.domkit.Object {
  4. static var SRC =
  5. <view class="mybox" min-width="200" content-halign={align}>
  6. Hello World
  7. ${
  8. for( i in icons )
  9. <bitmap src={i} id="icons[]"/>
  10. }
  11. </view>;
  12. public function new(align:h2d.Flow.FlowAlign,icons:Array<h2d.Tile>,?parent) {
  13. super(parent);
  14. initComponent();
  15. }
  16. }
  17. @:uiComp("button")
  18. class ButtonComp extends h2d.Flow implements h2d.domkit.Object {
  19. static var SRC = <button>
  20. <text public id="labelTxt" />
  21. </button>
  22. public var label(get, set): String;
  23. function get_label() return labelTxt.text;
  24. function set_label(s) {
  25. labelTxt.text = s;
  26. return s;
  27. }
  28. public function new( ?parent ) {
  29. super(parent);
  30. initComponent();
  31. enableInteractive = true;
  32. interactive.onClick = function(_) onClick();
  33. interactive.onOver = function(_) {
  34. dom.hover = true;
  35. };
  36. interactive.onPush = function(_) {
  37. dom.active = true;
  38. };
  39. interactive.onRelease = function(_) {
  40. dom.active = false;
  41. };
  42. interactive.onOut = function(_) {
  43. dom.hover = false;
  44. };
  45. }
  46. public dynamic function onClick() {
  47. }
  48. }
  49. @:uiComp("container")
  50. class ContainerComp extends h2d.Flow implements h2d.domkit.Object {
  51. static var SRC = <container>
  52. <view(align,[]) id="view"/>
  53. <button public id="btn"/>
  54. <button public id="btn1"/>
  55. <button public id="btn2"/>
  56. </container>;
  57. public function new(align:h2d.Flow.FlowAlign, ?parent) {
  58. super(parent);
  59. initComponent();
  60. }
  61. }
  62. //PARAM=-lib domkit
  63. class Domkit extends hxd.App {
  64. var center : h2d.Flow;
  65. var style = null;
  66. override function init() {
  67. center = new h2d.Flow(s2d);
  68. center.horizontalAlign = center.verticalAlign = Middle;
  69. onResize();
  70. var root = new ContainerComp(Right, center);
  71. // Override
  72. root.btn.label = "Button";
  73. root.btn1.label = "Highlight ON";
  74. root.btn2.labelTxt.text = "Highlight OFF";
  75. root.btn1.onClick = function() {
  76. root.btn.dom.addClass("highlight");
  77. }
  78. root.btn2.onClick = function() {
  79. root.btn.dom.removeClass("highlight");
  80. }
  81. style = new h2d.domkit.Style();
  82. style.load(hxd.Res.style);
  83. style.addObject(root);
  84. }
  85. override function onResize() {
  86. center.minWidth = center.maxWidth = s2d.width;
  87. center.minHeight = center.maxHeight = s2d.height;
  88. }
  89. override function update(dt:Float) {
  90. style.sync();
  91. }
  92. static function main() {
  93. #if hl
  94. hxd.res.Resource.LIVE_UPDATE = true;
  95. hxd.Res.initLocal();
  96. #else
  97. hxd.Res.initEmbed();
  98. #end
  99. new Domkit();
  100. }
  101. }