add image scale type

This commit is contained in:
pengfei.zhou 2019-12-21 18:48:37 +08:00
parent 65089091ec
commit 2f311f4c25

View File

@ -1,8 +1,17 @@
import { DoricViewNode, LEFT, RIGHT, CENTER_X, CENTER_Y, TOP, BOTTOM, toPixelString, toRGBAString } from "./DoricViewNode";
enum ScaleType {
ScaleToFill = 0,
ScaleAspectFit,
ScaleAspectFill,
}
export class DoricImageNode extends DoricViewNode {
build(): HTMLElement {
return document.createElement('img')
const ret = document.createElement('img')
ret.style.objectFit = "fill"
return ret
}
blendProps(v: HTMLImageElement, propName: string, prop: any) {
@ -21,6 +30,19 @@ export class DoricImageNode extends DoricViewNode {
})
}
break
case 'scaleType':
switch (prop) {
case ScaleType.ScaleToFill:
v.style.objectFit = "fill"
break
case ScaleType.ScaleAspectFit:
v.style.objectFit = "contain"
break
case ScaleType.ScaleAspectFill:
v.style.objectFit = "cover"
break
}
break
default:
super.blendProps(v, propName, prop)
break