diff --git a/.gitignore b/.gitignore index bc8b069..324fab2 100755 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ out/ target/ *.zip -pack.sh \ No newline at end of file +pack.sh +.vscode/ diff --git a/build.hxml b/build.hxml new file mode 100644 index 0000000..a2d1d32 --- /dev/null +++ b/build.hxml @@ -0,0 +1 @@ +-p src/main \ No newline at end of file diff --git a/haxelib.json b/haxelib.json index c0543d2..7e41049 100755 --- a/haxelib.json +++ b/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" } } diff --git a/src/main/hw/view/Root.hx b/src/main/hw/view/Root.hx index 356fe64..20e8b03 100755 --- a/src/main/hw/view/Root.hx +++ b/src/main/hw/view/Root.hx @@ -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(); diff --git a/src/main/hw/view/geometry/SizeValue.hx b/src/main/hw/view/geometry/SizeValue.hx index 51a9597..bb6b008 100644 --- a/src/main/hw/view/geometry/SizeValue.hx +++ b/src/main/hw/view/geometry/SizeValue.hx @@ -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)); } diff --git a/src/main/hw/view/layout/HorizontalLayout.hx b/src/main/hw/view/layout/HorizontalLayout.hx index 79c2b22..47d9e5b 100755 --- a/src/main/hw/view/layout/HorizontalLayout.hx +++ b/src/main/hw/view/layout/HorizontalLayout.hx @@ -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); diff --git a/src/main/hw/view/layout/VerticalLayout.hx b/src/main/hw/view/layout/VerticalLayout.hx index 06daf48..acc65b4 100755 --- a/src/main/hw/view/layout/VerticalLayout.hx +++ b/src/main/hw/view/layout/VerticalLayout.hx @@ -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); diff --git a/src/main/hw/view/text/FontPreset.hx b/src/main/hw/view/text/FontPreset.hx index 9749a34..7f5c202 100644 --- a/src/main/hw/view/text/FontPreset.hx +++ b/src/main/hw/view/text/FontPreset.hx @@ -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; @:style(0xffffff) public var color(default, default):Null; - @:style(16) public var size(default, default):Null; + @:style(16) public var size(default, default):Null; @:style(false) public var bold(default, default):Null; @: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; diff --git a/src/main/hw/view/text/TextView.hx b/src/main/hw/view/text/TextView.hx index 38d9a9a..3dbe624 100755 --- a/src/main/hw/view/text/TextView.hx +++ b/src/main/hw/view/text/TextView.hx @@ -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 ); diff --git a/src/main/hw/view/theme/ITheme.hx b/src/main/hw/view/theme/ITheme.hx index 1660710..018d832 100644 --- a/src/main/hw/view/theme/ITheme.hx +++ b/src/main/hw/view/theme/ITheme.hx @@ -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 {