[gui] update

This commit is contained in:
2019-03-01 16:29:53 +03:00
parent 3e06e5df26
commit cad4faa580
10 changed files with 45 additions and 22 deletions

View File

@@ -30,6 +30,8 @@ interface IView<C:DisplayObject> {
public function toUpdate():Void;
public function toUpdateParent():Void;
public function toRedraw():Void;
public function remove():Void;

View File

@@ -1,16 +1,14 @@
package haxework.gui;
import haxework.signal.Signal;
import flash.text.TextFormatAlign;
import flash.events.Event;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.text.TextField;
import haxework.core.IDisposable;
import haxework.core.Const;
import flash.events.KeyboardEvent;
import flash.events.TextEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import haxework.core.IDisposable;
import haxework.signal.Signal;
class InputView extends TextView implements IDisposable {

View File

@@ -144,8 +144,7 @@ class TextView extends SpriteView implements ITextView {
private function updateTextSize():Void {
var size = TextUtil.getSize(textField);
geometry.size.content.width = size.x;
geometry.size.content.height = size.y;
setContentSize(size.x, size.y);
}
override public function update():Void {

View File

@@ -51,9 +51,10 @@ class View<C:DisplayObject> implements IView<C> {
updater.toUpdate(this);
}
private function toUpdateParent():Void {
if (parent != null)
public function toUpdateParent():Void {
if (parent != null) {
updater.toUpdate(parent);
}
}
public function update():Void {}
@@ -62,15 +63,26 @@ class View<C:DisplayObject> implements IView<C> {
for (skin in this.skin) {
if (Std.is(skin, ISizeSkin)) {
var sizeSkin:ISizeSkin = cast skin;
if (sizeSkin.width != geometry.size.content.width || sizeSkin.height != geometry.size.content.width) {
geometry.size.content = [sizeSkin.width, sizeSkin.height];
toUpdateParent();
}
setSize(sizeSkin.width, sizeSkin.height);
}
skin.draw(this);
}
}
private function setSize(width:Float, height:Float):Void {
if (width != geometry.size.fixed.width || height != geometry.size.fixed.height) {
geometry.size.fixed = [width, height];
toUpdateParent();
}
}
private function setContentSize(width:Float, height:Float):Void {
if (width != geometry.size.content.width || height != geometry.size.content.height) {
geometry.size.content = [width, height];
toUpdateParent();
}
}
public function remove():Void {
if (parent != null) parent.removeView(this);
}

View File

@@ -36,10 +36,19 @@ class ViewUpdater {
}
public function update():Void {
var repeat = 0;
while (updateViews.length > 0) {
var v = null;
v = updateViews.shift();
var count = updateViews.length;
v.update();
if (updateViews.length > count) {
repeat++;
if (repeat > 100) {
L.e("ViewUpdater", 'repeat limit: ${updateViews}');
return;
}
}
}
}

View File

@@ -163,8 +163,10 @@ class ListView<D> extends GroupView {
public function render():Void {
if (data != null && factory != null) {
filteredData = filter == null ? data : data.filter(filter);
scroll.ratio = Math.min(1.0, (size - sizeDiff) / filteredData.length);
scroll.position = ((offset + offsetDiff) / filteredData.length);
if (scroll != null) {
scroll.ratio = Math.min(1.0, (size - sizeDiff) / filteredData.length);
scroll.position = ((offset + offsetDiff) / filteredData.length);
}
for (i in 0...size) {
var item:IListItemView<D> = items[i];
var index = offset + i;

View File

@@ -14,7 +14,7 @@ class BorderSkin implements ISkin<SpriteView> {
public function draw(view:SpriteView):Void {
view.content.graphics.lineStyle(tickness, color, alpha, true);
view.content.graphics.drawRect(0, 0, view.width - tickness, view.height - tickness);
view.content.graphics.drawRect(tickness, tickness, view.width - tickness * 2, view.height - tickness * 2);
view.content.graphics.lineStyle();
}
}

View File

@@ -12,7 +12,7 @@ class SizeSkin implements ISkin<IView<Dynamic>> {
public function draw(view:IView<Dynamic>):Void {
if (view.geometry.size.fixed.width != width || view.geometry.size.fixed.height != height) {
view.geometry.size.fixed = [width, height];
view.toUpdate();
view.toUpdateParent();
}
}
}