diff options
author | bobzel <zzzman@gmail.com> | 2020-12-12 18:38:04 -0500 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2020-12-12 18:38:04 -0500 |
commit | 0aa855ab36ead1e4669f25e2a3604e8941cf2075 (patch) | |
tree | 0ca7ebff6ec6f5bafaf28270f52223f9523ea22a /src/client/views/nodes/ContentFittingDocumentView.tsx | |
parent | f3f93e61f3914bd9fd6e8098a99e552f7860bc5f (diff) |
fixed screenToLocal for documents within ContentFittingDoc collections. fixed embedding documents in texst docs.
Diffstat (limited to 'src/client/views/nodes/ContentFittingDocumentView.tsx')
-rw-r--r-- | src/client/views/nodes/ContentFittingDocumentView.tsx | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/client/views/nodes/ContentFittingDocumentView.tsx b/src/client/views/nodes/ContentFittingDocumentView.tsx index e632f0e19..fed857c83 100644 --- a/src/client/views/nodes/ContentFittingDocumentView.tsx +++ b/src/client/views/nodes/ContentFittingDocumentView.tsx @@ -1,12 +1,13 @@ import React = require("react"); import { computed, observable, action } from "mobx"; import { observer } from "mobx-react"; -import { Doc } from "../../../fields/Doc"; +import { Doc, WidthSym, HeightSym } from "../../../fields/Doc"; import { TraceMobx } from "../../../fields/util"; import { emptyFunction, OmitKeys, returnVal, returnOne } from "../../../Utils"; import { DocumentView, DocumentViewProps } from "../nodes/DocumentView"; import "./ContentFittingDocumentView.scss"; import { StyleProp } from "../StyleProvider"; +import { StrCast } from "../../../fields/Types"; interface ContentFittingDocumentViewProps { dontCenter?: "x" | "y" | "xy"; @@ -39,8 +40,18 @@ export class ContentFittingDocumentView extends React.Component<DocumentViewProp return this.props.PanelHeight(); } + contentFittingScaling = () => { + if (this.props.DataDoc) return 1; // this is intended to detect when a document is being rendered inside itself as part of a template, but not as a leaf node where nativeWidth & height would apply. + const layoutStr = (this.props.LayoutTemplateString || StrCast(this.layoutDoc.layout)); + if (this.nativeWidth || layoutStr.includes("FormattedTextBox")) return this.nativeScaling; + + const wscale = this.layoutDoc[WidthSym]() / this.props.PanelWidth(); + const hscale = this.layoutDoc[HeightSym]() / this.props.PanelHeight(); + return this.nativeScaling * Math.max(wscale, hscale); + } + private getTransform = () => this.props.ScreenToLocalTransform(). - translate(this.props.dontCenter?.includes("x") ? 0 : -this.centeringOffset, this.props.dontCenter?.includes("y") ? 0 : -this.centeringYOffset) + translate(this.props.dontCenter?.includes("x") ? 0 : -this.centeringOffset, this.props.dontCenter?.includes("y") ? 0 : -this.centeringYOffset).scale(1 / this.contentFittingScaling()) private get centeringOffset() { return this.nativeWidth && !this.props.Document._fitWidth ? (this.props.PanelWidth() - this.nativeWidth * this.nativeScaling) / 2 : 0; } private get centeringYOffset() { return this.nativeWidth && Math.abs(this.centeringOffset) < 0.001 && this.nativeHeight ? (this.props.PanelHeight() - this.nativeHeight * this.nativeScaling) / 2 : 0; } @@ -64,6 +75,7 @@ export class ContentFittingDocumentView extends React.Component<DocumentViewProp PanelWidth={this.PanelWidth} PanelHeight={this.PanelHeight} ContentScaling={returnOne} + contentFittingScaling={this.contentFittingScaling} ScreenToLocalTransform={this.getTransform} focus={this.props.focus || emptyFunction} bringToFront={emptyFunction} |