From cad4faa580cfd307741163a3f003fc5b4914fd59 Mon Sep 17 00:00:00 2001 From: shmyga Date: Fri, 1 Mar 2019 16:29:53 +0300 Subject: [PATCH] [gui] update --- demo/src/demo/Demo.hx | 2 +- demo/src/demo/Demo.yaml | 3 ++- src/main/haxework/gui/IView.hx | 2 ++ src/main/haxework/gui/InputView.hx | 14 ++++++-------- src/main/haxework/gui/TextView.hx | 3 +-- src/main/haxework/gui/View.hx | 24 ++++++++++++++++++------ src/main/haxework/gui/ViewUpdater.hx | 9 +++++++++ src/main/haxework/gui/list/ListView.hx | 6 ++++-- src/main/haxework/gui/skin/BorderSkin.hx | 2 +- src/main/haxework/gui/skin/SizeSkin.hx | 2 +- 10 files changed, 45 insertions(+), 22 deletions(-) diff --git a/demo/src/demo/Demo.hx b/demo/src/demo/Demo.hx index 1d05836..1d8c1cf 100644 --- a/demo/src/demo/Demo.hx +++ b/demo/src/demo/Demo.hx @@ -32,7 +32,7 @@ import haxework.resources.Resources; @:view var switcher:IFrameSwitcher; @:view var tabs:IGroupView; - private function onFrameSwicth(frame:IView):Void { + private function onFrameSwitch(frame:IView):Void { for (view in tabs.views) cast(view, ToggleButtonView).on = view.id == frame.id; } } diff --git a/demo/src/demo/Demo.yaml b/demo/src/demo/Demo.yaml index 7821278..3528a0a 100644 --- a/demo/src/demo/Demo.yaml +++ b/demo/src/demo/Demo.yaml @@ -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: diff --git a/src/main/haxework/gui/IView.hx b/src/main/haxework/gui/IView.hx index 21b3e5e..712f9b8 100755 --- a/src/main/haxework/gui/IView.hx +++ b/src/main/haxework/gui/IView.hx @@ -30,6 +30,8 @@ interface IView { public function toUpdate():Void; + public function toUpdateParent():Void; + public function toRedraw():Void; public function remove():Void; diff --git a/src/main/haxework/gui/InputView.hx b/src/main/haxework/gui/InputView.hx index 5d33ade..249be6f 100755 --- a/src/main/haxework/gui/InputView.hx +++ b/src/main/haxework/gui/InputView.hx @@ -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 { diff --git a/src/main/haxework/gui/TextView.hx b/src/main/haxework/gui/TextView.hx index 8303a86..a8cfa6c 100755 --- a/src/main/haxework/gui/TextView.hx +++ b/src/main/haxework/gui/TextView.hx @@ -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 { diff --git a/src/main/haxework/gui/View.hx b/src/main/haxework/gui/View.hx index e2e8ece..375537c 100755 --- a/src/main/haxework/gui/View.hx +++ b/src/main/haxework/gui/View.hx @@ -51,9 +51,10 @@ class View implements IView { 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 implements IView { 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); } diff --git a/src/main/haxework/gui/ViewUpdater.hx b/src/main/haxework/gui/ViewUpdater.hx index 4a8d44c..ddbf981 100644 --- a/src/main/haxework/gui/ViewUpdater.hx +++ b/src/main/haxework/gui/ViewUpdater.hx @@ -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; + } + } } } diff --git a/src/main/haxework/gui/list/ListView.hx b/src/main/haxework/gui/list/ListView.hx index 09c3590..983990a 100755 --- a/src/main/haxework/gui/list/ListView.hx +++ b/src/main/haxework/gui/list/ListView.hx @@ -163,8 +163,10 @@ class ListView 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 = items[i]; var index = offset + i; diff --git a/src/main/haxework/gui/skin/BorderSkin.hx b/src/main/haxework/gui/skin/BorderSkin.hx index 45c8d2c..375c903 100644 --- a/src/main/haxework/gui/skin/BorderSkin.hx +++ b/src/main/haxework/gui/skin/BorderSkin.hx @@ -14,7 +14,7 @@ class BorderSkin implements ISkin { 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(); } } diff --git a/src/main/haxework/gui/skin/SizeSkin.hx b/src/main/haxework/gui/skin/SizeSkin.hx index e2be774..a383773 100644 --- a/src/main/haxework/gui/skin/SizeSkin.hx +++ b/src/main/haxework/gui/skin/SizeSkin.hx @@ -12,7 +12,7 @@ class SizeSkin implements ISkin> { public function draw(view:IView):Void { if (view.geometry.size.fixed.width != width || view.geometry.size.fixed.height != height) { view.geometry.size.fixed = [width, height]; - view.toUpdate(); + view.toUpdateParent(); } } }