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,44 +20,79 @@ class WindowManager {
|
|||||||
private function new() {
|
private function new() {
|
||||||
KernelEvents.instance.onKey.handle(params -> {
|
KernelEvents.instance.onKey.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onKey != null ? foo.onKey.invoke(params) : null;
|
||||||
|
}else{
|
||||||
currentMainContext.onKeyTrigger.trigger(params);
|
currentMainContext.onKeyTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onKeyUp.handle(keyCode -> {
|
KernelEvents.instance.onKeyUp.handle(keyCode -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onKeyUp != null ? foo.onKeyUp.invoke(keyCode) : null;
|
||||||
|
}else{
|
||||||
currentMainContext.onKeyUpTrigger.trigger(keyCode);
|
currentMainContext.onKeyUpTrigger.trigger(keyCode);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMouseClick.handle(params -> {
|
KernelEvents.instance.onMouseClick.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onClick != null ? foo.onClick.invoke(params) : null;
|
||||||
|
}else{
|
||||||
currentMainContext.onClickTrigger.trigger(params);
|
currentMainContext.onClickTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMouseDrag.handle(params -> {
|
KernelEvents.instance.onMouseDrag.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onMouseDrag != null ? foo.onMouseDrag.invoke(params) : null;
|
||||||
|
}else{
|
||||||
currentMainContext.onMouseDragTrigger.trigger(params);
|
currentMainContext.onMouseDragTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMouseScroll.handle(params -> {
|
KernelEvents.instance.onMouseScroll.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onMouseScroll != null ? foo.onMouseScroll.invoke(params) : null;
|
||||||
|
}else{
|
||||||
currentMainContext.onMouseScrollTrigger.trigger(params);
|
currentMainContext.onMouseScrollTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMouseUp.handle(params -> {
|
KernelEvents.instance.onMouseUp.handle(params -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onMouseUp != null ? foo.onMouseUp.invoke(params) : null;
|
||||||
|
}else{
|
||||||
currentMainContext.onMouseUpTrigger.trigger(params);
|
currentMainContext.onMouseUpTrigger.trigger(params);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onPaste.handle(text -> {
|
KernelEvents.instance.onPaste.handle(text -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onPaste != null ? foo.onPaste.invoke(text) : null;
|
||||||
|
}else{
|
||||||
currentMainContext.onPasteTrigger.trigger(text);
|
currentMainContext.onPasteTrigger.trigger(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.instance.onMonitorTouch.handle(params -> {
|
KernelEvents.instance.onMonitorTouch.handle(params -> {
|
||||||
@ -66,8 +101,13 @@ class WindowManager {
|
|||||||
|
|
||||||
KernelEvents.instance.onChar.handle(char -> {
|
KernelEvents.instance.onChar.handle(char -> {
|
||||||
if (currentMainContext != null) {
|
if (currentMainContext != null) {
|
||||||
|
if (currentMainContext.eventDelegate != null){
|
||||||
|
var foo = currentMainContext.eventDelegate.getEventHandlers();
|
||||||
|
foo.onChar != null ? foo.onChar.invoke(char) : null;
|
||||||
|
}else{
|
||||||
currentMainContext.onCharTrigger.trigger(char);
|
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