[view] rename from gui

This commit is contained in:
2019-03-25 16:24:57 +03:00
parent ad504de290
commit 22e7894c03
77 changed files with 202 additions and 203 deletions

View File

@@ -0,0 +1,80 @@
package haxework.view;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import haxework.signal.Signal;
class InputView extends TextView {
public var hint(default, set):String;
public var onChange(default, null):Signal<String> = new Signal();
private var hintTextField:TextField;
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;
toUpdate();
}
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;
}
private function onTextChange(event:Event):Void {
hintTextField.visible = (textField.text == "");
}
private function _onKeyUp(event:KeyboardEvent):Void {
event.stopImmediatePropagation();
onChange.emit(textField.text);
}
private function onKeyDown(event:KeyboardEvent):Void {
event.stopImmediatePropagation();
}
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);
}
}