[gui] update
This commit is contained in:
@@ -32,7 +32,7 @@ import haxework.resources.Resources;
|
||||
@:view var switcher:IFrameSwitcher;
|
||||
@:view var tabs:IGroupView;
|
||||
|
||||
private function onFrameSwicth(frame:IView<Dynamic>):Void {
|
||||
private function onFrameSwitch(frame:IView<Dynamic>):Void {
|
||||
for (view in tabs.views) cast(view, ToggleButtonView).on = view.id == frame.id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ views:
|
||||
layout.hAlign: left
|
||||
geometry.size.width: 100%
|
||||
geometry.padding.left: 5
|
||||
geometry.margin.bottom: -3
|
||||
views:
|
||||
- id: list_form
|
||||
$type: haxework.gui.ToggleButtonView
|
||||
@@ -33,7 +34,7 @@ views:
|
||||
- id: switcher
|
||||
$type: haxework.gui.frame.FrameSwitcher
|
||||
skin: $r:skin:border
|
||||
+onSwitch: $this:onFrameSwicth
|
||||
+onSwitch: $this:onFrameSwitch
|
||||
geometry.size.stretch: true
|
||||
geometry.padding: 5
|
||||
views:
|
||||
|
||||
@@ -30,6 +30,8 @@ interface IView<C:DisplayObject> {
|
||||
|
||||
public function toUpdate():Void;
|
||||
|
||||
public function toUpdateParent():Void;
|
||||
|
||||
public function toRedraw():Void;
|
||||
|
||||
public function remove():Void;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user