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