added ui events to LayerdRootElement
This commit is contained in:
parent
3e09bcfad2
commit
92deb7177f
@ -2,25 +2,31 @@ package lib.ui.elements;
|
|||||||
|
|
||||||
import lib.ui.rendere.UIEventDelegate;
|
import lib.ui.rendere.UIEventDelegate;
|
||||||
|
|
||||||
abstract EventMap(List<{bound:Rect, delegate:UIEventDelegate}>) {
|
/**
|
||||||
inline public function new(?i:List<{bound:Rect, delegate:UIEventDelegate}>) {
|
Find the responsable UIElement to handle the event based on position. Element can be layerd.
|
||||||
|
Elements added first are lower in the layer.
|
||||||
|
**/
|
||||||
|
abstract EventMap(Array<{bound:Rect, delegate:UIEventDelegate}>) {
|
||||||
|
inline public function new(?i:Array<{bound:Rect, delegate:UIEventDelegate}>) {
|
||||||
if (i == null) {
|
if (i == null) {
|
||||||
this = new List<{bound:Rect, delegate:UIEventDelegate}>();
|
this = new Array<{bound:Rect, delegate:UIEventDelegate}>();
|
||||||
} else {
|
} else {
|
||||||
this = i;
|
this = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findResponseableDelegate(pos:Pos):UIEventDelegate {
|
public function findResponseableDelegate(pos:Pos):UIEventDelegate {
|
||||||
for (i in this) {
|
for (i in 0...this.length) {
|
||||||
if (i.bound.isInside(pos)) {
|
var newi = (this.length - 1) - i;
|
||||||
return i.delegate;
|
var element = this[newi];
|
||||||
|
if (element.bound.isInside(pos)) {
|
||||||
|
return element.delegate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addElement(element:UIEventDelegate, bound:Rect) {
|
public inline function addElement(element:UIEventDelegate, bound:Rect) {
|
||||||
this.add({bound: bound, delegate: element});
|
this.push({bound: bound, delegate: element});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,16 @@ class LayerdRootElement implements UIElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function render(bounds:Pos):Canvas {
|
public function render(bounds:Pos):Canvas {
|
||||||
// TODO: add event handle
|
this.eventManager.clearMap();
|
||||||
|
|
||||||
var stack = new CanvasStack();
|
var stack = new CanvasStack();
|
||||||
|
|
||||||
for (child in this.children) {
|
for (child in this.children) {
|
||||||
stack.addLayer(child.element.render(bounds), child.offset);
|
var canvas = child.element.render(bounds);
|
||||||
|
var bound = canvas.getBounds();
|
||||||
|
bound.offset(child.offset);
|
||||||
|
eventManager.addMapElement(child.element, bound);
|
||||||
|
stack.addLayer(canvas, child.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack.compress();
|
return stack.compress();
|
||||||
|
Loading…
Reference in New Issue
Block a user