/** * Created by W.X. on 2016/11/18. */ import * as React from "react"; import {observer} from "mobx-react/index"; import {autobind} from "core-decorators"; import {Unit} from "../../../../drawing/Unit"; import Editor from "../Editor"; import {Position} from "../../../../items/properties/classes/Position"; import {SpinnerComponent} from "../_components/SpinnerComponent"; import {CommonProperty} from "../../../../items/properties/define"; import {DesignerHost} from "../../../DesignerHost"; @observer export class PositionEditor extends Editor { private _mergeLeftNull: boolean = false; private _mergeTopNull: boolean = false; getValue(){ const {items} = this.props; const firstItemLeft = items[0].left; const firstItemTop = items[0].top; this._mergeLeftNull = false; this._mergeTopNull = false; items.map((item) => { if(item.left.toPixel() !== firstItemLeft.toPixel()){ this._mergeLeftNull = true; } if(item.top.toPixel() !== firstItemTop.toPixel()){ this._mergeTopNull = true; } }); return new Position( this._mergeLeftNull ? new Unit(0) : firstItemLeft, this._mergeTopNull ? new Unit(0) : firstItemTop ); } renderValueEditor() { const position: Position = this.getValue(); return (
{CommonProperty.x.label}
{CommonProperty.y.label}
); } @autobind onChangeX(value: Unit) { console.log(value); this.changeValue('x', value); } @autobind onChangeY(value: Unit) { this.changeValue('y', value); } changeValue(type: string, value: Unit) { const {items} = this.props; const position: Position = this.getValue(); const newPosition = position ? position.clone() : new Position(); newPosition[type] = value; items.map((item) => { item.setPropertyValue(CommonProperty[type], newPosition[type]); //如果父容器是band, 则要自动撑开父容器 const parent = item.parent; const parentTypeName = parent.constructor.name; if(parentTypeName.indexOf('Band')> -1){ const parentDesigner = DesignerHost.instance().getDesigner(parent); parentDesigner.updateMinBounds(); } }); this.setValue(newPosition); } }