laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
166 lines (165 loc) • 4.73 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextInput = void 0;
const Label_1 = require("./Label");
const Input_1 = require("../display/Input");
const Event_1 = require("../events/Event");
const Loader_1 = require("../net/Loader");
const AutoBitmap_1 = require("./AutoBitmap");
const Styles_1 = require("./Styles");
const UIUtils_1 = require("./UIUtils");
const Handler_1 = require("../utils/Handler");
const ILaya_1 = require("../../ILaya");
class TextInput extends Label_1.Label {
constructor(text = "") {
super();
this.text = text;
this.skin = this.skin;
}
preinitialize() {
this.mouseEnabled = true;
}
destroy(destroyChild = true) {
super.destroy(destroyChild);
this._bg && this._bg.destroy();
this._bg = null;
}
createChildren() {
this.addChild(this._tf = new Input_1.Input());
this._tf.padding = Styles_1.Styles.inputLabelPadding;
this._tf.on(Event_1.Event.INPUT, this, this._onInput);
this._tf.on(Event_1.Event.ENTER, this, this._onEnter);
this._tf.on(Event_1.Event.BLUR, this, this._onBlur);
this._tf.on(Event_1.Event.FOCUS, this, this._onFocus);
}
_onFocus() {
this.event(Event_1.Event.FOCUS, this);
}
_onBlur() {
this.event(Event_1.Event.BLUR, this);
}
_onInput() {
this.event(Event_1.Event.INPUT, this);
}
_onEnter() {
this.event(Event_1.Event.ENTER, this);
}
initialize() {
this.width = 128;
this.height = 22;
}
get bg() {
return this._bg;
}
set bg(value) {
this.graphics = this._bg = value;
}
get skin() {
return this._skin;
}
set skin(value) {
if (this._skin != value) {
this._skin = value;
if (this._skin && !Loader_1.Loader.getRes(this._skin)) {
ILaya_1.ILaya.loader.load(this._skin, Handler_1.Handler.create(this, this._skinLoaded), null, Loader_1.Loader.IMAGE, 1);
}
else {
this._skinLoaded();
}
}
}
_skinLoaded() {
this._bg || (this.graphics = this._bg = new AutoBitmap_1.AutoBitmap());
this._bg.source = Loader_1.Loader.getRes(this._skin);
this._width && (this._bg.width = this._width);
this._height && (this._bg.height = this._height);
this._sizeChanged();
this.event(Event_1.Event.LOADED);
}
get sizeGrid() {
return this._bg && this._bg.sizeGrid ? this._bg.sizeGrid.join(",") : null;
}
set sizeGrid(value) {
this._bg || (this.graphics = this._bg = new AutoBitmap_1.AutoBitmap());
this._bg.sizeGrid = UIUtils_1.UIUtils.fillArray(Styles_1.Styles.defaultSizeGrid, value, Number);
}
set text(value) {
if (this._tf.text != value) {
value = value + "";
this._tf.text = value;
this.event(Event_1.Event.CHANGE);
}
}
get text() {
return super.text;
}
set width(value) {
super.width = value;
this._bg && (this._bg.width = value);
}
get width() {
return super.width;
}
set height(value) {
super.height = value;
this._bg && (this._bg.height = value);
}
get height() {
return super.height;
}
get multiline() {
return this._tf.multiline;
}
set multiline(value) {
this._tf.multiline = value;
}
set editable(value) {
this._tf.editable = value;
}
get editable() {
return this._tf.editable;
}
select() {
this._tf.select();
}
get restrict() {
return this._tf.restrict;
}
set restrict(pattern) {
this._tf.restrict = pattern;
}
get prompt() {
return this._tf.prompt;
}
set prompt(value) {
this._tf.prompt = value;
}
get promptColor() {
return this._tf.promptColor;
}
set promptColor(value) {
this._tf.promptColor = value;
}
get maxChars() {
return this._tf.maxChars;
}
set maxChars(value) {
this._tf.maxChars = value;
}
get focus() {
return this._tf.focus;
}
set focus(value) {
this._tf.focus = value;
}
get type() {
return this._tf.type;
}
set type(value) {
this._tf.type = value;
}
setSelection(startIndex, endIndex) {
this._tf.setSelection(startIndex, endIndex);
}
}
exports.TextInput = TextInput;