bright-gpu-74537
06/20/2020, 10:56 AMbright-gpu-74537
06/20/2020, 10:56 AMbright-gpu-74537
06/20/2020, 10:57 AMfast-rain-20339
06/20/2020, 10:57 AMbright-gpu-74537
06/20/2020, 10:57 AMbright-gpu-74537
06/20/2020, 11:20 AMhaxe
class MyComponent extends Box {
public var lastSelection:String = null;
public function new() {
super();
registerEvent(MouseEvent.CLICK, onViewClick);
}
public override function renderTo(g:Graphics) {
if (this.isReady == false || this.hidden == true) {
return;
}
g.color = Color.Blue;
g.fillRect(screenX, screenY, this.width / 2, this.height / 2);
g.color = Color.White;
g.color = Color.Yellow;
g.fillRect(screenX + this.width / 2, screenY, this.width / 2, this.height / 2);
g.color = Color.White;
g.color = Color.Red;
g.fillRect(screenX, screenY + this.height / 2, this.width / 2, this.height / 2);
g.color = Color.White;
g.color = Color.Green;
g.fillRect(screenX + this.width / 2, screenY + this.height / 2, this.width / 2, this.height / 2);
g.color = Color.White;
}
private function onViewClick(event:MouseEvent) {
var x = event.localX;
var y = event.localY;
var cx = this.width;
var cy = this.height;
if (x < cx / 2 && y < cy / 2) {
lastSelection = "blue";
dispatch(new UIEvent(UIEvent.CHANGE));
} else if (x > cx / 2 && y < cy / 2) {
lastSelection = "yellow";
dispatch(new UIEvent(UIEvent.CHANGE));
} else if (x < cx / 2 && y > cy / 2) {
lastSelection = "red";
dispatch(new UIEvent(UIEvent.CHANGE));
} else if (x > cx / 2 && y > cy / 2) {
lastSelection = "green";
dispatch(new UIEvent(UIEvent.CHANGE));
}
}
}
bright-gpu-74537
06/20/2020, 11:20 AMxml
<vbox style="padding: 5px;">
<button text="Click Me!" onclick="c.width += 20; c.height += 20;" />
<my-component id="c" width="100" height="100" onchange="sel.text = this.lastSelection" />
<label id="sel" text="Select something!" />
</vbox>
bright-gpu-74537
06/20/2020, 11:21 AMfast-rain-20339
06/20/2020, 11:21 AMfast-rain-20339
06/20/2020, 11:22 AMbright-gpu-74537
06/20/2020, 11:22 AMfast-rain-20339
06/20/2020, 11:23 AMdispatch(new UIEvent
before, that looks clean. Reminds me of using web frameworks like react or vueclever-oil-61353
06/20/2020, 12:05 PMfast-rain-20339
06/20/2020, 12:06 PMclever-oil-61353
06/20/2020, 12:08 PMfast-rain-20339
06/20/2020, 12:08 PMclever-oil-61353
06/20/2020, 12:09 PMbright-gpu-74537
06/20/2020, 12:10 PMfast-rain-20339
06/20/2020, 12:10 PMclever-oil-61353
06/20/2020, 12:10 PMfast-rain-20339
06/20/2020, 12:10 PMclever-oil-61353
06/20/2020, 12:10 PMbright-gpu-74537
06/20/2020, 12:11 PMbright-gpu-74537
06/20/2020, 12:11 PMclever-oil-61353
06/20/2020, 12:11 PMclever-oil-61353
06/20/2020, 12:11 PMbright-gpu-74537
06/20/2020, 12:11 PMbright-gpu-74537
06/20/2020, 12:11 PMclever-oil-61353
06/20/2020, 12:11 PMclever-oil-61353
06/20/2020, 12:14 PM