From 39ca4b3d9bbf7572fdbfc76539f23b7372a8f157 Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 11 Feb 2020 22:47:03 +0300 Subject: [PATCH] [style] rework --- haxelib.json | 2 +- src/main/haxework/App.hx | 8 +- src/main/haxework/app/LinuxIcon.hx | 2 +- src/main/haxework/macro/PositionYamlParser.hx | 2 +- src/main/haxework/view/theme/StyleId.hx | 9 +++ src/main/haxework/view/theme/Theme.hx | 77 ++++++++++++++----- 6 files changed, 76 insertions(+), 24 deletions(-) diff --git a/haxelib.json b/haxelib.json index fb15405..08eff7b 100755 --- a/haxelib.json +++ b/haxelib.json @@ -8,7 +8,7 @@ "template" ], "description": "View framework.", - "version": "1.0.0", + "version": "1.1.0", "releasenote": "Update.", "contributors": [ "shmyga" diff --git a/src/main/haxework/App.hx b/src/main/haxework/App.hx index 11996c8..e42f7b4 100644 --- a/src/main/haxework/App.hx +++ b/src/main/haxework/App.hx @@ -1,5 +1,6 @@ package haxework; +import flash.display.BitmapData; import flash.Lib; import haxework.animate.Animate; import haxework.animate.FadeAnimate; @@ -15,8 +16,13 @@ class App { @:provide var theme:ITheme; @:provide var popupManager:PopupManager; - public function new(?theme:ITheme) { + public function new(?theme:ITheme, ?icon:BitmapData) { this.theme = theme; + #if linux + if (icon != null) { + haxework.app.LinuxIcon.value = icon; + } + #end popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v); popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v); app = this; diff --git a/src/main/haxework/app/LinuxIcon.hx b/src/main/haxework/app/LinuxIcon.hx index a6b7f39..0a448f5 100644 --- a/src/main/haxework/app/LinuxIcon.hx +++ b/src/main/haxework/app/LinuxIcon.hx @@ -1,4 +1,4 @@ -package ru.m.puzzlez; +package haxework.app; import flash.display.BitmapData; import flash.filters.ColorMatrixFilter; diff --git a/src/main/haxework/macro/PositionYamlParser.hx b/src/main/haxework/macro/PositionYamlParser.hx index ddec310..a5b8ab3 100644 --- a/src/main/haxework/macro/PositionYamlParser.hx +++ b/src/main/haxework/macro/PositionYamlParser.hx @@ -17,7 +17,7 @@ class PositionYamlParser { } private function parseAll():Void { - parseBlock(result); + //parseBlock(result); } private function parseBlock(result:DynamicAccess):Void { diff --git a/src/main/haxework/view/theme/StyleId.hx b/src/main/haxework/view/theme/StyleId.hx index ec8928c..61ed3c5 100644 --- a/src/main/haxework/view/theme/StyleId.hx +++ b/src/main/haxework/view/theme/StyleId.hx @@ -18,6 +18,15 @@ abstract StyleId(Array) { return this.remove(value); } + public function match(value:StyleId):Bool { + for (v in value.toArray()) { + if (this.indexOf(v) == -1) { + return false; + } + } + return true; + } + @:to public inline function toArray():Array { return this; } diff --git a/src/main/haxework/view/theme/Theme.hx b/src/main/haxework/view/theme/Theme.hx index 5db1db8..6f43bc7 100644 --- a/src/main/haxework/view/theme/Theme.hx +++ b/src/main/haxework/view/theme/Theme.hx @@ -1,13 +1,13 @@ package haxework.view.theme; -import haxework.view.geometry.VAlign; -import haxework.view.geometry.HAlign; import flash.text.Font; import flash.text.FontType; import haxework.color.Color; import haxework.signal.Signal; import haxework.view.geometry.Box; +import haxework.view.geometry.HAlign; import haxework.view.geometry.SizeValue; +import haxework.view.geometry.VAlign; import haxework.view.skin.TabColorSkin; import haxework.view.theme.ITheme; @@ -25,19 +25,68 @@ class Style { } } +class StyleBundle { + + private var data:Map>; + private var parentMap:Map; + + public function new() { + data = new Map(); + parentMap = new Map(); + } + + public function register(style:Style):Void { + for (key in style.data.keys()) { + if (!data.exists(key)) { + data.set(key, new Map()); + } + data.get(key).set(style.id, style.data.get(key)); + } + if (style.parent != null) { + parentMap.set(style.id, style.parent); + } + } + + public function get(key:String, id:StyleId):Null { + var result = null; + if (data.exists(key)) { + var bundle:Map = data.get(key); + var length = 0; + for (key in bundle.keys()) { + if (id.match(key) && key.length > length) { + result = bundle.get(key); + length = key.length; + } + } + } + if (result == null) { + if (parentMap.exists(id)) { + var parentId:StyleId = parentMap.get(id); + for (pId in parentId.toArray()) { + result = get(key, pId); + if (result != null) { + break; + } + } + } + } + return result; + } +} + class Theme implements ITheme { public var font(default, set):ThemeFont; public var fontSize(default, set):ThemeFontSize; public var colors(default, set):ThemeColors; public var updateSignal(default, null):Signal0; - private var data:Map; private var cache:Map; + private var bundle:StyleBundle; public function new(?font:ThemeFont, ?colors:ThemeColors, ?fontSize:ThemeFontSize) { updateSignal = new Signal0(); - data = new Map(); cache = new Map(); + bundle = new StyleBundle(); this.font = font; this.colors = colors; this.fontSize = fontSize; @@ -79,7 +128,7 @@ class Theme implements ITheme { } private function register(style:Style):Void { - data.set(style.id, style); + bundle.register(style); } private function reload():Void { @@ -148,20 +197,8 @@ class Theme implements ITheme { ])); } - private function _resolve(key:String, style:Style):Null { - if (style == null) { - return null; - } else if (style.data.exists(key)) { - return style.data.get(key); - } else if (style.parent != null) { - for (s in style.parent.toArray()) { - var result = _resolve(key, data.get(s)); - if (result != null) { - return result; - } - } - } - return null; + private function _resolve(key:String, style:StyleId):Null { + return bundle.get(key, style); } public function resolve(key:String, style:StyleId):T { @@ -171,7 +208,7 @@ class Theme implements ITheme { if (cache.exists(k)) { result = cache.get(k); } else { - result = _resolve(key, data.get(style)); + result = _resolve(key, style); cache.set(k, result); } }