[gui] update
This commit is contained in:
@@ -1,39 +1,39 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.net.ImageLoader;
|
||||
import haxework.gui.utils.DrawUtil.FillType;
|
||||
import haxework.gui.skin.BitmapSkin;
|
||||
import haxework.gui.skin.ButtonBitmapSkin;
|
||||
import flash.display.BitmapData;
|
||||
import haxework.gui.skin.BitmapSkin;
|
||||
import haxework.gui.utils.DrawUtil.FillType;
|
||||
import haxework.net.ImageLoader;
|
||||
|
||||
class ImageView extends SpriteView {
|
||||
|
||||
public var image(default, set):BitmapData;
|
||||
public var imageUrl(default, set):String;
|
||||
public var image(default, set):BitmapData;
|
||||
public var imageUrl(default, set):String;
|
||||
|
||||
public function new(?image:BitmapData) {
|
||||
super();
|
||||
if (image != null) {
|
||||
this.image = image;
|
||||
public function new(?image:BitmapData) {
|
||||
super();
|
||||
if (image != null) {
|
||||
this.image = image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
skin = [new BitmapSkin(image, FillType.CONTAIN)];
|
||||
invalidate();
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
skin = [new BitmapSkin(image, FillType.DEFAULT)];
|
||||
toUpdate();
|
||||
toRedraw();
|
||||
}
|
||||
return image;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
private function set_imageUrl(value:String):String {
|
||||
if (imageUrl != value) {
|
||||
imageUrl = value;
|
||||
new ImageLoader().GET(imageUrl).then(function(data) {
|
||||
image = data;
|
||||
});
|
||||
private function set_imageUrl(value:String):String {
|
||||
if (imageUrl != value) {
|
||||
imageUrl = value;
|
||||
new ImageLoader().GET(imageUrl).then(function(data) {
|
||||
image = data;
|
||||
});
|
||||
}
|
||||
return imageUrl;
|
||||
}
|
||||
return imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import flash.text.TextFormatAlign;
|
||||
import haxework.dispath.Dispatcher;
|
||||
import haxework.dispath.IDispatcher;
|
||||
import flash.events.Event;
|
||||
import flash.text.TextFormat;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
@@ -15,81 +14,70 @@ import flash.text.TextFieldType;
|
||||
|
||||
class InputView extends TextView implements IDisposable {
|
||||
|
||||
public var hint(default, set):String;
|
||||
public var dispatcher(default, null):IDispatcher<InputViewListener>;
|
||||
public var onKeyUp(null, set):InputViewListener;
|
||||
public var hint(default, set):String;
|
||||
public var onChange(default, null):Signal<String> = new Signal();
|
||||
|
||||
private var hintTextField:TextField;
|
||||
private var hintTextField:TextField;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
dispatcher = new Dispatcher<InputViewListener>();
|
||||
textField.addEventListener(Event.CHANGE, onTextChange);
|
||||
textField.addEventListener(KeyboardEvent.KEY_UP, _onKeyUp);
|
||||
textField.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
public function new() {
|
||||
super();
|
||||
textField.addEventListener(Event.CHANGE, onTextChange);
|
||||
textField.addEventListener(KeyboardEvent.KEY_UP, _onKeyUp);
|
||||
textField.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
|
||||
hintTextField = buildHintTextField();
|
||||
content.addChild(hintTextField);
|
||||
textFormat.align = TextFormatAlign.LEFT;
|
||||
}
|
||||
|
||||
override private function buildTextField():TextField {
|
||||
return new InputTextField();
|
||||
}
|
||||
|
||||
private function set_hint(value:String):String {
|
||||
if (hint != value) {
|
||||
hint = value;
|
||||
invalidate();
|
||||
hintTextField = buildHintTextField();
|
||||
content.addChild(hintTextField);
|
||||
textFormat.align = TextFormatAlign.LEFT;
|
||||
}
|
||||
return hint;
|
||||
}
|
||||
|
||||
private function buildHintTextField():TextField {
|
||||
var textField:TextField = new TextField();
|
||||
textField.autoSize = TextFieldAutoSize.NONE;
|
||||
textField.type = TextFieldType.DYNAMIC;
|
||||
textField.multiline = false;
|
||||
textField.defaultTextFormat = new TextFormat("Arial", 16, 0xa0a0a0);
|
||||
textField.mouseEnabled = false;
|
||||
return textField;
|
||||
}
|
||||
override private function buildTextField():TextField {
|
||||
return new InputTextField();
|
||||
}
|
||||
|
||||
private function onTextChange(event:Event):Void {
|
||||
hintTextField.visible = (textField.text == "");
|
||||
}
|
||||
private function set_hint(value:String):String {
|
||||
if (hint != value) {
|
||||
hint = value;
|
||||
toUpdate();
|
||||
}
|
||||
return hint;
|
||||
}
|
||||
|
||||
private function _onKeyUp(event:KeyboardEvent):Void {
|
||||
event.stopImmediatePropagation();
|
||||
dispatcher.dispatch(function(listener) listener.onKeyUp(textField.text));
|
||||
}
|
||||
private function buildHintTextField():TextField {
|
||||
var textField:TextField = new TextField();
|
||||
textField.autoSize = TextFieldAutoSize.NONE;
|
||||
textField.type = TextFieldType.DYNAMIC;
|
||||
textField.multiline = false;
|
||||
textField.defaultTextFormat = new TextFormat("Arial", 16, 0xa0a0a0);
|
||||
textField.mouseEnabled = false;
|
||||
return textField;
|
||||
}
|
||||
|
||||
private function onKeyDown(event:KeyboardEvent):Void {
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
private function onTextChange(event:Event):Void {
|
||||
hintTextField.visible = (textField.text == "");
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var htf:TextFormat = textField.defaultTextFormat;
|
||||
htf.color = 0xa0a0a0;
|
||||
htf.size -= 2;
|
||||
hintTextField.defaultTextFormat = htf;
|
||||
hintTextField.text = hint == null ? "" : hint;
|
||||
placeTextField(hintTextField);
|
||||
}
|
||||
private function _onKeyUp(event:KeyboardEvent):Void {
|
||||
event.stopImmediatePropagation();
|
||||
onChange.emit(textField.text);
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
textField.removeEventListener(Event.CHANGE, onTextChange);
|
||||
textField.removeEventListener(KeyboardEvent.KEY_UP, _onKeyUp);
|
||||
textField.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
}
|
||||
private function onKeyDown(event:KeyboardEvent):Void {
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
private function set_onKeyUp(value:InputViewListener):InputViewListener {
|
||||
dispatcher.addListener(value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
typedef InputViewListener = {
|
||||
public function onKeyUp(text:String):Void;
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var htf:TextFormat = textField.defaultTextFormat;
|
||||
htf.color = 0xa0a0a0;
|
||||
htf.size -= 2;
|
||||
hintTextField.defaultTextFormat = htf;
|
||||
hintTextField.text = hint == null ? "" : hint;
|
||||
placeTextField(hintTextField);
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
textField.removeEventListener(Event.CHANGE, onTextChange);
|
||||
textField.removeEventListener(KeyboardEvent.KEY_UP, _onKeyUp);
|
||||
textField.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.core.HAlign;
|
||||
|
||||
class LabelView extends TextView {
|
||||
|
||||
public function new() {
|
||||
@@ -8,5 +11,7 @@ class LabelView extends TextView {
|
||||
textField.selectable = false;
|
||||
textField.wordWrap = false;
|
||||
textField.multiline = true;
|
||||
layout.hAlign = HAlign.CENTER;
|
||||
layout.vAlign = VAlign.MIDDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.core.HAlign;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextFormat;
|
||||
@@ -7,10 +9,19 @@ import flash.text.TextFormatAlign;
|
||||
import haxework.text.BitmapTextField;
|
||||
import haxework.text.TextUtil;
|
||||
|
||||
class TextLayout {
|
||||
public var hAlign(default, default):HAlign = HAlign.NONE;
|
||||
public var vAlign(default, default):VAlign = VAlign.NONE;
|
||||
|
||||
public function new() {}
|
||||
}
|
||||
|
||||
class TextView extends SpriteView implements ITextView {
|
||||
|
||||
public var textField(default, null):TextField;
|
||||
public var text(get, set):String;
|
||||
public var layout:TextLayout;
|
||||
|
||||
private var _text:String;
|
||||
public var align(default, set):TextFormatAlign;
|
||||
public var fontFamily(default, set):String;
|
||||
@@ -28,6 +39,7 @@ class TextView extends SpriteView implements ITextView {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
layout = new TextLayout();
|
||||
textField = buildTextField();
|
||||
textField.width = 1;
|
||||
textField.height = 1;
|
||||
@@ -144,6 +156,7 @@ class TextView extends SpriteView implements ITextView {
|
||||
if (t != null) textField.text = t;
|
||||
textField.setTextFormat(textFormat);
|
||||
updateTextSize();
|
||||
placeTextField(textField);
|
||||
/*if (false && _text != null && _text.length > 0) {
|
||||
#if html5
|
||||
var h = _textHeight;
|
||||
@@ -170,23 +183,23 @@ class TextView extends SpriteView implements ITextView {
|
||||
}
|
||||
|
||||
private function placeTextField(textField:TextField):Void {
|
||||
/*textField.width = width;
|
||||
textField.height = _textHeight;
|
||||
textField.width = width;
|
||||
textField.height = geometry.size.content.height;
|
||||
|
||||
textField.x = switch (layoutHAlign) {
|
||||
textField.x = switch (layout.hAlign) {
|
||||
case HAlign.NONE: 0;
|
||||
case HAlign.LEFT: leftPadding;
|
||||
case HAlign.CENTER: (width - textField.width) / 2 + leftPadding - rightPadding;
|
||||
case HAlign.RIGHT: width - textField.width - rightPadding;
|
||||
case HAlign.LEFT: geometry.padding.left;
|
||||
case HAlign.CENTER: (width - textField.width) / 2 + geometry.padding.left - geometry.padding.right;
|
||||
case HAlign.RIGHT: width - textField.width - geometry.padding.right;
|
||||
default: 0;
|
||||
}
|
||||
textField.y = switch (layoutVAlign) {
|
||||
textField.y = switch (layout.vAlign) {
|
||||
case VAlign.NONE: 0;
|
||||
case VAlign.TOP: topPadding;
|
||||
case VAlign.MIDDLE: (height - _textHeight) / 2 + topPadding - bottomPadding;
|
||||
case VAlign.BOTTOM: height - _textHeight - bottomPadding;
|
||||
case VAlign.TOP: geometry.padding.top;
|
||||
case VAlign.MIDDLE: (height - geometry.size.content.height) / 2 + geometry.padding.top - geometry.padding.bottom;
|
||||
case VAlign.BOTTOM: height - geometry.size.content.height - geometry.padding.bottom;
|
||||
default: 0;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
override private function set_mouseEnabled(value:Bool):Bool {
|
||||
|
||||
@@ -84,7 +84,7 @@ class View<C:DisplayObject> implements IView<C> {
|
||||
}
|
||||
|
||||
private function set_width(value:Float):Float {
|
||||
trace('${this.id}.width = $value');
|
||||
//trace('${this.id}.width = $value');
|
||||
if (width != value) {
|
||||
width = value;
|
||||
toRedraw();
|
||||
@@ -93,7 +93,7 @@ class View<C:DisplayObject> implements IView<C> {
|
||||
}
|
||||
|
||||
private function set_height(value:Float):Float {
|
||||
trace('${this.id}.height = $value');
|
||||
//trace('${this.id}.height = $value');
|
||||
if (height != value) {
|
||||
height = value;
|
||||
toRedraw();
|
||||
|
||||
@@ -33,6 +33,10 @@ abstract Size(Array<Float>) {
|
||||
@:from static public inline function fromArray(value:Array<Float>):Size {
|
||||
return new Size(value);
|
||||
}
|
||||
|
||||
@:from static public inline function fromFloat(value:Float):Size {
|
||||
return new Size([value]);
|
||||
}
|
||||
}
|
||||
|
||||
enum SizeValue {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.core.Geometry.SizeValue;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.layout.HorizontalLayout;
|
||||
@@ -8,25 +9,28 @@ import haxework.gui.list.ListView.IListItemView;
|
||||
|
||||
class HListView<D> extends ListView<D> {
|
||||
|
||||
public function new() {
|
||||
super(new HorizontalLayout(), new VerticalLayout());
|
||||
//box.layoutHAlign = HAlign.LEFT;
|
||||
//box.layoutVAlign = VAlign.MIDDLE;
|
||||
}
|
||||
public function new() {
|
||||
super(new VerticalLayout(), new HorizontalLayout());
|
||||
box.layout.hAlign = HAlign.LEFT;
|
||||
box.layout.vAlign = VAlign.MIDDLE;
|
||||
}
|
||||
|
||||
override private function recalcSize(item:IListItemView<D>):Void {
|
||||
/*itemSize = item.width + item.leftMargin + item.rightMargin + box.layoutMargin;
|
||||
size = Math.ceil(Math.max(0, box.width / itemSize)) + 2;
|
||||
sizeDiff = size - ((box.width - box.layoutMargin - 1) / itemSize);*/
|
||||
}
|
||||
override private function recalcSize(item:IListItemView<D>):Void {
|
||||
var itemSize = switch(item.geometry.width) {
|
||||
case SizeValue.FIXED(value): value + item.geometry.margin.horizontal + box.layout.margin;
|
||||
case _: 0;
|
||||
}
|
||||
size = Math.ceil(Math.max(0, box.width / itemSize)) + 2;
|
||||
sizeDiff = size - ((box.width - box.layout.margin - 1) / itemSize);
|
||||
}
|
||||
|
||||
override private function set_offsetDiff(value:Float):Float {
|
||||
/*box.leftPadding = -value * itemSize;
|
||||
mask.leftMargin = -box.leftPadding;*/
|
||||
return super.set_offsetDiff(value);
|
||||
}
|
||||
override private function set_offsetDiff(value:Float):Float {
|
||||
box.geometry.padding.left = -value * itemSize;
|
||||
mask.geometry.margin.left = -box.geometry.padding.left;
|
||||
return super.set_offsetDiff(value);
|
||||
}
|
||||
|
||||
override private function onMouseWheel(value:Int):Void {
|
||||
offset = offset + value;
|
||||
}
|
||||
override private function onMouseWheel(value:Int):Void {
|
||||
offset = offset - value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ class LabelListItem<T> extends LabelView implements IListItemView<T> {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
height = 20;
|
||||
//pWidth = 100;
|
||||
geometry.size.percent.width = 100;
|
||||
geometry.size.fixed.height = 20;
|
||||
}
|
||||
private function set_data(value:T):T {
|
||||
data = value;
|
||||
|
||||
@@ -41,8 +41,8 @@ class ListView<D> extends GroupView {
|
||||
public function new(layout:ILayout, otherLayout:ILayout) {
|
||||
super(otherLayout);
|
||||
main = new GroupView(layout);
|
||||
//main.layoutHAlign = HAlign.CENTER;
|
||||
//main.layoutVAlign = VAlign.MIDDLE;
|
||||
main.layout.hAlign = HAlign.CENTER;
|
||||
main.layout.vAlign = VAlign.MIDDLE;
|
||||
main.geometry.size.stretch = true;
|
||||
addView(main);
|
||||
box = new GroupView(layout);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package haxework.gui.list;
|
||||
|
||||
import haxework.gui.core.Geometry.SizeValue;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.layout.HorizontalLayout;
|
||||
@@ -8,25 +9,28 @@ import haxework.gui.list.ListView.IListItemView;
|
||||
|
||||
class VListView<D> extends ListView<D> {
|
||||
|
||||
public function new() {
|
||||
super(new VerticalLayout(), new HorizontalLayout());
|
||||
//box.layoutHAlign = HAlign.CENTER;
|
||||
//box.layoutVAlign = VAlign.TOP;
|
||||
}
|
||||
public function new() {
|
||||
super(new VerticalLayout(), new HorizontalLayout());
|
||||
box.layout.hAlign = HAlign.CENTER;
|
||||
box.layout.vAlign = VAlign.TOP;
|
||||
}
|
||||
|
||||
override private function recalcSize(item:IListItemView<D>):Void {
|
||||
/*itemSize = item.height + item.topMargin + item.bottomMargin + box.layoutMargin;
|
||||
size = Math.ceil(Math.max(0, box.height / itemSize)) + 2;
|
||||
sizeDiff = size - ((box.height - box.layoutMargin - 1) / itemSize);*/
|
||||
}
|
||||
override private function recalcSize(item:IListItemView<D>):Void {
|
||||
var itemSize = switch(item.geometry.height) {
|
||||
case SizeValue.FIXED(value): value + item.geometry.margin.vertical + box.layout.margin;
|
||||
case _: 0;
|
||||
}
|
||||
size = Math.ceil(Math.max(0, box.height / itemSize)) + 2;
|
||||
sizeDiff = size - ((box.height - box.layout.margin - 1) / itemSize);
|
||||
}
|
||||
|
||||
override private function set_offsetDiff(value:Float):Float {
|
||||
/*box.topPadding = -value * itemSize;
|
||||
mask.topMargin = -box.topPadding;*/
|
||||
return super.set_offsetDiff(value);
|
||||
}
|
||||
override private function set_offsetDiff(value:Float):Float {
|
||||
box.geometry.padding.top = -value * itemSize;
|
||||
mask.geometry.margin.top = -box.geometry.padding.top;
|
||||
return super.set_offsetDiff(value);
|
||||
}
|
||||
|
||||
override private function onMouseWheel(value:Int):Void {
|
||||
offset = offset - value;
|
||||
}
|
||||
override private function onMouseWheel(value:Int):Void {
|
||||
offset = offset - value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,7 @@ class BitmapSkin implements ISkin<SpriteView> {
|
||||
public function draw(view:SpriteView):Void {
|
||||
if (image == null) return;
|
||||
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||
/*if (view.contentSize) {
|
||||
view.w = image.width;
|
||||
view.h = image.height;
|
||||
}*/
|
||||
view.geometry.size.content.width = image.width;
|
||||
view.geometry.size.content.height = image.height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +62,8 @@ class ButtonBitmapSkin implements ISkin<ButtonView> {
|
||||
if (images == null) return;
|
||||
var image:BitmapData = view.disabled ? disableImage == null ? disable : disableImage : images.get(view.state);
|
||||
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||
if (view.contentSize) {
|
||||
view.w = image.width;
|
||||
view.h = image.height;
|
||||
}
|
||||
view.geometry.size.content.width = image.width;
|
||||
view.geometry.size.content.height = image.height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class ResMap<T> extends StringMap<T> {
|
||||
}
|
||||
|
||||
public function put(key:String, value:T):Void {
|
||||
trace(key, value);
|
||||
set(key, value);
|
||||
if (listeners.exists(key)) {
|
||||
for (f in listeners.get(key)) call(f, value);
|
||||
|
||||
Reference in New Issue
Block a user