Skip to content

Commit

Permalink
Renamed BoundsAware to InternalBoundsAware
Browse files Browse the repository at this point in the history
  • Loading branch information
spoenemann committed Jan 3, 2024
1 parent 91e1f4b commit 3a3a0a0
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 74 deletions.
8 changes: 4 additions & 4 deletions examples/multicore/src/chipmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
********************************************************************************/

import {
SShapeElementImpl, SChildElementImpl, BoundsAware, boundsFeature, fadeFeature,
layoutContainerFeature, LayoutContainer, selectFeature, ViewportRootElementImpl,
SShapeElementImpl, SChildElementImpl, InternalBoundsAware, boundsFeature, fadeFeature,
layoutContainerFeature, selectFeature, ViewportRootElementImpl, InternalLayoutContainer,
hoverFeedbackFeature, popupFeature
} from 'sprotty';
import {
Expand All @@ -33,7 +33,7 @@ export interface ProcessorSchema extends SModelRoot {
columns: number
}

export class Processor extends ViewportRootElementImpl implements BoundsAware {
export class Processor extends ViewportRootElementImpl implements InternalBoundsAware {
static override readonly DEFAULT_FEATURES = [...ViewportRootElementImpl.DEFAULT_FEATURES, boundsFeature];

rows: number = 0;
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface CoreSchema extends SShapeElement {
children: SModelElement[]
}

export class Core extends SShapeElementImpl implements Selectable, Fadeable, Hoverable, LayoutContainer {
export class Core extends SShapeElementImpl implements Selectable, Fadeable, Hoverable, InternalLayoutContainer {
static readonly DEFAULT_FEATURES = [selectFeature, fadeFeature, layoutContainerFeature,
hoverFeedbackFeature, popupFeature];

Expand Down
46 changes: 30 additions & 16 deletions packages/sprotty-protocol/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,22 @@ export interface ViewportRootElement extends SModelRoot, Partial<Viewport>, Part
/**
* Root element for graph-like models.
*/
export interface SGraph extends ViewportRootElement {
export interface SGraph extends ViewportRootElement, Partial<LayoutableChild> {
children: SModelElement[]
layoutOptions?: ModelLayoutOptions

/** @deprecated Use `position` and `size` instead. */
bounds?: Bounds
}

/**
* Options to control the "micro layout" of a model element, i.e. the arrangement of its content
* using simple algorithms such as horizontal or vertical box layout.
*/
export type ModelLayoutOptions = { [key: string]: string | number | boolean };

export interface SShapeElement extends SModelElement, Partial<BoundsAware> {
layoutOptions?: ModelLayoutOptions
export interface SShapeElement extends SModelElement, Partial<LayoutableChild> {
}

/**
* Model element class for nodes, which are the main entities in a graph. A node can be connected to
* another node via an SEdge. Such a connection can be direct, i.e. the node is the source or target of
* the edge, or indirect through a port, i.e. it contains an SPort which is the source or target of the edge.
*/
export interface SNode extends SShapeElement, Partial<Selectable>, Partial<Hoverable>, Partial<Fadeable> {
layout?: string
export interface SNode extends SShapeElement, Partial<LayoutContainer>, Partial<Selectable>, Partial<Hoverable>, Partial<Fadeable> {
anchorKind?: string
}

Expand Down Expand Up @@ -102,8 +93,7 @@ export interface SLabel extends SShapeElement, Partial<Selectable>, Partial<Alig
* A compartment is used to group multiple child elements such as labels of a node. Usually a `vbox`
* or `hbox` layout is used to arrange these children.
*/
export interface SCompartment extends SShapeElement {
layout?: string
export interface SCompartment extends SShapeElement, Partial<LayoutContainer> {
}

/**
Expand Down Expand Up @@ -138,13 +128,37 @@ export function isZoomable(element: SModelElement | Zoomable): element is Zoomab
}

/**
* Model elements that implement this interface have a position and a size.
* An element that can be placed at a specific location using its position property.
* Feature extension interface for `moveFeature`.
*/
export interface BoundsAware {
export interface Locateable {
position: Point
}

/**
* Model elements that implement this interface have a position and a size.
*/
export interface BoundsAware extends Locateable {
size: Dimension
}

export type ModelLayoutOptions = { [key: string]: string | number | boolean };

/**
* Feature extension interface for `layoutableChildFeature`. This is used when the parent
* element has a `layout` property (meaning it's a `LayoutContainer`).
*/
export interface LayoutableChild extends BoundsAware {
layoutOptions?: ModelLayoutOptions
}

/**
* Used to identify model elements that specify a layout to apply to their children.
*/
export interface LayoutContainer extends LayoutableChild {
layout: string
}

/**
* Feature extension interface for `alignFeature`.
* Used to adjust elements whose bounding box is not at the origin, e.g. labels
Expand Down
16 changes: 8 additions & 8 deletions packages/sprotty/src/features/bounds/abstract-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { Bounds, Dimension, Point } from "sprotty-protocol/lib/utils/geometry";
import { SParentElementImpl, SModelElementImpl, SChildElementImpl } from "../../base/model/smodel";
import { isLayoutContainer, isLayoutableChild, LayoutContainer, isBoundsAware } from "./model";
import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
import { SParentElementImpl, SModelElementImpl, SChildElementImpl } from '../../base/model/smodel';
import { isLayoutContainer, isLayoutableChild, InternalLayoutContainer, isBoundsAware } from './model';
import { ILayout, StatefulLayouter } from './layout';
import { AbstractLayoutOptions, HAlignment, VAlignment } from './layout-options';
import { BoundsData } from './hidden-bounds-updater';
import { injectable } from "inversify";
import { injectable } from 'inversify';

@injectable()
export abstract class AbstractLayout<T extends AbstractLayoutOptions> implements ILayout {

layout(container: SParentElementImpl & LayoutContainer,
layout(container: SParentElementImpl & InternalLayoutContainer,
layouter: StatefulLayouter) {
const boundsData = layouter.getBoundsData(container);
const options = this.getLayoutOptions(container);
Expand All @@ -50,7 +50,7 @@ export abstract class AbstractLayout<T extends AbstractLayoutOptions> implements
currentOffset: Point,
maxWidth: number, maxHeight: number): Point;

protected getFinalContainerBounds(container: SParentElementImpl & LayoutContainer,
protected getFinalContainerBounds(container: SParentElementImpl & InternalLayoutContainer,
lastOffset: Point,
options: T,
maxWidth: number,
Expand Down Expand Up @@ -85,11 +85,11 @@ export abstract class AbstractLayout<T extends AbstractLayoutOptions> implements
}
}

protected abstract getChildrenSize(container: SParentElementImpl & LayoutContainer,
protected abstract getChildrenSize(container: SParentElementImpl & InternalLayoutContainer,
containerOptions: T,
layouter: StatefulLayouter): Dimension;

protected layoutChildren(container: SParentElementImpl & LayoutContainer,
protected layoutChildren(container: SParentElementImpl & InternalLayoutContainer,
layouter: StatefulLayouter,
containerOptions: T,
maxWidth: number,
Expand Down
4 changes: 2 additions & 2 deletions packages/sprotty/src/features/bounds/bounds-manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
import { CommandExecutionContext, CommandResult, CommandReturn, HiddenCommand, SystemCommand } from '../../base/commands/command';
import { SModelElementImpl } from '../../base/model/smodel';
import { TYPES } from '../../base/types';
import { BoundsAware, isBoundsAware } from './model';
import { InternalBoundsAware, isBoundsAware } from './model';

export interface ResolvedElementAndBounds {
element: SModelElementImpl & BoundsAware
element: SModelElementImpl & InternalBoundsAware
oldBounds: Bounds
newPosition?: Point
newSize: Dimension
Expand Down
4 changes: 2 additions & 2 deletions packages/sprotty/src/features/bounds/hbox-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
import { AbstractLayout } from './abstract-layout';
import { AbstractLayoutOptions, VAlignment } from './layout-options';
import { BoundsData } from './hidden-bounds-updater';
import { LayoutContainer, isLayoutableChild } from './model';
import { InternalLayoutContainer, isLayoutableChild } from './model';
import { StatefulLayouter } from './layout';

export interface HBoxLayoutOptions extends AbstractLayoutOptions {
Expand All @@ -36,7 +36,7 @@ export class HBoxLayouter extends AbstractLayout<HBoxLayoutOptions> {

static KIND = 'hbox';

protected getChildrenSize(container: SParentElementImpl & LayoutContainer,
protected getChildrenSize(container: SParentElementImpl & InternalLayoutContainer,
containerOptions: HBoxLayoutOptions,
layouter: StatefulLayouter) {
let maxWidth = 0;
Expand Down
6 changes: 3 additions & 3 deletions packages/sprotty/src/features/bounds/hidden-bounds-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { SChildElementImpl, SModelElementImpl, SModelRootImpl } from '../../base
import { TYPES } from '../../base/types';
import { IVNodePostprocessor } from '../../base/views/vnode-postprocessor';
import { Layouter } from './layout';
import { BoundsAware, isAlignable, isLayoutContainer, isSizeable } from './model';
import { InternalBoundsAware, isAlignable, isLayoutContainer, isSizeable } from './model';

export class BoundsData {
vnode?: VNode;
Expand Down Expand Up @@ -53,7 +53,7 @@ export class HiddenBoundsUpdater implements IVNodePostprocessor {
@inject(TYPES.IActionDispatcher) protected actionDispatcher: IActionDispatcher;
@inject(TYPES.Layouter) protected layouter: Layouter;

private readonly element2boundsData: Map<SModelElementImpl & BoundsAware, BoundsData> = new Map;
private readonly element2boundsData: Map<SModelElementImpl & InternalBoundsAware, BoundsData> = new Map;

root: SModelRootImpl | undefined;

Expand Down Expand Up @@ -155,7 +155,7 @@ export class HiddenBoundsUpdater implements IVNodePostprocessor {
* their parent, you can add the `ATTR_BBOX_ELEMENT` attribute to the SVG element
* that shall be used to compute the bounding box.
*/
protected getBounds(elm: Node, element: SModelElementImpl & BoundsAware): Bounds {
protected getBounds(elm: Node, element: SModelElementImpl & InternalBoundsAware): Bounds {
if (!isSVGGraphicsElement(elm)) {
this.logger.error(this, 'Not an SVG element:', elm);
return Bounds.EMPTY;
Expand Down
8 changes: 4 additions & 4 deletions packages/sprotty/src/features/bounds/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { TYPES } from "../../base/types";
import { ILogger } from '../../utils/logging';
import { InstanceRegistry } from "../../utils/registry";
import { SParentElementImpl, SModelElementImpl } from "../../base/model/smodel";
import { isLayoutContainer, LayoutContainer } from "./model";
import { isLayoutContainer, InternalLayoutContainer } from "./model";
import { BoundsData } from "./hidden-bounds-updater";
import { isInjectable } from "../../utils/inversify";

Expand Down Expand Up @@ -59,7 +59,7 @@ export class Layouter {

export class StatefulLayouter {

private toBeLayouted: (SParentElementImpl & LayoutContainer)[];
private toBeLayouted: (SParentElementImpl & InternalLayoutContainer)[];

constructor(private readonly element2boundsData: Map<SModelElementImpl, BoundsData>,
private readonly layoutRegistry: LayoutRegistry,
Expand Down Expand Up @@ -96,7 +96,7 @@ export class StatefulLayouter {
}
}

protected doLayout(element: SParentElementImpl & LayoutContainer): Bounds {
protected doLayout(element: SParentElementImpl & InternalLayoutContainer): Bounds {
const index = this.toBeLayouted.indexOf(element);
if (index >= 0)
this.toBeLayouted.splice(index, 1);
Expand All @@ -114,7 +114,7 @@ export class StatefulLayouter {
}

export interface ILayout {
layout(container: SParentElementImpl & LayoutContainer,
layout(container: SParentElementImpl & InternalLayoutContainer,
layouter: StatefulLayouter): void
}

Expand Down
27 changes: 18 additions & 9 deletions packages/sprotty/src/features/bounds/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { Locateable } from 'sprotty-protocol/lib/model';
import { Bounds, Dimension, isBounds, Point } from 'sprotty-protocol/lib/utils/geometry';
import { SChildElementImpl, SModelElementImpl, SModelRootImpl, SParentElementImpl } from '../../base/model/smodel';
import { findParentByFeature } from '../../base/model/smodel-utils';
import { DOMHelper } from '../../base/views/dom-helper';
import { ViewerOptions } from '../../base/views/viewer-options';
import { getWindowScroll } from '../../utils/browser';
import type { Locateable } from '../move/model';

export const boundsFeature = Symbol('boundsFeature');
export const layoutContainerFeature = Symbol('layoutContainerFeature');
Expand All @@ -34,26 +34,35 @@ export const alignFeature = Symbol('alignFeature');
*
* Feature extension interface for {@link boundsFeature}.
*/
export interface BoundsAware {
export interface InternalBoundsAware {
bounds: Bounds
}

/** @deprecated Use `InternalBoundsAware` instead. */
export type BoundsAware = InternalBoundsAware;

/**
* Used to identify model elements that specify a layout to apply to their children.
*/
export interface LayoutContainer extends LayoutableChild {
export interface InternalLayoutContainer extends InternalLayoutableChild {
layout: string
}

/** @deprecated Use `InternalLayoutContainer` instead. */
export type LayoutContainer = InternalLayoutContainer;

export type ModelLayoutOptions = { [key: string]: string | number | boolean };

/**
* Feature extension interface for {@link layoutableChildFeature}.
*/
export interface LayoutableChild extends BoundsAware {
export interface InternalLayoutableChild extends InternalBoundsAware {
layoutOptions?: ModelLayoutOptions
}

/** @deprecated Use `InternalLayoutableChild` instead. */
export type LayoutableChild = InternalLayoutableChild;

/**
* Feature extension interface for {@link alignFeature}.
* Used to adjust elements whose bounding box is not at the origin, e.g.
Expand All @@ -64,22 +73,22 @@ export interface Alignable {
alignment: Point
}

export function isBoundsAware(element: SModelElementImpl): element is SModelElementImpl & BoundsAware {
export function isBoundsAware(element: SModelElementImpl): element is SModelElementImpl & InternalBoundsAware {
return 'bounds' in element;
}

export function isLayoutContainer(element: SModelElementImpl): element is SParentElementImpl & LayoutContainer {
export function isLayoutContainer(element: SModelElementImpl): element is SParentElementImpl & InternalLayoutContainer {
return isBoundsAware(element)
&& element.hasFeature(layoutContainerFeature)
&& 'layout' in element;
}

export function isLayoutableChild(element: SModelElementImpl): element is SChildElementImpl & LayoutableChild {
export function isLayoutableChild(element: SModelElementImpl): element is SChildElementImpl & InternalLayoutableChild {
return isBoundsAware(element)
&& element.hasFeature(layoutableChildFeature);
}

export function isSizeable(element: SModelElementImpl): element is SModelElementImpl & BoundsAware {
export function isSizeable(element: SModelElementImpl): element is SModelElementImpl & InternalBoundsAware {
return element.hasFeature(boundsFeature) && isBoundsAware(element);
}

Expand Down Expand Up @@ -165,7 +174,7 @@ function doFindChildrenAtPosition(parent: SParentElementImpl, point: Point, matc
/**
* Abstract class for elements with a position and a size.
*/
export abstract class SShapeElementImpl extends SChildElementImpl implements BoundsAware, Locateable, LayoutableChild {
export abstract class SShapeElementImpl extends SChildElementImpl implements InternalBoundsAware, Locateable, InternalLayoutableChild {

position: Point = Point.ORIGIN;
size: Dimension = Dimension.EMPTY;
Expand Down
4 changes: 2 additions & 2 deletions packages/sprotty/src/features/bounds/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { Dimension } from "sprotty-protocol/lib/utils/geometry";
import { Animation } from "../../base/animations/animation";
import { SModelRootImpl, SModelElementImpl } from "../../base/model/smodel";
import { CommandExecutionContext } from "../../base/commands/command";
import { BoundsAware } from './model';
import { InternalBoundsAware } from './model';

export interface ResolvedElementResize {
element: SModelElementImpl & BoundsAware
element: SModelElementImpl & InternalBoundsAware
fromDimension: Dimension
toDimension: Dimension
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sprotty/src/features/bounds/stack-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
import { AbstractLayout } from './abstract-layout';
import { AbstractLayoutOptions, HAlignment, VAlignment } from './layout-options';
import { BoundsData } from './hidden-bounds-updater';
import { LayoutContainer, isLayoutableChild } from './model';
import { InternalLayoutContainer, isLayoutableChild } from './model';
import { StatefulLayouter } from './layout';

export interface StackLayoutOptions extends AbstractLayoutOptions {
Expand All @@ -34,7 +34,7 @@ export class StackLayouter extends AbstractLayout<StackLayoutOptions> {

static KIND = 'stack';

protected getChildrenSize(container: SParentElementImpl & LayoutContainer,
protected getChildrenSize(container: SParentElementImpl & InternalLayoutContainer,
options: StackLayoutOptions,
layouter: StatefulLayouter) {
let maxWidth = -1;
Expand Down
4 changes: 2 additions & 2 deletions packages/sprotty/src/features/bounds/vbox-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
import { AbstractLayout } from './abstract-layout';
import { AbstractLayoutOptions, HAlignment } from './layout-options';
import { BoundsData } from './hidden-bounds-updater';
import { LayoutContainer, isLayoutableChild } from './model';
import { InternalLayoutContainer, isLayoutableChild } from './model';
import { StatefulLayouter } from './layout';

export interface VBoxLayoutOptions extends AbstractLayoutOptions {
Expand All @@ -36,7 +36,7 @@ export class VBoxLayouter extends AbstractLayout<VBoxLayoutOptions> {

static KIND = 'vbox';

protected getChildrenSize(container: SParentElementImpl & LayoutContainer,
protected getChildrenSize(container: SParentElementImpl & InternalLayoutContainer,
containerOptions: VBoxLayoutOptions,
layouter: StatefulLayouter) {
let maxWidth = -1;
Expand Down
Loading

0 comments on commit 3a3a0a0

Please sign in to comment.