laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
172 lines (171 loc) • 5.84 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.View = void 0;
const Widget_1 = require("./Widget");
const Animation_1 = require("../display/Animation");
const Scene_1 = require("../display/Scene");
const Text_1 = require("../display/Text");
const Event_1 = require("../events/Event");
const Box_1 = require("./Box");
const Button_1 = require("./Button");
const CheckBox_1 = require("./CheckBox");
const Image_1 = require("./Image");
const Label_1 = require("./Label");
const ProgressBar_1 = require("./ProgressBar");
const Radio_1 = require("./Radio");
const RadioGroup_1 = require("./RadioGroup");
const Tab_1 = require("./Tab");
const UIComponent_1 = require("./UIComponent");
const ViewStack_1 = require("./ViewStack");
const TextArea_1 = require("./TextArea");
const ColorPicker_1 = require("./ColorPicker");
const ScaleBox_1 = require("./ScaleBox");
const Clip_1 = require("./Clip");
const ComboBox_1 = require("./ComboBox");
const HScrollBar_1 = require("./HScrollBar");
const HSlider_1 = require("./HSlider");
const List_1 = require("./List");
const Panel_1 = require("./Panel");
const ScrollBar_1 = require("./ScrollBar");
const Slider_1 = require("./Slider");
const TextInput_1 = require("./TextInput");
const VScrollBar_1 = require("./VScrollBar");
const VSlider_1 = require("./VSlider");
const Tree_1 = require("./Tree");
const HBox_1 = require("./HBox");
const VBox_1 = require("./VBox");
const FontClip_1 = require("./FontClip");
const ILaya_1 = require("../../ILaya");
class View extends Scene_1.Scene {
static __init__() {
ILaya_1.ILaya.ClassUtils.regShortClassName([ViewStack_1.ViewStack, Button_1.Button, TextArea_1.TextArea, ColorPicker_1.ColorPicker, Box_1.Box, ScaleBox_1.ScaleBox, CheckBox_1.CheckBox, Clip_1.Clip, ComboBox_1.ComboBox, UIComponent_1.UIComponent,
HScrollBar_1.HScrollBar, HSlider_1.HSlider, Image_1.Image, Label_1.Label, List_1.List, Panel_1.Panel, ProgressBar_1.ProgressBar, Radio_1.Radio, RadioGroup_1.RadioGroup, ScrollBar_1.ScrollBar, Slider_1.Slider, Tab_1.Tab, TextInput_1.TextInput, View,
VScrollBar_1.VScrollBar, VSlider_1.VSlider, Tree_1.Tree, HBox_1.HBox, VBox_1.VBox, Animation_1.Animation, Text_1.Text, FontClip_1.FontClip]);
}
constructor() {
super(false);
this._watchMap = {};
this._anchorX = NaN;
this._anchorY = NaN;
this._widget = Widget_1.Widget.EMPTY;
this.createChildren();
}
static regComponent(key, compClass) {
ILaya_1.ILaya.ClassUtils.regClass(key, compClass);
}
static regViewRuntime(key, compClass) {
ILaya_1.ILaya.ClassUtils.regClass(key, compClass);
}
static regUI(url, json) {
ILaya_1.ILaya.loader.cacheRes(url, json);
}
destroy(destroyChild = true) {
this._watchMap = null;
super.destroy(destroyChild);
}
changeData(key) {
var arr = this._watchMap[key];
if (!arr)
return;
for (var i = 0, n = arr.length; i < n; i++) {
var watcher = arr[i];
watcher.exe(this);
}
}
get top() {
return this._widget.top;
}
set top(value) {
if (value != this._widget.top) {
this._getWidget().top = value;
}
}
get bottom() {
return this._widget.bottom;
}
set bottom(value) {
if (value != this._widget.bottom) {
this._getWidget().bottom = value;
}
}
get left() {
return this._widget.left;
}
set left(value) {
if (value != this._widget.left) {
this._getWidget().left = value;
}
}
get right() {
return this._widget.right;
}
set right(value) {
if (value != this._widget.right) {
this._getWidget().right = value;
}
}
get centerX() {
return this._widget.centerX;
}
set centerX(value) {
if (value != this._widget.centerX) {
this._getWidget().centerX = value;
}
}
get centerY() {
return this._widget.centerY;
}
set centerY(value) {
if (value != this._widget.centerY) {
this._getWidget().centerY = value;
}
}
get anchorX() {
return this._anchorX;
}
set anchorX(value) {
if (this._anchorX != value) {
this._anchorX = value;
this.callLater(this._sizeChanged);
}
}
get anchorY() {
return this._anchorY;
}
set anchorY(value) {
if (this._anchorY != value) {
this._anchorY = value;
this.callLater(this._sizeChanged);
}
}
_sizeChanged() {
if (!isNaN(this._anchorX))
this.pivotX = this.anchorX * this.width;
if (!isNaN(this._anchorY))
this.pivotY = this.anchorY * this.height;
this.event(Event_1.Event.RESIZE);
}
_getWidget() {
this._widget === Widget_1.Widget.EMPTY && (this._widget = this.addComponent(Widget_1.Widget));
return this._widget;
}
loadUI(path) {
var uiView = View.uiMap[path];
View.uiMap && this.createView(uiView);
}
get dataSource() {
return this._dataSource;
}
set dataSource(value) {
this._dataSource = value;
for (var name in value) {
var comp = this.getChildByName(name);
if (comp instanceof UIComponent_1.UIComponent)
comp.dataSource = value[name];
else if (name in this && !(this[name] instanceof Function))
this[name] = value[name];
}
}
}
exports.View = View;
View.uiMap = {};