feat(view): add display width and height size types
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,4 +5,5 @@
|
||||
out/
|
||||
target/
|
||||
*.zip
|
||||
pack.sh
|
||||
pack.sh
|
||||
.vscode/
|
||||
|
||||
1
build.hxml
Normal file
1
build.hxml
Normal file
@@ -0,0 +1 @@
|
||||
-p src/main
|
||||
14
haxelib.json
14
haxelib.json
@@ -2,22 +2,16 @@
|
||||
"name": "haxework",
|
||||
"url": "https://bitbucket.org/shmyga/haxework",
|
||||
"license": "MIT",
|
||||
"tags": [
|
||||
"view",
|
||||
"layout",
|
||||
"template"
|
||||
],
|
||||
"tags": ["view", "layout", "template"],
|
||||
"description": "View framework.",
|
||||
"version": "2.0.0",
|
||||
"version": "2.1.0",
|
||||
"releasenote": "Update.",
|
||||
"contributors": [
|
||||
"shmyga"
|
||||
],
|
||||
"contributors": ["shmyga"],
|
||||
"classPath": "src/main",
|
||||
"dependencies": {
|
||||
"promhx": "1.1.0",
|
||||
"protohx": "0.4.6",
|
||||
"haxe-crypto": "0.0.8",
|
||||
"haxe-crypto": "0.0.8",
|
||||
"yaml": "2.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import flash.Lib;
|
||||
import hw.provider.Provider;
|
||||
import hw.signal.Signal;
|
||||
import hw.view.group.IGroupView;
|
||||
import hw.view.geometry.SizeValue.DisplaySize;
|
||||
|
||||
class Root {
|
||||
|
||||
@@ -55,6 +56,7 @@ class Root {
|
||||
|
||||
private function onResizeEvent(?_):Void {
|
||||
var content:DisplayObject = view.content;
|
||||
DisplaySize.instance.update(content.stage.stageWidth, content.stage.stageHeight);
|
||||
if (autoSize) {
|
||||
view.setSize(content.stage.stageWidth, content.stage.stageHeight, "stage");
|
||||
view.toUpdate();
|
||||
|
||||
@@ -3,9 +3,30 @@ package hw.view.geometry;
|
||||
enum SizeType {
|
||||
FIXED;
|
||||
PERCENT;
|
||||
DISPLAY_WIDTH;
|
||||
DISPLAY_HEIGHT;
|
||||
}
|
||||
|
||||
@:singleton class DisplaySize {
|
||||
public var width:Int;
|
||||
public var height:Int;
|
||||
|
||||
public function new(width:Int = 0, height:Int = 0) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public function update(width:Int, height:Int) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
abstract SizeValue({type:SizeType, value:Float}) {
|
||||
public static final PERCENT_TYPE_CHAR:String = "%";
|
||||
public static final DISPLAY_WIDTH_TYPE_CHAR:String = "w";
|
||||
public static final DISPLAY_HEIGHT_TYPE_CHAR:String = "h";
|
||||
|
||||
public var type(get, set):SizeType;
|
||||
public var value(get, set):Float;
|
||||
|
||||
@@ -35,6 +56,8 @@ abstract SizeValue({type:SizeType, value:Float}) {
|
||||
private inline function get_fixed():Float {
|
||||
return switch type {
|
||||
case FIXED: value;
|
||||
case DISPLAY_WIDTH: value * (DisplaySize.instance.width / 100);
|
||||
case DISPLAY_HEIGHT: value * (DisplaySize.instance.height / 100);
|
||||
case _: 0;
|
||||
}
|
||||
}
|
||||
@@ -65,8 +88,13 @@ abstract SizeValue({type:SizeType, value:Float}) {
|
||||
}
|
||||
|
||||
@:from static public inline function fromString(value:String):SizeValue {
|
||||
if (value.substr(value.length - 1) == "%") {
|
||||
var typeChar = value.substr(value.length - 1);
|
||||
if (typeChar == PERCENT_TYPE_CHAR) {
|
||||
return new SizeValue(PERCENT, Std.parseFloat(value));
|
||||
} else if (typeChar == DISPLAY_WIDTH_TYPE_CHAR) {
|
||||
return new SizeValue(DISPLAY_WIDTH, Std.parseFloat(value));
|
||||
} else if (typeChar == DISPLAY_HEIGHT_TYPE_CHAR) {
|
||||
return new SizeValue(DISPLAY_HEIGHT, Std.parseFloat(value));
|
||||
} else {
|
||||
return new SizeValue(FIXED, Std.parseFloat(value));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class HorizontalLayout extends DefaultLayout {
|
||||
switch view.geometry.width.type {
|
||||
case PERCENT:
|
||||
leftSize -= (view.geometry.margin.horizontal);
|
||||
case FIXED:
|
||||
case FIXED | DISPLAY_WIDTH | DISPLAY_HEIGHT:
|
||||
fixedSize += (view.width + view.geometry.margin.horizontal);
|
||||
}
|
||||
maxSize = Math.max(maxSize, view.size.toSize("percent").height + view.geometry.padding.vertical + view.geometry.margin.vertical);
|
||||
|
||||
@@ -19,7 +19,7 @@ class VerticalLayout extends DefaultLayout {
|
||||
switch view.geometry.height.type {
|
||||
case PERCENT:
|
||||
leftSize -= (view.geometry.margin.vertical);
|
||||
case FIXED:
|
||||
case FIXED | DISPLAY_WIDTH | DISPLAY_HEIGHT:
|
||||
fixedSize += (Math.max(view.geometry.height.value, view.height) + view.geometry.margin.vertical);
|
||||
}
|
||||
maxSize = Math.max(maxSize, view.size.toSize("percent").width + view.geometry.padding.horizontal + view.geometry.margin.horizontal);
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package hw.view.text;
|
||||
|
||||
import hw.color.Color;
|
||||
import hw.view.geometry.SizeValue;
|
||||
import flash.text.TextFormatAlign;
|
||||
|
||||
@:style class FontPreset {
|
||||
@:style("Courirer") public var family(default, default):String;
|
||||
@:style(false) public var embed(default, default):Null<Bool>;
|
||||
@:style(0xffffff) public var color(default, default):Null<Color>;
|
||||
@:style(16) public var size(default, default):Null<Int>;
|
||||
@:style(16) public var size(default, default):Null<SizeValue>;
|
||||
@:style(false) public var bold(default, default):Null<Bool>;
|
||||
@:style(TextFormatAlign.LEFT) public var align(default, default):TextFormatAlign;
|
||||
|
||||
public function new(?family:String, ?embed:Bool, ?color:Color, ?size:Int,
|
||||
public function new(?family:String, ?embed:Bool, ?color:Color, ?size:SizeValue,
|
||||
?bold:Bool, ?align:TextFormatAlign) {
|
||||
this.family = family;
|
||||
this.embed = embed;
|
||||
|
||||
@@ -89,7 +89,7 @@ import hw.view.layout.Layout;
|
||||
}
|
||||
textField.embedFonts = font.embed;
|
||||
textField.defaultTextFormat = new TextFormat(
|
||||
font.family, font.size, font.color,
|
||||
font.family, Std.int(font.size.fixed), font.color,
|
||||
font.bold, false, false, null,
|
||||
font.align
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ package hw.view.theme;
|
||||
|
||||
import hw.signal.Signal;
|
||||
import hw.color.Color;
|
||||
import hw.view.geometry.SizeValue;
|
||||
|
||||
typedef ThemeFont = {
|
||||
@:optional var name:String;
|
||||
@@ -17,9 +18,9 @@ typedef ThemeColors = {
|
||||
}
|
||||
|
||||
typedef ThemeFontSize = {
|
||||
@:optional var base:Float;
|
||||
@:optional var big:Float;
|
||||
@:optional var veryBig:Float;
|
||||
@:optional var base:SizeValue;
|
||||
@:optional var big:SizeValue;
|
||||
@:optional var veryBig:SizeValue;
|
||||
}
|
||||
|
||||
interface ITheme {
|
||||
|
||||
Reference in New Issue
Block a user