aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-02-23 22:36:52 -0500
committerbobzel <zzzman@gmail.com>2021-02-23 22:36:52 -0500
commit2cddc1cd6012a1c71c919124f640ce1d04593ec8 (patch)
tree3b40aa29a9e4f722c44979a62413212bb9355402 /src
parent953e9dacf886aa5dff7331ca1f7ba7ba7f5373dd (diff)
removed _renderContentBounds and updated miniMap view.
Diffstat (limited to 'src')
-rw-r--r--src/client/views/collections/TabDocView.tsx186
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx10
-rw-r--r--src/client/views/nodes/DocumentView.tsx2
3 files changed, 105 insertions, 93 deletions
diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx
index c1a1a6f04..c7eb9ef48 100644
--- a/src/client/views/collections/TabDocView.tsx
+++ b/src/client/views/collections/TabDocView.tsx
@@ -9,7 +9,6 @@ import * as ReactDOM from 'react-dom';
import { DataSym, Doc, DocListCast, DocListCastAsync, HeightSym, Opt, WidthSym } from "../../../fields/Doc";
import { Id } from '../../../fields/FieldSymbols';
import { FieldId } from "../../../fields/RefField";
-import { listSpec } from '../../../fields/Schema';
import { Cast, NumCast, StrCast } from "../../../fields/Types";
import { TraceMobx } from '../../../fields/util';
import { emptyFunction, returnEmptyDoclist, returnFalse, returnTrue, setupMoveUpEvents, Utils } from "../../../Utils";
@@ -55,13 +54,7 @@ export class TabDocView extends React.Component<TabDocViewProps> {
@computed get layoutDoc() { return this._document && Doc.Layout(this._document); }
@computed get tabColor() { return StrCast(this._document?._backgroundColor, StrCast(this._document?.backgroundColor, DefaultStyleProvider(this._document, undefined, StyleProp.BackgroundColor))); }
- @computed get renderBounds() {
- const bounds = this._document ? Cast(this._document._renderContentBounds, listSpec("number"), [0, 0, this.returnMiniSize(), this.returnMiniSize()]) : [0, 0, 0, 0];
- const xbounds = bounds[2] - bounds[0];
- const ybounds = bounds[3] - bounds[1];
- const dim = Math.max(xbounds, ybounds);
- return { l: bounds[0] + xbounds / 2 - dim / 2, t: bounds[1] + ybounds / 2 - dim / 2, cx: bounds[0] + xbounds / 2, cy: bounds[1] + ybounds / 2, dim };
- }
+
get stack() { return (this.props as any).glContainer.parent.parent; }
get tab() { return (this.props as any).glContainer.tab; }
@@ -290,76 +283,9 @@ export class TabDocView extends React.Component<TabDocViewProps> {
}
}
- childLayoutTemplate = () => Cast(this._document?.childLayoutTemplate, Doc, null);
- returnMiniSize = () => NumCast(this._document?._miniMapSize, 150);
- miniDown = (e: React.PointerEvent) => {
- const doc = this._document;
- const miniSize = this.returnMiniSize();
- doc && setupMoveUpEvents(this, e, action((e: PointerEvent, down: number[], delta: number[]) => {
- doc._panX = clamp(NumCast(doc._panX) + delta[0] / miniSize * this.renderBounds.dim, this.renderBounds.l, this.renderBounds.l + this.renderBounds.dim);
- doc._panY = clamp(NumCast(doc._panY) + delta[1] / miniSize * this.renderBounds.dim, this.renderBounds.t, this.renderBounds.t + this.renderBounds.dim);
- return false;
- }), emptyFunction, emptyFunction);
- }
getCurrentFrame = () => {
return NumCast(Cast(PresBox.Instance.childDocs[PresBox.Instance.itemIndex].presentationTargetDoc, Doc, null)._currentFrame);
}
- renderMiniMap() {
- const miniWidth = this.PanelWidth() / NumCast(this._document?._viewScale, 1) / this.renderBounds.dim * 100;
- const miniHeight = this.PanelHeight() / NumCast(this._document?._viewScale, 1) / this.renderBounds.dim * 100;
- const miniLeft = 50 + (NumCast(this._document?._panX) - this.renderBounds.cx) / this.renderBounds.dim * 100 - miniWidth / 2;
- const miniTop = 50 + (NumCast(this._document?._panY) - this.renderBounds.cy) / this.renderBounds.dim * 100 - miniHeight / 2;
- const miniSize = this.returnMiniSize();
- return <>
- <div className="miniMap" style={{ width: miniSize, height: miniSize, background: this.tabColor }}>
- <CollectionFreeFormView
- Document={this._document!}
- CollectionView={undefined}
- ContainingCollectionView={undefined}
- ContainingCollectionDoc={undefined}
- parentActive={returnFalse}
- docViewPath={returnEmptyDoclist}
- childLayoutTemplate={this.childLayoutTemplate} // bcz: Ugh .. should probably be rendering a CollectionView or the minimap should be part of the collectionFreeFormView to avoid having to set stuff like this.
- noOverlay={true} // don't render overlay Docs since they won't scale
- active={returnTrue}
- select={emptyFunction}
- dropAction={undefined}
- isSelected={returnFalse}
- dontRegisterView={true}
- fieldKey={Doc.LayoutFieldKey(this._document!)}
- bringToFront={emptyFunction}
- rootSelected={returnTrue}
- addDocument={returnFalse}
- moveDocument={returnFalse}
- removeDocument={returnFalse}
- PanelWidth={this.returnMiniSize}
- PanelHeight={this.returnMiniSize}
- ScreenToLocalTransform={Transform.Identity}
- renderDepth={0}
- whenActiveChanged={emptyFunction}
- focus={DocUtils.DefaultFocus}
- styleProvider={TabDocView.miniStyleProvider}
- layerProvider={undefined}
- addDocTab={this.addDocTab}
- pinToPres={TabDocView.PinDoc}
- docFilters={CollectionDockingView.Instance.docFilters}
- docRangeFilters={CollectionDockingView.Instance.docRangeFilters}
- searchFilterDocs={CollectionDockingView.Instance.searchFilterDocs}
- fitContentsToDoc={returnTrue}
- />
- <div className="miniOverlay" onPointerDown={this.miniDown} >
- <div className="miniThumb" style={{ width: `${miniWidth}% `, height: `${miniHeight}% `, left: `${miniLeft}% `, top: `${miniTop}% `, }} />
- </div>
- </div>
-
- <Tooltip title={<div className="dash-tooltip">{"toggle minimap"}</div>}>
- <div className="miniMap-hidden" onPointerDown={e => e.stopPropagation()} onClick={action(e => { e.stopPropagation(); this._document!.hideMinimap = !this._document!.hideMinimap; })}
- style={{ background: DefaultStyleProvider(this._document, undefined, StyleProp.BackgroundColor) }} >
- <FontAwesomeIcon icon={"globe-asia"} size="lg" />
- </div>
- </Tooltip>
- </>;
- }
@action
focusFunc = (doc: Doc, options?: DocFocusOptions) => {
const vals = (!options?.originalTarget || options?.originalTarget === this._document) && this.view?.ComponentView?.freeformData?.(true);
@@ -402,6 +328,10 @@ export class TabDocView extends React.Component<TabDocViewProps> {
}
}
}
+ miniMapColor = () => this.tabColor;
+ miniPanelWidth = () => this.PanelWidth();
+ miniPanelHeight = () => this.PanelHeight();
+ tabView = () => this._view;
@computed get layerProvider() { return this._document && DefaultLayerProvider(this._document); }
@computed get docView() {
TraceMobx();
@@ -431,14 +361,18 @@ export class TabDocView extends React.Component<TabDocViewProps> {
docViewPath={returnEmptyDoclist}
bringToFront={emptyFunction}
pinToPres={TabDocView.PinDoc} />
- {this._document._viewType !== CollectionViewType.Freeform ? (null) :
- <>{this._document.hideMinimap ? (null) : this.renderMiniMap()}
- <Tooltip key="ttip" title={<div className="dash-tooltip">{"toggle minimap"}</div>}>
- <div className="miniMap-hidden" onPointerDown={e => e.stopPropagation()} onClick={action(e => { e.stopPropagation(); this._document!.hideMinimap = !this._document!.hideMinimap; })} >
- <FontAwesomeIcon icon={"globe-asia"} size="lg" />
- </div>
- </Tooltip>
- </>}
+ <TabMinimapView key="minimap"
+ addDocTab={this.addDocTab}
+ PanelHeight={this.miniPanelHeight}
+ PanelWidth={this.miniPanelWidth}
+ background={this.miniMapColor}
+ document={this._document}
+ tabView={this.tabView} />
+ <Tooltip key="ttip" title={<div className="dash-tooltip">{"toggle minimap"}</div>}>
+ <div className="miniMap-hidden" onPointerDown={e => e.stopPropagation()} onClick={action(e => { e.stopPropagation(); this._document!.hideMinimap = !this._document!.hideMinimap; })} >
+ <FontAwesomeIcon icon={"globe-asia"} size="lg" />
+ </div>
+ </Tooltip>
</>;
}
@@ -454,4 +388,90 @@ export class TabDocView extends React.Component<TabDocViewProps> {
</div >
);
}
+}
+
+interface TabMinimapViewProps {
+ document: Doc;
+ tabView: () => DocumentView | undefined;
+ addDocTab: (doc: Doc, where: string) => boolean;
+ PanelWidth: () => number;
+ PanelHeight: () => number;
+ background: () => string;
+}
+@observer
+export class TabMinimapView extends React.Component<TabMinimapViewProps> {
+ @computed get renderBounds() {
+ const bounds = this.props.tabView()?.ComponentView?.freeformData?.()?.bounds ?? { x: 0, y: 0, r: this.returnMiniSize(), b: this.returnMiniSize() };
+ const xbounds = bounds.r - bounds.x;
+ const ybounds = bounds.b - bounds.y;
+ const dim = Math.max(xbounds, ybounds);
+ return { l: bounds.x + xbounds / 2 - dim / 2, t: bounds.y + ybounds / 2 - dim / 2, cx: bounds.x + xbounds / 2, cy: bounds.y + ybounds / 2, dim };
+ }
+ childLayoutTemplate = () => Cast(this.props.document.childLayoutTemplate, Doc, null);
+ returnMiniSize = () => NumCast(this.props.document._miniMapSize, 150);
+ miniDown = (e: React.PointerEvent) => {
+ const doc = this.props.document;
+ const miniSize = this.returnMiniSize();
+ doc && setupMoveUpEvents(this, e, action((e: PointerEvent, down: number[], delta: number[]) => {
+ doc._panX = clamp(NumCast(doc._panX) + delta[0] / miniSize * this.renderBounds.dim, this.renderBounds.l, this.renderBounds.l + this.renderBounds.dim);
+ doc._panY = clamp(NumCast(doc._panY) + delta[1] / miniSize * this.renderBounds.dim, this.renderBounds.t, this.renderBounds.t + this.renderBounds.dim);
+ return false;
+ }), emptyFunction, emptyFunction);
+ }
+ render() {
+ const miniWidth = this.props.PanelWidth() / NumCast(this.props.document._viewScale, 1) / this.renderBounds.dim * 100;
+ const miniHeight = this.props.PanelHeight() / NumCast(this.props.document._viewScale, 1) / this.renderBounds.dim * 100;
+ const miniLeft = 50 + (NumCast(this.props.document._panX) - this.renderBounds.cx) / this.renderBounds.dim * 100 - miniWidth / 2;
+ const miniTop = 50 + (NumCast(this.props.document._panY) - this.renderBounds.cy) / this.renderBounds.dim * 100 - miniHeight / 2;
+ const miniSize = this.returnMiniSize();
+ return this.props.document._viewType !== CollectionViewType.Freeform || this.props.document.hideMinimap ? (null) : <>
+ <div className="miniMap" style={{ width: miniSize, height: miniSize, background: this.props.background() }}>
+ <CollectionFreeFormView
+ Document={this.props.document}
+ CollectionView={undefined}
+ ContainingCollectionView={undefined}
+ ContainingCollectionDoc={undefined}
+ parentActive={returnFalse}
+ docViewPath={returnEmptyDoclist}
+ childLayoutTemplate={this.childLayoutTemplate} // bcz: Ugh .. should probably be rendering a CollectionView or the minimap should be part of the collectionFreeFormView to avoid having to set stuff like this.
+ noOverlay={true} // don't render overlay Docs since they won't scale
+ active={returnTrue}
+ select={emptyFunction}
+ dropAction={undefined}
+ isSelected={returnFalse}
+ dontRegisterView={true}
+ fieldKey={Doc.LayoutFieldKey(this.props.document)}
+ bringToFront={emptyFunction}
+ rootSelected={returnTrue}
+ addDocument={returnFalse}
+ moveDocument={returnFalse}
+ removeDocument={returnFalse}
+ PanelWidth={this.returnMiniSize}
+ PanelHeight={this.returnMiniSize}
+ ScreenToLocalTransform={Transform.Identity}
+ renderDepth={0}
+ whenActiveChanged={emptyFunction}
+ focus={DocUtils.DefaultFocus}
+ styleProvider={TabDocView.miniStyleProvider}
+ layerProvider={undefined}
+ addDocTab={this.props.addDocTab}
+ pinToPres={TabDocView.PinDoc}
+ docFilters={CollectionDockingView.Instance.docFilters}
+ docRangeFilters={CollectionDockingView.Instance.docRangeFilters}
+ searchFilterDocs={CollectionDockingView.Instance.searchFilterDocs}
+ fitContentsToDoc={returnTrue}
+ />
+ <div className="miniOverlay" onPointerDown={this.miniDown} >
+ <div className="miniThumb" style={{ width: `${miniWidth}% `, height: `${miniHeight}% `, left: `${miniLeft}% `, top: `${miniTop}% `, }} />
+ </div>
+ </div>
+
+ <Tooltip title={<div className="dash-tooltip">{"toggle minimap"}</div>}>
+ <div className="miniMap-hidden" onPointerDown={e => e.stopPropagation()} onClick={action(e => { e.stopPropagation(); this.props.document.hideMinimap = !this.props.document.hideMinimap; })}
+ style={{ background: DefaultStyleProvider(this.props.document, undefined, StyleProp.BackgroundColor) }} >
+ <FontAwesomeIcon icon={"globe-asia"} size="lg" />
+ </div>
+ </Tooltip>
+ </>;
+ }
} \ No newline at end of file
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 9fa5b8670..ba89579cd 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -120,6 +120,7 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
@computed get backgroundActive() { return this.props.layerProvider?.(this.layoutDoc) === false && (this.props.ContainingCollectionView?.active() || this.props.active()); }
@computed get fitToContentVals() {
return {
+ bounds: this.contentBounds,
panX: (this.contentBounds.x + this.contentBounds.r) / 2,
panY: (this.contentBounds.y + this.contentBounds.b) / 2,
scale: !this.childDocs.length ? 1 :
@@ -1214,15 +1215,6 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
this._disposers.layoutComputation = reaction(() => this.doLayoutComputation,
(elements) => this._layoutElements = elements || [],
{ fireImmediately: true, name: "doLayout" });
- if (!this.props.isAnnotationOverlay) {
- this._disposers.contentBounds = reaction(() => this.contentBounds,
- bounds => (!this.fitToContent && this._layoutElements?.length) && setTimeout(() => {
- const rbounds = Cast(this.Document._renderContentBounds, listSpec("number"), [0, 0, 0, 0]);
- if (rbounds[0] !== bounds.x || rbounds[1] !== bounds.y || rbounds[2] !== bounds.r || rbounds[3] !== bounds.b) {
- this.Document._renderContentBounds = new List<number>([bounds.x, bounds.y, bounds.r, bounds.b]);
- }
- }));
- }
this._marqueeRef.current?.addEventListener("dashDragAutoScroll", this.onDragAutoScroll as any);
}
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index e31101459..5dfb3e99b 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -83,7 +83,7 @@ export interface DocComponentView {
forward?: () => boolean;
url?: () => string;
submitURL?: (url: string) => boolean;
- freeformData?: (force?: boolean) => Opt<{ panX: number, panY: number, scale: number }>;
+ freeformData?: (force?: boolean) => Opt<{ panX: number, panY: number, scale: number, bounds: { x: number, y: number, r: number, b: number } }>;
}
export interface DocumentViewSharedProps {
renderDepth: number;