cc-haxe/src/lib/ui/elements/EventMap.hx

33 lines
870 B
Haxe

package lib.ui.elements;
import lib.ui.rendere.IUIEventDelegate;
/**
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:IUIEventDelegate}>) {
inline public function new(?i:Array<{bound:Rect, delegate:IUIEventDelegate}>) {
if (i == null) {
this = new Array<{bound:Rect, delegate:IUIEventDelegate}>();
} else {
this = i;
}
}
public function findResponseableDelegate(pos:Pos):IUIEventDelegate {
for (i in 0...this.length) {
var newi = (this.length - 1) - i;
var element = this[newi];
if (element.bound.isInside(pos)) {
return element.delegate;
}
}
return null;
}
public inline function addElement(element:IUIEventDelegate, bound:Rect) {
this.push({bound: bound, delegate: element});
}
}