implemented UIEvents delegate in WindowContext
This commit is contained in:
parent
a1ce5957d1
commit
8f7739c26a
@ -1,5 +1,6 @@
|
|||||||
package kernel.ui;
|
package kernel.ui;
|
||||||
|
|
||||||
|
import lib.ui.rendere.UIEventDelegate;
|
||||||
import lib.Pos;
|
import lib.Pos;
|
||||||
import lib.Color;
|
import lib.Color;
|
||||||
import kernel.ButtonType;
|
import kernel.ButtonType;
|
||||||
@ -14,6 +15,8 @@ using tink.CoreApi;
|
|||||||
class WindowContext implements TermWriteable {
|
class WindowContext implements TermWriteable {
|
||||||
private final writer:VirtualTermWriter;
|
private final writer:VirtualTermWriter;
|
||||||
|
|
||||||
|
@:allow(kernel.ui.WindowManager) private var eventDelegate: Null<UIEventDelegate>;
|
||||||
|
|
||||||
public var onClick(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
public var onClick(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
||||||
public var onKey(default, null):Signal<{keyCode:Int, isHeld:Bool}>;
|
public var onKey(default, null):Signal<{keyCode:Int, isHeld:Bool}>;
|
||||||
public var onKeyUp(default, null):Signal<Int>;
|
public var onKeyUp(default, null):Signal<Int>;
|
||||||
@ -137,4 +140,12 @@ class WindowContext implements TermWriteable {
|
|||||||
public function reset() {
|
public function reset() {
|
||||||
writer.reset();
|
writer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Delegate events to an UIEventDelegate.
|
||||||
|
Set to null to stop delegating events.
|
||||||
|
**/
|
||||||
|
public function delegateEvents(delegate: Null<UIEventDelegate>){
|
||||||
|
this.eventDelegate = delegate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,43 +20,78 @@ class WindowManager {
|
|||||||
private function new() {
|
private function new() {
|
||||||
KernelEvents.instance.onKey.handle(params -> {
|
KernelEvents.instance.onKey.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.onKeyTrigger.trigger(params);
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onKey != null ? foo.onKey.invoke(params) : null;
|
||||||
|
}else{
|
||||||
|
currentMainContext.onKeyTrigger.trigger(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onKeyUp.handle(keyCode -> {
|
KernelEvents.instance.onKeyUp.handle(keyCode -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.onKeyUpTrigger.trigger(keyCode);
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onKeyUp != null ? foo.onKeyUp.invoke(keyCode) : null;
|
||||||
|
}else{
|
||||||
|
currentMainContext.onKeyUpTrigger.trigger(keyCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMouseClick.handle(params -> {
|
KernelEvents.instance.onMouseClick.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.onClickTrigger.trigger(params);
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onClick != null ? foo.onClick.invoke(params) : null;
|
||||||
|
}else{
|
||||||
|
currentMainContext.onClickTrigger.trigger(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMouseDrag.handle(params -> {
|
KernelEvents.instance.onMouseDrag.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.onMouseDragTrigger.trigger(params);
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onMouseDrag != null ? foo.onMouseDrag.invoke(params) : null;
|
||||||
|
}else{
|
||||||
|
currentMainContext.onMouseDragTrigger.trigger(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMouseScroll.handle(params -> {
|
KernelEvents.instance.onMouseScroll.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.onMouseScrollTrigger.trigger(params);
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onMouseScroll != null ? foo.onMouseScroll.invoke(params) : null;
|
||||||
|
}else{
|
||||||
|
currentMainContext.onMouseScrollTrigger.trigger(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMouseUp.handle(params -> {
|
KernelEvents.instance.onMouseUp.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.onMouseUpTrigger.trigger(params);
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onMouseUp != null ? foo.onMouseUp.invoke(params) : null;
|
||||||
|
}else{
|
||||||
|
currentMainContext.onMouseUpTrigger.trigger(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onPaste.handle(text -> {
|
KernelEvents.instance.onPaste.handle(text -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.onPasteTrigger.trigger(text);
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onPaste != null ? foo.onPaste.invoke(text) : null;
|
||||||
|
}else{
|
||||||
|
currentMainContext.onPasteTrigger.trigger(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -66,7 +101,12 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.instance.onChar.handle(char -> {
|
KernelEvents.instance.onChar.handle(char -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
currentMainContext.onCharTrigger.trigger(char);
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onChar != null ? foo.onChar.invoke(char) : null;
|
||||||
|
}else{
|
||||||
|
currentMainContext.onCharTrigger.trigger(char);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,5 @@ typedef UIEvents = {
|
|||||||
public var ?onMouseScroll:Callback<{dir:Int, pos:Pos}>;
|
public var ?onMouseScroll:Callback<{dir:Int, pos:Pos}>;
|
||||||
public var ?onMouseUp:Callback<{button:ButtonType, pos:Pos}>;
|
public var ?onMouseUp:Callback<{button:ButtonType, pos:Pos}>;
|
||||||
public var ?onPaste:Callback<String>;
|
public var ?onPaste:Callback<String>;
|
||||||
|
public var ?onChar:Callback<String>;
|
||||||
}
|
}
|
||||||
|
5
src/lib/ui/rendere/UIEventDelegate.hx
Normal file
5
src/lib/ui/rendere/UIEventDelegate.hx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package lib.ui.rendere;
|
||||||
|
|
||||||
|
interface UIEventDelegate {
|
||||||
|
public function getEventHandlers(): UIEvents;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user