[style] rework
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
"template"
|
"template"
|
||||||
],
|
],
|
||||||
"description": "View framework.",
|
"description": "View framework.",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"releasenote": "Update.",
|
"releasenote": "Update.",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"shmyga"
|
"shmyga"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package haxework;
|
package haxework;
|
||||||
|
|
||||||
|
import flash.display.BitmapData;
|
||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
import haxework.animate.Animate;
|
import haxework.animate.Animate;
|
||||||
import haxework.animate.FadeAnimate;
|
import haxework.animate.FadeAnimate;
|
||||||
@@ -15,8 +16,13 @@ class App {
|
|||||||
@:provide var theme:ITheme;
|
@:provide var theme:ITheme;
|
||||||
@:provide var popupManager:PopupManager;
|
@:provide var popupManager:PopupManager;
|
||||||
|
|
||||||
public function new(?theme:ITheme) {
|
public function new(?theme:ITheme, ?icon:BitmapData) {
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
|
#if linux
|
||||||
|
if (icon != null) {
|
||||||
|
haxework.app.LinuxIcon.value = icon;
|
||||||
|
}
|
||||||
|
#end
|
||||||
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v);
|
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v);
|
||||||
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v);
|
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v);
|
||||||
app = this;
|
app = this;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ru.m.puzzlez;
|
package haxework.app;
|
||||||
|
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import flash.filters.ColorMatrixFilter;
|
import flash.filters.ColorMatrixFilter;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class PositionYamlParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function parseAll():Void {
|
private function parseAll():Void {
|
||||||
parseBlock(result);
|
//parseBlock(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseBlock(result:DynamicAccess<Dynamic>):Void {
|
private function parseBlock(result:DynamicAccess<Dynamic>):Void {
|
||||||
|
|||||||
@@ -18,6 +18,15 @@ abstract StyleId(Array<String>) {
|
|||||||
return this.remove(value);
|
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<String> {
|
@:to public inline function toArray():Array<String> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package haxework.view.theme;
|
package haxework.view.theme;
|
||||||
|
|
||||||
import haxework.view.geometry.VAlign;
|
|
||||||
import haxework.view.geometry.HAlign;
|
|
||||||
import flash.text.Font;
|
import flash.text.Font;
|
||||||
import flash.text.FontType;
|
import flash.text.FontType;
|
||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import haxework.signal.Signal;
|
import haxework.signal.Signal;
|
||||||
import haxework.view.geometry.Box;
|
import haxework.view.geometry.Box;
|
||||||
|
import haxework.view.geometry.HAlign;
|
||||||
import haxework.view.geometry.SizeValue;
|
import haxework.view.geometry.SizeValue;
|
||||||
|
import haxework.view.geometry.VAlign;
|
||||||
import haxework.view.skin.TabColorSkin;
|
import haxework.view.skin.TabColorSkin;
|
||||||
import haxework.view.theme.ITheme;
|
import haxework.view.theme.ITheme;
|
||||||
|
|
||||||
@@ -25,19 +25,68 @@ class Style {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StyleBundle {
|
||||||
|
|
||||||
|
private var data:Map<String, Map<String, Dynamic>>;
|
||||||
|
private var parentMap:Map<String, String>;
|
||||||
|
|
||||||
|
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<Dynamic> {
|
||||||
|
var result = null;
|
||||||
|
if (data.exists(key)) {
|
||||||
|
var bundle:Map<String, Dynamic> = 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 {
|
class Theme implements ITheme {
|
||||||
public var font(default, set):ThemeFont;
|
public var font(default, set):ThemeFont;
|
||||||
public var fontSize(default, set):ThemeFontSize;
|
public var fontSize(default, set):ThemeFontSize;
|
||||||
public var colors(default, set):ThemeColors;
|
public var colors(default, set):ThemeColors;
|
||||||
public var updateSignal(default, null):Signal0;
|
public var updateSignal(default, null):Signal0;
|
||||||
|
|
||||||
private var data:Map<String, Style>;
|
|
||||||
private var cache:Map<String, Dynamic>;
|
private var cache:Map<String, Dynamic>;
|
||||||
|
private var bundle:StyleBundle;
|
||||||
|
|
||||||
public function new(?font:ThemeFont, ?colors:ThemeColors, ?fontSize:ThemeFontSize) {
|
public function new(?font:ThemeFont, ?colors:ThemeColors, ?fontSize:ThemeFontSize) {
|
||||||
updateSignal = new Signal0();
|
updateSignal = new Signal0();
|
||||||
data = new Map();
|
|
||||||
cache = new Map();
|
cache = new Map();
|
||||||
|
bundle = new StyleBundle();
|
||||||
this.font = font;
|
this.font = font;
|
||||||
this.colors = colors;
|
this.colors = colors;
|
||||||
this.fontSize = fontSize;
|
this.fontSize = fontSize;
|
||||||
@@ -79,7 +128,7 @@ class Theme implements ITheme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function register(style:Style):Void {
|
private function register(style:Style):Void {
|
||||||
data.set(style.id, style);
|
bundle.register(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function reload():Void {
|
private function reload():Void {
|
||||||
@@ -148,20 +197,8 @@ class Theme implements ITheme {
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _resolve<T>(key:String, style:Style):Null<T> {
|
private function _resolve<T>(key:String, style:StyleId):Null<T> {
|
||||||
if (style == null) {
|
return bundle.get(key, style);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolve<T>(key:String, style:StyleId):T {
|
public function resolve<T>(key:String, style:StyleId):T {
|
||||||
@@ -171,7 +208,7 @@ class Theme implements ITheme {
|
|||||||
if (cache.exists(k)) {
|
if (cache.exists(k)) {
|
||||||
result = cache.get(k);
|
result = cache.get(k);
|
||||||
} else {
|
} else {
|
||||||
result = _resolve(key, data.get(style));
|
result = _resolve(key, style);
|
||||||
cache.set(k, result);
|
cache.set(k, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user