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 | |
parent | f3f93e61f3914bd9fd6e8098a99e552f7860bc5f (diff) |
fixed screenToLocal for documents within ContentFittingDoc collections. fixed embedding documents in texst docs.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/DocumentDecorations.tsx | 2 | ||||
-rw-r--r-- | src/client/views/nodes/ContentFittingDocumentView.tsx | 16 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 2 | ||||
-rw-r--r-- | src/client/views/nodes/formattedText/RichTextSchema.tsx | 3 |
4 files changed, 19 insertions, 4 deletions
diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx index 9e81e108e..d3b83352e 100644 --- a/src/client/views/DocumentDecorations.tsx +++ b/src/client/views/DocumentDecorations.tsx @@ -69,7 +69,7 @@ export class DocumentDecorations extends React.Component<{ boundsLeft: number, b Doc.AreProtosEqual(documentView.props.Document, Doc.UserDoc())) { return bounds; } - const transform = (documentView.props.ScreenToLocalTransform().scale(documentView.props.ContentScaling())).inverse(); + const transform = (documentView.props.ScreenToLocalTransform().scale(documentView.LocalScaling)).inverse(); var [sptX, sptY] = transform.transformPoint(0, 0); let [bptX, bptY] = transform.transformPoint(documentView.props.PanelWidth(), documentView.props.PanelHeight()); if (documentView.props.LayoutTemplateString?.includes("LinkAnchorBox")) { 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} diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 1b1870f81..97937e3e0 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -93,6 +93,7 @@ export interface DocumentViewProps extends DocumentViewSharedProps { dragDivName?: string; contentPointerEvents?: string; radialMenu?: String[]; + contentFittingScaling?: () => number; LayoutTemplate?: () => Opt<Doc>; contextMenuItems?: () => { script: ScriptField, label: string }[]; onDoubleClick?: () => ScriptField; @@ -128,6 +129,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu (this.dataDoc.author === Doc.CurrentUserEmail ? StrCast(Doc.UserDoc().showTitle) : "author;creationDate") : undefined); } + @computed get LocalScaling() { return this.props.ContentScaling() * (this.props.contentFittingScaling?.() || 1); } @computed get topMost() { return this.props.renderDepth === 0; } @computed get freezeDimensions() { return this.props.freezeDimensions; } @computed get nativeWidth() { return returnVal(this.props.NativeWidth?.(), Doc.NativeWidth(this.layoutDoc, this.dataDoc, this.freezeDimensions)); } diff --git a/src/client/views/nodes/formattedText/RichTextSchema.tsx b/src/client/views/nodes/formattedText/RichTextSchema.tsx index bb544e5e8..e94829769 100644 --- a/src/client/views/nodes/formattedText/RichTextSchema.tsx +++ b/src/client/views/nodes/formattedText/RichTextSchema.tsx @@ -14,6 +14,7 @@ import { DocumentView } from "../DocumentView"; import { FormattedTextBox } from "./FormattedTextBox"; import React = require("react"); import { CurrentUserUtils } from "../../../util/CurrentUserUtils"; +import { DefaultStyleProvider } from "../../StyleProvider"; export class DashDocView { @@ -147,7 +148,7 @@ export class DashDocView { PanelWidth={finalLayout[WidthSym]} PanelHeight={finalLayout[HeightSym]} focus={this.outerFocus} - styleProvider={returnEmptyString} + styleProvider={DefaultStyleProvider} parentActive={returnFalse} whenActiveChanged={returnFalse} bringToFront={emptyFunction} |