diff --git a/src/bin/pathfinder/PFClient.hx b/src/bin/pathfinder/PFClient.hx new file mode 100644 index 0000000..75077cd --- /dev/null +++ b/src/bin/pathfinder/PFClient.hx @@ -0,0 +1,54 @@ +package bin.pathfinder; + +import lib.Pos3; +import lib.ui.elements.UIElement; +import lib.ui.elements.TextElement; +import lib.ui.elements.RootElement; +import kernel.ui.WindowContext; +import kernel.ps.ProcessHandle; +import kernel.ps.Process; + +class PFClient implements Process { + private var handle:ProcessHandle; + + private var ctx: WindowContext; + private var requestRender:Void -> Void; + private var root:RootElement; + + public function new() {} + + public function run(handle:ProcessHandle) { + this.handle = handle; + + var stateless = handle.createStatelessWindowContext(); + this.ctx = stateless.ctx; + this.requestRender = stateless.requestRender; + + stateless.setRenderFunc(this.render); + + this.root = new RootElement(); + this.root.setTitle("Pathfinder"); + + this.ctx.delegateEvents(this.root); + + this.requestRender(); + } + + private function render() { + var acc = kernel.gps.GPS.instance.getAccuracy(); + var pos: Pos3 = kernel.gps.GPS.instance.getPosition() ?? {x: 0, y: 0, z: 0}; + + var childre: Array = [ + new TextElement('Acc: ${acc}'), + new TextElement('Pos: X:${pos.x} Y:${pos.y} Z:${pos.z}'), + new TextElement('UPDATE', { onClick: () -> { + kernel.gps.GPS.instance.locate().handle((pos) ->{ + this.requestRender(); + }); + }}), + ]; + + this.root.setChildren(childre); + this.root.render(ctx.getSize()).renderToContext(ctx); + } +} diff --git a/src/kernel/binstore/BinStore.hx b/src/kernel/binstore/BinStore.hx index 8e6c3b5..48ee95a 100644 --- a/src/kernel/binstore/BinStore.hx +++ b/src/kernel/binstore/BinStore.hx @@ -1,5 +1,6 @@ package kernel.binstore; +import bin.pathfinder.PFClient; import bin.ID; import bin.exporter.Res; import bin.exporter.ResManager; @@ -41,7 +42,8 @@ class BinStore { {c: KSettings, name: "KSettings", aliases: ["ksettings","ks"]}, {c: ResManager, name: "ResManager", aliases: ["resmanager","resmgr"]}, {c: Res, name: "Res", aliases: ["res"]}, - {c: ID , name: "ID", aliases: ["id"]} + {c: ID , name: "ID", aliases: ["id"]}, + {c: PFClient, name: "PFClient", aliases: ["pfclient"]} ]; @:allow(kernel.Init) diff --git a/src/lib/HomeContext.hx b/src/lib/HomeContext.hx index f686360..26f5d51 100644 --- a/src/lib/HomeContext.hx +++ b/src/lib/HomeContext.hx @@ -33,7 +33,8 @@ class HomeContext { private final listedApps:Array = [ "terminal", - "log" + "log", + "pfclient" ]; public function new() {}