Domkit.hx 2.7 KB

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