BIG FORMATING COMMIT
This commit is contained in:
@@ -5,7 +5,7 @@ import lib.Pos;
|
||||
import lib.Rect;
|
||||
import kernel.ui.Pixel;
|
||||
|
||||
abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pixel>>{
|
||||
abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pixel>> {
|
||||
inline public function new() {
|
||||
this = [[]];
|
||||
}
|
||||
@@ -62,8 +62,8 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pix
|
||||
return max;
|
||||
}
|
||||
|
||||
public function getBounds(): Rect {
|
||||
return new Rect({x:0,y:0},{
|
||||
public function getBounds():Rect {
|
||||
return new Rect({x: 0, y: 0}, {
|
||||
x: maxWidth() - 1,
|
||||
y: height() - 1
|
||||
});
|
||||
@@ -72,9 +72,9 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pix
|
||||
/**
|
||||
Renders the canvas directly to the context
|
||||
**/
|
||||
public function renderToContext(ctx: WindowContext){
|
||||
var lastBgColor: Color = null;
|
||||
var lastTextColor: Color = null;
|
||||
public function renderToContext(ctx:WindowContext) {
|
||||
var lastBgColor:Color = null;
|
||||
var lastTextColor:Color = null;
|
||||
|
||||
for (lineIndex => line in this) {
|
||||
if (line == null || line.length == 0) {
|
||||
@@ -126,7 +126,7 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> from Array<Array<Pix
|
||||
}
|
||||
|
||||
class CanvasKeyValueIterator {
|
||||
private final canvas:Array<Array<Pixel>> ;
|
||||
private final canvas:Array<Array<Pixel>>;
|
||||
private var index:Null<Pos> = {x: 0, y: 0};
|
||||
private var nextIndex:Null<Pos> = null;
|
||||
|
||||
@@ -134,14 +134,14 @@ class CanvasKeyValueIterator {
|
||||
private function new(canvas:Array<Array<Pixel>>) {
|
||||
this.canvas = canvas;
|
||||
|
||||
if (!isValidPos(this.index)){
|
||||
if (!isValidPos(this.index)) {
|
||||
this.index = nextValidPixel();
|
||||
}
|
||||
|
||||
this.nextIndex = nextValidPixel();
|
||||
}
|
||||
|
||||
private function isValidPos(pos: Pos): Bool {
|
||||
private function isValidPos(pos:Pos):Bool {
|
||||
if (this.canvas[pos.y] == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -157,19 +157,19 @@ class CanvasKeyValueIterator {
|
||||
return this.index != null;
|
||||
}
|
||||
|
||||
private function nextValidPixel(): Null<Pos> {
|
||||
private function nextValidPixel():Null<Pos> {
|
||||
if (this.index == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var startX = this.index.x + 1;
|
||||
|
||||
for (y in this.index.y...this.canvas.length){
|
||||
for (y in this.index.y...this.canvas.length) {
|
||||
if (this.canvas[y] == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (x in startX...(this.canvas[y].length)){
|
||||
for (x in startX...(this.canvas[y].length)) {
|
||||
if (this.canvas[y][x] == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -191,7 +191,6 @@ class CanvasKeyValueIterator {
|
||||
this.index = this.nextIndex;
|
||||
this.nextIndex = nextValidPixel();
|
||||
|
||||
|
||||
return rtn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package lib.ui;
|
||||
import lib.Color;
|
||||
|
||||
typedef Style = {
|
||||
public var ?fgColor: Color;
|
||||
public var ?bgColor: Color;
|
||||
public var ?fgColor:Color;
|
||||
public var ?bgColor:Color;
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ import kernel.ui.WindowContext;
|
||||
using tink.CoreApi;
|
||||
|
||||
abstract class UIApp {
|
||||
public abstract function invoke(context: WindowContext): Future<Bool>;
|
||||
public abstract function invoke(context:WindowContext):Future<Bool>;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class RootElement implements UIElement {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public function render(bounds: Pos):Canvas {
|
||||
public function render(bounds:Pos):Canvas {
|
||||
var canvas = new Canvas();
|
||||
var offset = new Pos({x: 0, y: 0});
|
||||
|
||||
@@ -48,11 +48,11 @@ class RootElement implements UIElement {
|
||||
return canvas;
|
||||
}
|
||||
|
||||
public function setTitle(title: String) {
|
||||
public function setTitle(title:String) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
private inline function hasTitle(): Bool {
|
||||
return title != "";
|
||||
private inline function hasTitle():Bool {
|
||||
return title != "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ class TextElement implements UIElement {
|
||||
private final uiEvents:UIEvents;
|
||||
private final style:Style;
|
||||
|
||||
public function new(text:String, ?props: {?style:Style, ?uiEvents:UIEvents}) {
|
||||
public function new(text:String, ?props:{?style:Style, ?uiEvents:UIEvents}) {
|
||||
this.text = text;
|
||||
this.uiEvents = props?.uiEvents;
|
||||
this.style = props?.style ?? {fgColor: White, bgColor: Black};
|
||||
@@ -26,7 +26,7 @@ class TextElement implements UIElement {
|
||||
return uiEvents;
|
||||
}
|
||||
|
||||
public function render(bounds: Pos):Canvas {
|
||||
public function render(bounds:Pos):Canvas {
|
||||
var canvas = new Canvas();
|
||||
for (i in 0...this.text.length) {
|
||||
var c = this.text.charAt(i);
|
||||
|
||||
@@ -3,5 +3,5 @@ package lib.ui.elements;
|
||||
import lib.ui.rendere.UIEventDelegate;
|
||||
|
||||
interface UIElement extends UIEventDelegate {
|
||||
public function render(bounds: Pos):Canvas;
|
||||
public function render(bounds:Pos):Canvas;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package lib.ui.rendere;
|
||||
|
||||
class List implements UIEventDelegate{
|
||||
private final onElementClick: Null<Int->Void>;
|
||||
class List implements UIEventDelegate {
|
||||
private final onElementClick:Null<Int->Void>;
|
||||
|
||||
public function new(?onElementClick: Int->Void) {
|
||||
public function new(?onElementClick:Int->Void) {
|
||||
this.onElementClick = onElementClick;
|
||||
}
|
||||
|
||||
public function render(list:Array<String>): Canvas {
|
||||
public function render(list:Array<String>):Canvas {
|
||||
var canvas = new Canvas();
|
||||
for (line in 0...list.length) {
|
||||
for (char in 0...list[line].length) {
|
||||
@@ -22,14 +22,14 @@ class List implements UIEventDelegate{
|
||||
return canvas;
|
||||
}
|
||||
|
||||
public function getEventHandlers(): UIEvents{
|
||||
public function getEventHandlers():UIEvents {
|
||||
return {
|
||||
onClick: handleClick
|
||||
};
|
||||
}
|
||||
|
||||
private function handleClick(e: {button:kernel.ButtonType, pos:Pos}): Void{
|
||||
if (this.onElementClick == null){
|
||||
private function handleClick(e:{button:kernel.ButtonType, pos:Pos}):Void {
|
||||
if (this.onElementClick == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package lib.ui.rendere;
|
||||
|
||||
interface UIEventDelegate {
|
||||
public function getEventHandlers(): UIEvents;
|
||||
public function getEventHandlers():UIEvents;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user