laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
60 lines (59 loc) • 2.04 kB
JavaScript
import { HTMLElement, HTMLElementType } from "./HTMLElement";
import { Event } from "../../events/Event";
import { Loader } from "../../net/Loader";
import { Texture } from "../../resource/Texture";
import { IHtml } from "../utils/IHtml";
export class HTMLImageElement extends HTMLElement {
constructor() {
super();
this.eletype = HTMLElementType.IMAGE;
}
reset() {
super.reset();
if (this._tex) {
this._tex.off(Event.LOADED, this, this.onloaded);
}
this._tex = null;
this._url = null;
return this;
}
set src(url) {
url = this.formatURL(url);
if (this._url === url)
return;
this._url = url;
var tex = this._tex = Loader.getRes(url);
if (!tex) {
this._tex = tex = new Texture();
tex.load(url);
Loader.cacheTexture(url, tex);
}
tex.getIsReady() ? this.onloaded() : tex.once(Event.READY, this, this.onloaded);
}
onloaded() {
if (!this._style)
return;
var style = this._style;
var w = style.widthed(this) ? -1 : this._tex.width;
var h = style.heighted(this) ? -1 : this._tex.height;
if (!style.widthed(this) && this._width != this._tex.width) {
this.width = this._tex.width;
this.parent && this.parent._layoutLater();
}
if (!style.heighted(this) && this._height != this._tex.height) {
this.height = this._tex.height;
this.parent && this.parent._layoutLater();
}
this.repaint();
}
_addToLayout(out) {
var style = this._style;
!style.absolute && out.push(this);
}
renderSelfToGraphic(graphic, gX, gY, recList) {
if (!this._tex)
return;
graphic.drawImage(this._tex, gX, gY, this.width || this._tex.width, this.height || this._tex.height);
}
}
IHtml.HTMLImageElement = HTMLImageElement;