[view] fixes

This commit is contained in:
2019-07-13 16:14:27 +03:00
parent b488e6f88a
commit 5faa179116
11 changed files with 70 additions and 30 deletions

View File

@@ -16,7 +16,7 @@ import haxework.view.group.VGroupView;
@:view var tabs:ButtonGroup<String>; @:view var tabs:ButtonGroup<String>;
private function init():Void { private function init():Void {
switcher.change("tail"); switcher.change("list");
} }
private function onFrameSwitch(frame:FrameView<Dynamic>):Void { private function onFrameSwitch(frame:FrameView<Dynamic>):Void {

View File

@@ -11,7 +11,7 @@ views:
geometry.width: 100% geometry.width: 100%
geometry.padding.left: 5 geometry.padding.left: 5
geometry.margin.bottom: -6 geometry.margin.bottom: -6
buttonStyle: tab buttonStyle: button.tab
+onDataSelect: ~function(id) switcher.change(id) +onDataSelect: ~function(id) switcher.change(id)
data: data:
- "list" - "list"

View File

@@ -74,7 +74,11 @@ class View<C:DisplayObject> implements IView<C> {
} }
public function update():Void { public function update():Void {
setSize(geometry.width.fixed, geometry.height.fixed, "geometry"); setSize(
geometry.width.fixed - geometry.padding.horizontal,
geometry.height.fixed - geometry.padding.vertical,
"geometry"
);
} }
public function redraw():Void { public function redraw():Void {

View File

@@ -57,7 +57,7 @@ class FrameSwitcher extends GroupView {
} }
addView(current); addView(current);
toUpdate(); toUpdate();
//update(); update();
//ToDo: //ToDo:
if (content.stage != null) { if (content.stage != null) {
content.stage.focus = current.content; content.stage.focus = current.content;

View File

@@ -4,29 +4,31 @@ import flash.display.CapsStyle;
import flash.display.Graphics; import flash.display.Graphics;
import flash.display.JointStyle; import flash.display.JointStyle;
import flash.display.LineScaleMode; import flash.display.LineScaleMode;
import haxework.color.ColorUtil; import haxework.color.Color;
import haxework.view.form.ButtonView; import haxework.view.form.ButtonView;
import haxework.view.form.ToggleButtonView; import haxework.view.form.ToggleButtonView;
using haxework.color.ColorUtil;
class ButtonColorSkin implements ISkin<ButtonView> { class ButtonColorSkin implements ISkin<ButtonView> {
public var color(default, default):Int; public var color(default, default):Color;
public var borderColor(default, default):Int; public var borderColor(default, default):Null<Color>;
public var round(default, default):Float; public var round(default, default):Float;
private var colors:Map<ButtonState, Int>; private var colors:Map<ButtonState, Int>;
public function new(color:Int = 0xffffff, borderColor:Int = -1, round:Float = 15) { public function new(?color:Color, ?borderColor:Color, round:Float = 15) {
this.color = color; this.color = color != null ? color : 0xffffff;
this.borderColor = borderColor; this.borderColor = borderColor;
this.round = round; this.round = round;
} }
public function draw(view:ButtonView):Void { public function draw(view:ButtonView):Void {
var color:Int = stateColor(color, view.state); var color:Color = stateColor(color, view.state);
var borderColor:Int = borderColor > -1 ? borderColor : ColorUtil.multiply(color, 1.5); var borderColor:Color = borderColor != null ? borderColor : color.multiply(1.5);
if (Std.is(view, ToggleButtonView)) { if (Std.is(view, ToggleButtonView)) {
if (!cast(view, ToggleButtonView).on) { if (!cast(view, ToggleButtonView).on) {
color = ColorUtil.multiply(color, 0.5); color = color.multiply(0.5);
} }
} }
var graphics:Graphics = view.content.graphics; var graphics:Graphics = view.content.graphics;
@@ -37,12 +39,12 @@ class ButtonColorSkin implements ISkin<ButtonView> {
graphics.endFill(); graphics.endFill();
} }
private static function stateColor(color:Int, state:ButtonState):Int { private static function stateColor(color:Color, state:ButtonState):Color {
return switch state { return switch state {
case UP: color; case UP: color;
case DOWN: ColorUtil.diff(color, -24); case DOWN: color.diff(-24);
case OVER: ColorUtil.diff(color, 24); case OVER: color.diff(24);
case DISABLED: ColorUtil.multiply(color, 0.6); case DISABLED: color.multiply(0.6);
} }
} }
} }

View File

@@ -1,6 +1,7 @@
package haxework.view.skin; package haxework.view.skin;
import flash.display.BitmapData; import flash.display.BitmapData;
import haxework.color.Color;
import haxework.view.form.ButtonView; import haxework.view.form.ButtonView;
import haxework.view.utils.DrawUtil; import haxework.view.utils.DrawUtil;
@@ -16,7 +17,7 @@ class Skin {
return new SpriteSkin({color: color, alpha: alpha}); return new SpriteSkin({color: color, alpha: alpha});
} }
public static function buttonColor(color:Int, borderColor:Int = -1):ISkin<ButtonView> { public static function buttonColor(color:Color, ?borderColor:Color):ISkin<ButtonView> {
return new ButtonColorSkin(color, borderColor); return new ButtonColorSkin(color, borderColor);
} }

View File

@@ -6,18 +6,18 @@ import flash.text.TextFormatAlign;
class FontPreset { class FontPreset {
public var family(default, default):String; public var family(default, default):String;
public var embed(default, default):Bool; public var embed(default, default):Bool;
public var color(default, default):Color; public var color(default, default):Null<Color>;
public var size(default, default):Int; public var size(default, default):Null<Int>;
public var bold(default, default):Bool; public var bold(default, default):Bool;
public var align(default, default):TextFormatAlign; public var align(default, default):TextFormatAlign;
public function new(family:String = null, embed:Bool = false, color:Color = null, size:Int = 16, public function new(?family:String, ?embed:Bool, ?color:Color, ?size:Int,
bold:Bool = false, align:TextFormatAlign = null) { ?bold:Bool, ?align:TextFormatAlign) {
this.family = family; this.family = family;
this.embed = embed; this.embed = embed;
this.color = color != null ? color : 0xffffff; this.color = color;
this.size = size; this.size = size;
this.bold = bold; this.bold = bold;
this.align = align != null ? align : TextFormatAlign.LEFT; this.align = align;
} }
} }

View File

@@ -12,7 +12,23 @@ class FontStyle implements IStyle<ITextView> {
} }
public function apply(view:ITextView):Void { public function apply(view:ITextView):Void {
view.font = font; var update = false;
view.toUpdate(); if (font.family != null) {
view.font.family = font.family;
view.font.embed = font.embed;
update = true;
}
if (font.color != null) {
view.font.color = font.color;
update = true;
}
if (font.size != null) {
view.font.size = font.size;
update = true;
}
// ToDo: other properties
if (update) {
view.toUpdate();
}
} }
} }

View File

@@ -29,6 +29,7 @@ class GeometryStyle implements IStyle<IView<Dynamic>> {
update = true; update = true;
} }
if (update) { if (update) {
view.toUpdate();
view.toUpdateParent(); view.toUpdateParent();
} }
} }

View File

@@ -1,5 +1,6 @@
package haxework.view.theme; package haxework.view.theme;
import haxework.view.geometry.HAlign;
import haxework.view.group.IGroupView; import haxework.view.group.IGroupView;
import haxework.view.layout.ILayout; import haxework.view.layout.ILayout;
@@ -12,7 +13,21 @@ class LayoutStyle implements IStyle<IGroupView> {
} }
public function apply(view:IGroupView):Void { public function apply(view:IGroupView):Void {
view.layout = layout; var update = false;
view.toUpdate(); if (layout.margin != 0) {
view.layout.margin = layout.margin;
update = true;
}
if (layout.hAlign != NONE) {
view.layout.hAlign = layout.hAlign;
update = true;
}
if (layout.vAlign != NONE) {
view.layout.vAlign = layout.vAlign;
update = true;
}
if (update) {
view.toUpdate();
}
} }
} }

View File

@@ -97,8 +97,9 @@ class Theme implements ITheme {
styles.put("text", text()); styles.put("text", text());
styles.put("label", text().concat([new GeometryStyle(new Geometry().setPadding([8, 2]))])); styles.put("label", text().concat([new GeometryStyle(new Geometry().setPadding([8, 2]))]));
styles.put("button", button()); styles.put("button", button());
styles.put("button.active", button(null, null, colors.active));
styles.put("dropdown", background(null, true)); styles.put("dropdown", background(null, true));
styles.put("tab", text().concat([ styles.put("button.tab", text().concat([
new SkinStyle(Skin.tabColor(this.colors.light)), new SkinStyle(Skin.tabColor(this.colors.light)),
new GeometryStyle(new Geometry().setPadding([25, 8])) new GeometryStyle(new Geometry().setPadding([25, 8]))
])); ]));
@@ -137,12 +138,12 @@ class Theme implements ITheme {
]; ];
} }
public function button(?color:Color, ?textColor:Color):StyleSet { public function button(?color:Color, ?textColor:Color, ?borderColor:Color):StyleSet {
if (color == null) { if (color == null) {
color = colors.light; color = colors.light;
} }
return text(textColor).concat([ return text(textColor).concat([
new SkinStyle(Skin.buttonColor(color)), new SkinStyle(Skin.buttonColor(color, borderColor)),
new GeometryStyle(new Geometry().setPadding([25, 8])), new GeometryStyle(new Geometry().setPadding([25, 8])),
]); ]);
} }