[view] fix view size
This commit is contained in:
@@ -3,7 +3,7 @@ package haxework.view;
|
|||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import flash.geom.Rectangle;
|
import flash.geom.Rectangle;
|
||||||
import haxework.view.geometry.Geometry;
|
import haxework.view.geometry.Geometry;
|
||||||
import haxework.view.geometry.Size;
|
import haxework.view.geometry.SizeSet;
|
||||||
import haxework.view.group.IGroupView;
|
import haxework.view.group.IGroupView;
|
||||||
import haxework.view.skin.ISkin;
|
import haxework.view.skin.ISkin;
|
||||||
import haxework.view.theme.StyleId;
|
import haxework.view.theme.StyleId;
|
||||||
@@ -20,7 +20,7 @@ interface IView<C:DisplayObject> {
|
|||||||
public var width(default, null):Float;
|
public var width(default, null):Float;
|
||||||
public var height(default, null):Float;
|
public var height(default, null):Float;
|
||||||
|
|
||||||
public var size(default, null):Size;
|
public var size(default, null):SizeSet;
|
||||||
|
|
||||||
public var style(default, set):StyleId;
|
public var style(default, set):StyleId;
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import haxework.view.theme.ITheme;
|
|||||||
public var width(default, null):Float;
|
public var width(default, null):Float;
|
||||||
public var height(default, null):Float;
|
public var height(default, null):Float;
|
||||||
|
|
||||||
public var size(default, null):Size;
|
public var size(default, null):SizeSet;
|
||||||
|
|
||||||
public var content(default, null):C;
|
public var content(default, null):C;
|
||||||
|
|
||||||
@@ -40,12 +40,9 @@ import haxework.view.theme.ITheme;
|
|||||||
|
|
||||||
public var rect(get, null):Rectangle;
|
public var rect(get, null):Rectangle;
|
||||||
|
|
||||||
private var sizeSet:SizeSet;
|
|
||||||
|
|
||||||
public function new(content:C) {
|
public function new(content:C) {
|
||||||
id = Type.getClassName(Type.getClass(this)) + counter++;
|
id = Type.getClassName(Type.getClass(this)) + counter++;
|
||||||
sizeSet = new SizeSet();
|
size = new SizeSet();
|
||||||
size = 0;
|
|
||||||
this.content = content;
|
this.content = content;
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
@@ -90,13 +87,10 @@ import haxework.view.theme.ITheme;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setSize(width:Float, height:Float, type:String = "default"):Void {
|
public function setSize(width:Float, height:Float, type:String = "default"):Void {
|
||||||
if (sizeSet.update([width, height], type)) {
|
if (size.update([width, height], type)) {
|
||||||
var s = sizeSet.toSize();
|
var s = size.toSize();
|
||||||
this.width = s.width + geometry.padding.horizontal;
|
this.width = s.width + geometry.padding.horizontal;
|
||||||
this.height = s.height + geometry.padding.vertical;
|
this.height = s.height + geometry.padding.vertical;
|
||||||
size = sizeSet.toSize(false);
|
|
||||||
size.width += geometry.padding.horizontal;
|
|
||||||
size.height += geometry.padding.vertical;
|
|
||||||
toUpdateParent();
|
toUpdateParent();
|
||||||
toRedraw();
|
toRedraw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class SizeSet extends StringMap<Size> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function update(value:Size, type:String = "default"):Bool {
|
public function update(value:Size, type:String = "default"):Bool {
|
||||||
var existValue = get(type);
|
var existValue:Size = get(type);
|
||||||
if (existValue == null || value.width != existValue.width || value.height != existValue.height) {
|
if (existValue == null || value.width != existValue.width || value.height != existValue.height) {
|
||||||
set(type, value);
|
set(type, value);
|
||||||
return true;
|
return true;
|
||||||
@@ -17,10 +17,10 @@ class SizeSet extends StringMap<Size> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toSize(percent:Bool = true):Size {
|
public function toSize(?exclude:String):Size {
|
||||||
var result:Size = 0;
|
var result:Size = 0;
|
||||||
for (type in keys()) {
|
for (type in keys()) {
|
||||||
if (percent || type.indexOf("percent") == -1) {
|
if (exclude == null || type.indexOf(exclude) == -1) {
|
||||||
var value = get(type);
|
var value = get(type);
|
||||||
result.width = Math.max(result.width, value.width);
|
result.width = Math.max(result.width, value.width);
|
||||||
result.height = Math.max(result.height, value.height);
|
result.height = Math.max(result.height, value.height);
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ class DefaultLayout extends Layout {
|
|||||||
setViewHeight(group, view);
|
setViewHeight(group, view);
|
||||||
placeViewHorizontal(group, view);
|
placeViewHorizontal(group, view);
|
||||||
placeViewVertical(group, view);
|
placeViewVertical(group, view);
|
||||||
width = Math.max(width, view.size.width + view.geometry.margin.horizontal);
|
var size = view.size.toSize("percent");
|
||||||
height = Math.max(height, view.size.height + view.geometry.margin.horizontal);
|
width = Math.max(width, size.width + view.geometry.margin.horizontal);
|
||||||
|
height = Math.max(height, size.height + view.geometry.margin.horizontal);
|
||||||
}
|
}
|
||||||
if (!overflow) group.setSize(width, height, "group");
|
if (!overflow) group.setSize(width, height, "group");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class HorizontalLayout extends DefaultLayout {
|
|||||||
case FIXED:
|
case FIXED:
|
||||||
fixedSize += (view.width + view.geometry.margin.horizontal);
|
fixedSize += (view.width + view.geometry.margin.horizontal);
|
||||||
}
|
}
|
||||||
maxSize = Math.max(maxSize, view.size.height + view.geometry.margin.vertical);
|
maxSize = Math.max(maxSize, view.size.toSize("percent").height + view.geometry.padding.vertical + view.geometry.margin.vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!overflow) group.setSize(fixedSize, maxSize, "group");
|
if (!overflow) group.setSize(fixedSize, maxSize, "group");
|
||||||
|
|||||||
@@ -34,12 +34,13 @@ class TailLayout extends DefaultLayout {
|
|||||||
views: [],
|
views: [],
|
||||||
}
|
}
|
||||||
var w:Float = 0;
|
var w:Float = 0;
|
||||||
|
var size = group.size.toSize("group");
|
||||||
for (view in views) {
|
for (view in views) {
|
||||||
setViewWidth(group, view);
|
setViewWidth(group, view);
|
||||||
setViewHeight(group, view);
|
setViewHeight(group, view);
|
||||||
if (
|
if (
|
||||||
(rowSize > 0 && row.views.length >= rowSize) ||
|
(rowSize > 0 && row.views.length >= rowSize) ||
|
||||||
(/*rowSize == 0 && */row.width + view.width + margin + group.geometry.margin.horizontal > group.width)
|
(/*rowSize == 0 && */row.width + view.width + margin + group.geometry.margin.horizontal > size.width)
|
||||||
) {
|
) {
|
||||||
row.width -= margin;
|
row.width -= margin;
|
||||||
w = Math.max(w, row.width);
|
w = Math.max(w, row.width);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class VerticalLayout extends DefaultLayout {
|
|||||||
case FIXED:
|
case FIXED:
|
||||||
fixedSize += (Math.max(view.geometry.height.value, view.height) + view.geometry.margin.vertical);
|
fixedSize += (Math.max(view.geometry.height.value, view.height) + view.geometry.margin.vertical);
|
||||||
}
|
}
|
||||||
maxSize = Math.max(maxSize, view.size.width + view.geometry.margin.horizontal);
|
maxSize = Math.max(maxSize, view.size.toSize("percent").width + view.geometry.padding.horizontal + view.geometry.margin.horizontal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!overflow) group.setSize(maxSize, fixedSize, "group");
|
if (!overflow) group.setSize(maxSize, fixedSize, "group");
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ import haxework.view.layout.Layout;
|
|||||||
|
|
||||||
private function placeTextField(textField:TextField):Void {
|
private function placeTextField(textField:TextField):Void {
|
||||||
textField.width = width;
|
textField.width = width;
|
||||||
textField.height = sizeSet.exists("text") ? sizeSet.get("text").height : height;
|
textField.height = size.exists("text") ? size.get("text").height : height;
|
||||||
//textField.height = height;
|
//textField.height = height;
|
||||||
|
|
||||||
textField.x = switch (layout.hAlign) {
|
textField.x = switch (layout.hAlign) {
|
||||||
|
|||||||
@@ -78,10 +78,10 @@ class Theme implements ITheme {
|
|||||||
"font.embed" => font.embed,
|
"font.embed" => font.embed,
|
||||||
]);
|
]);
|
||||||
data.set("text0", create([
|
data.set("text0", create([
|
||||||
"font.color" => colors.light.diff(-16),
|
"skin.background.color" => colors.light.diff(-16),
|
||||||
], ["text"]));
|
], ["text"]));
|
||||||
data.set("text1", create([
|
data.set("text1", create([
|
||||||
"font.color" => colors.light.diff(16),
|
"skin.background.color" => colors.light.diff(16),
|
||||||
], ["text"]));
|
], ["text"]));
|
||||||
data.set("label", create([
|
data.set("label", create([
|
||||||
"geometry.padding" => Box.fromArray([8, 2]),
|
"geometry.padding" => Box.fromArray([8, 2]),
|
||||||
|
|||||||
Reference in New Issue
Block a user