use Pos instead of Vec2<Int>

This commit is contained in:
2022-03-08 13:33:40 +01:00
parent edc3195192
commit de35f34173
13 changed files with 59 additions and 45 deletions

View File

@@ -1,5 +1,6 @@
package lib.ui;
import util.Pos;
import util.Rect;
import util.Vec.Vec2;
import kernel.ui.Pixel;
@@ -9,7 +10,7 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
this = [[]];
}
public inline function set(i:Vec2<Int>, pixel:Pixel) {
public inline function set(i:Pos, pixel:Pixel) {
if (this[i.y] == null) {
this[i.y] = [];
}
@@ -17,15 +18,15 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
this[i.y][i.x] = pixel;
}
public inline function get(i:Vec2<Int>):Pixel {
public inline function get(i:Pos):Pixel {
return this[i.y][i.x];
}
public function keyValueIterator():KeyValueIterator<Vec2<Int>, Pixel> {
public function keyValueIterator():KeyValueIterator<Pos, Pixel> {
return new CanvasKeyValueIterator(this);
}
public function combine(other:Canvas, offset:Vec2<Int>) {
public function combine(other:Canvas, offset:Pos) {
for (key => value in other) {
if (value == null) {
continue;
@@ -67,7 +68,7 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
class CanvasKeyValueIterator {
private final canvas:Array<Array<Pixel>>;
private var index:Vec2<Int> = {x: 0, y: 0};
private var index:Pos = {x: 0, y: 0};
@:allow(lib.ui.Canvas)
private function new(canvas:Array<Array<Pixel>>) {
@@ -78,8 +79,8 @@ class CanvasKeyValueIterator {
return index.y < canvas.length && index.x <= canvas[index.y].length;
}
public function next():{key:Vec2<Int>, value:Pixel} {
var oldIndex:Vec2<Int> = this.index;
public function next():{key:Pos, value:Pixel} {
var oldIndex:Pos = this.index;
if (index.x >= canvas[index.y].length) {
// Goto next line

View File

@@ -1,15 +1,16 @@
package lib.ui;
import util.Pos;
import util.Vec.Vec2;
import kernel.ButtonType;
using tink.CoreApi;
typedef UIEvents = {
public var ?onClick:Callback<{button:ButtonType, pos:Vec2<Int>}>;
public var ?onClick:Callback<{button:ButtonType, pos:Pos}>;
public var ?onKey:Callback<{keyCode:Int, isHeld:Bool}>;
public var ?onKeyUp:Callback<Int>;
public var ?onMouseDrag:Callback<{button:ButtonType, pos:Vec2<Int>}>;
public var ?onMouseScroll:Callback<{dir:Int, pos:Vec2<Int>}>;
public var ?onMouseUp:Callback<{button:ButtonType, pos:Vec2<Int>}>;
public var ?onMouseDrag:Callback<{button:ButtonType, pos:Pos}>;
public var ?onMouseScroll:Callback<{dir:Int, pos:Pos}>;
public var ?onMouseUp:Callback<{button:ButtonType, pos:Pos}>;
public var ?onPaste:Callback<String>;
}

View File

@@ -44,7 +44,7 @@ class ListElement extends UIElement {
public function render(bounds:Vec2<Int>,offset: Pos):Canvas {
var canvas: Canvas = new Canvas();
var writePoint:Vec2<Int> = {x: 0, y: 0};
var writePoint:Pos = {x: 0, y: 0};
this.offset = offset;
for(element in this.content.get()){

View File

@@ -1,5 +1,6 @@
package lib.ui.reactive;
import util.Pos;
import util.Rect;
import util.Color;
import util.Vec.Vec2;
@@ -145,7 +146,7 @@ class ReactiveUI {
var canvas:Canvas = new Canvas();
var elementMap: Map<Rect,UIElement> = new Map();
var writePoint:Vec2<Int> = {x: 0, y: 0};
var writePoint:Pos = {x: 0, y: 0};
for (child in children) {
if (bounds.y - writePoint.y <= 0) {