import * as React from "react"; import {Unit, RectUnit} from "../drawing/Unit"; import {ReportBandBase} from "../items/band/ReportBandBase"; import {ParentItemDesignerBase} from "./designer/ParentItemDesignerBase"; import {SelectionRules} from "./behavior/Enums"; import {ReportItemBaseDesigner} from "./designer/ReportItemBaseDesigner"; import {RectF, SizeF} from "../drawing/Unit"; import {DesignerHost} from "./DesignerHost"; import {SnapLine, SnapLineType, SnapLinePriority} from "./behavior/SnapLine"; import {ItemBodyGlyph} from "./behavior/ItemBodyGlyph"; import {Cursor} from "../drawing/Cursor"; import {GroupObjectPool, TextObjectPool} from "../drawing/KonvaObjectPools"; export abstract class BandDesignerBase extends ParentItemDesignerBase { private _x = Unit.Zero; private _y = Unit.Zero; get band():ReportBandBase { return this.item as ReportBandBase; } get leftPadding(): Unit{ return this.band.leftPadding; } get topPadding(): Unit{ return this.band.topPadding; } get x():Unit { return this._x; } set x(value:Unit) { this._x = value; } get y():Unit { return this._y; } set y(value:Unit) { this._y = value; } get height():Unit { return this.band.height; } get width():Unit { return this.reportDesigner.report.bandWidth; } get bounds():RectUnit { const width = this.width; // return new RectUnit(new Unit(this.x.pixels+this.leftPadding.pixels), new Unit(this.y.pixels+this.topPadding.pixels), width, this.height); return new RectUnit(this.leftPadding, new Unit(this.y.pixels+this.topPadding.pixels), width, this.height); } get selectionRules():SelectionRules { return (SelectionRules.Visible | SelectionRules.BottomSizeable | SelectionRules.RightSizeable); } private innerCalculateAllowedShrinkSize(): SizeF { return super.calculateAllowedShrinkSize(); } calculateAllowedShrinkSize(): SizeF { const size = super.calculateAllowedShrinkSize(); for (let band of this.reportObject.report.items) { const designer = DesignerHost.instance().getDesigner(band); if (designer && designer !== this) { const minSize = designer.innerCalculateAllowedShrinkSize(); size.width = Math.max(size.width, minSize.width); } } return size; } protected getSnapLines(): Array { const snapLines:Array = super.getSnapLines(); const bounds = this.getBounds(); // MarginsU margins = this.Item.Margins; const zoom = this.behaviorService.zoom; const margins = { Left: Unit.Zero, Top: Unit.Zero, Right: Unit.Zero, Bottom: Unit.Zero, }; snapLines.push(new SnapLine(SnapLineType.HorizontalMiddle, bounds.top + bounds.height / 2.0, SnapLinePriority.Medium, SnapLine.MiddleHorizontal)); snapLines.push(new SnapLine(SnapLineType.VerticalMiddle, bounds.left + bounds.width / 2.0, SnapLinePriority.Medium, SnapLine.MiddleVertical)); return snapLines; } protected getDefaultItemBodyGlyph(): ItemBodyGlyph { return new ReportBandGlyph(this, Cursor.Default, this.defaultBehavior); } render(bounds:RectF):any { const item = this.band; const text = item.displayName(); const fontSize = 24; const paddingTop = 0; const paddingLeft = 0; const paddingRight = 0; const paddingBottom = 0; const clipWidth = bounds.width - paddingLeft - paddingRight; const clipHeight = bounds.height - paddingTop - paddingBottom; const textHeight = ReportItemBaseDesigner.calculateTextHeight(text, fontSize, clipWidth); const rootProps = { x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, clipX: 0, clipY: paddingTop, clipWidth: bounds.width, clipHeight: clipHeight, }; const props = { x: 0, y: Math.max(paddingTop, paddingTop + (clipHeight - textHeight) / 2), text: text, fontSize: fontSize, fill: "#ECE4E4", width: bounds.width, align: "center", }; const groupNode = GroupObjectPool.get(rootProps); const clipBounds = bounds.clone(); clipBounds.x = 0; clipBounds.y = 0; groupNode.add(TextObjectPool.get(props)); return groupNode; } } export class ReportBandGlyph extends ItemBodyGlyph { render(parentNode) { parentNode.add(this.designer.render(this.bounds)); } }