[view] rework view size system

This commit is contained in:
2019-07-12 11:10:35 +03:00
parent 0a072562cb
commit ce17fff6df
39 changed files with 384 additions and 370 deletions

View File

@@ -3,7 +3,8 @@ package haxework.view;
import flash.display.DisplayObject;
import flash.display.InteractiveObject;
import flash.geom.Rectangle;
import haxework.view.core.Geometry;
import haxework.view.geometry.Geometry;
import haxework.view.geometry.SizeSet;
import haxework.view.group.IGroupView;
import haxework.view.skin.ISkin;
import haxework.view.theme.ITheme;
@@ -15,19 +16,19 @@ class View<C:DisplayObject> implements IView<C> {
@:provide var theme:ITheme;
public var geometry(default, default):Geometry;
public var skin(default, default):ISkin<Dynamic>;
public var styles(default, default):Array<String>;
public var id(default, default):String;
public var x(default, set):Float;
public var y(default, set):Float;
public var width(default, set):Float;
public var height(default, set):Float;
public var geometry(default, default):Geometry;
public var width(default, null):Float;
public var height(default, null):Float;
public var content(default, null):C;
public var skin(default, set):SkinSet;
public var skinId(null, set):String;
public var parent(default, null):Null<IGroupView>;
@@ -37,8 +38,11 @@ class View<C:DisplayObject> implements IView<C> {
public var rect(get, null):Rectangle;
private var size:SizeSet;
public function new(content:C) {
id = Type.getClassName(Type.getClass(this)) + counter++;
size = new SizeSet();
this.content = content;
x = 0;
y = 0;
@@ -47,7 +51,7 @@ class View<C:DisplayObject> implements IView<C> {
geometry = new Geometry();
visible = true;
index = -1;
skin = [];
skin = null;
}
public function toRedraw():Void {
@@ -65,19 +69,22 @@ class View<C:DisplayObject> implements IView<C> {
}
public function update():Void {
setSize(geometry.width.fixed, geometry.height.fixed, "geometry");
}
public function redraw():Void {
for (skin in this.skin) {
if (skin != null) {
skin.draw(this);
}
}
public function setContentSize(width:Float, height:Float, type:String="default"):Void {
var contentSize = geometry.size.content.get(type);
if (contentSize == null || width != contentSize.width || height != contentSize.height) {
geometry.size.content.set(type, [width, height]);
public function setSize(width:Float, height:Float, type:String = "default"):Void {
if (size.update([width, height], type)) {
var s = size.toSize();
this.width = s.width;
this.height = s.height;
toUpdateParent();
toRedraw();
}
}
@@ -99,51 +106,12 @@ class View<C:DisplayObject> implements IView<C> {
return y;
}
private function set_width(value:Float):Float {
if (width != value) {
width = value;
toRedraw();
if (geometry != null && geometry.size.ratio > -1) {
var ratioHeight = value / geometry.size.ratio;
var size = geometry.size.content["ratio.height"];
if (size == null || size.height != ratioHeight) {
this.setContentSize(-1, ratioHeight, "ratio.height");
}
}
}
return width;
}
private function set_height(value:Float):Float {
if (height != value) {
height = value;
toRedraw();
if (geometry != null && geometry.size.ratio > -1) {
var ratioWidth = value * geometry.size.ratio;
var size = geometry.size.content["ratio.width"];
if (size == null || size.width != ratioWidth) {
this.setContentSize(ratioWidth, -1, "ratio.width");
}
}
}
return height;
}
private function set_skin(value:SkinSet):SkinSet {
private function set_skin(value:ISkin<Dynamic>):ISkin<Dynamic> {
this.skin = value;
toRedraw();
return this.skin;
}
private function set_skinId(value:String):String {
//skin = theme != null ? theme.resolve(value) : [];
skinId = value;
if (theme != null) {
theme.bind(skinId, this);
}
return skinId;
}
private function set_visible(value:Bool):Bool {
if (visible != value) {
visible = value;