Skip to content

Commit

Permalink
Improve interfaces for layout and layout options (#426)
Browse files Browse the repository at this point in the history
* Improve interfaces for layout and layout options

Signed-off-by: Guillaume Fontorbe <[email protected]>

* Update with spoenemann comments

Signed-off-by: Guillaume Fontorbe <[email protected]>

---------

Signed-off-by: Guillaume Fontorbe <[email protected]>
  • Loading branch information
gfontorbe authored Feb 12, 2024
1 parent 2056562 commit e171c12
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
33 changes: 29 additions & 4 deletions packages/sprotty-protocol/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,48 @@ 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
}

/**
* Layout options of a `LayoutableChild`.
*/
export interface ModelLayoutOptions {
hAlign?: HAlignment
hGap?: number
vAlign?: VAlignment
vGap?: number
paddingTop?: number
paddingRight?: number
paddingBottom?: number
paddingLeft?: number
paddingFactor?: number
minWidth?: number
minHeight?: number
resizeContainer?: boolean
[key: string]: string | number | boolean | undefined
};

export type HAlignment = 'left' | 'center' | 'right';
export type VAlignment = 'top' | 'center' | 'bottom';

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

/**
* Type for the layout property of a `LayoutContainer`.
*/
export type LayoutKind = 'stack' | 'vbox' | 'hbox' | (string & {});

/**
* Feature extension interface for `alignFeature`.
* Used to adjust elements whose bounding box is not at the origin, e.g. labels
Expand Down
5 changes: 3 additions & 2 deletions packages/sprotty/src/features/bounds/abstract-layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
* Copyright (c) 2017-2024 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -18,9 +18,10 @@ 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 { AbstractLayoutOptions } from './layout-options';
import { BoundsData } from './hidden-bounds-updater';
import { injectable } from 'inversify';
import { HAlignment, VAlignment } from 'sprotty-protocol/lib/model';

@injectable()
export abstract class AbstractLayout<T extends AbstractLayoutOptions> implements ILayout {
Expand Down
5 changes: 3 additions & 2 deletions packages/sprotty/src/features/bounds/hbox-layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
* Copyright (c) 2017-2024 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -18,10 +18,11 @@ import { injectable } from 'inversify';
import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
import { AbstractLayout } from './abstract-layout';
import { AbstractLayoutOptions, VAlignment } from './layout-options';
import { AbstractLayoutOptions } from './layout-options';
import { BoundsData } from './hidden-bounds-updater';
import { InternalLayoutContainer, isLayoutableChild } from './model';
import { StatefulLayouter } from './layout';
import { VAlignment } from 'sprotty-protocol/lib/model';

export interface HBoxLayoutOptions extends AbstractLayoutOptions {
hGap: number
Expand Down
4 changes: 3 additions & 1 deletion packages/sprotty/src/features/bounds/layout-options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
* Copyright (c) 2017-2024 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -16,8 +16,10 @@

import { JsonMap } from 'sprotty-protocol/lib/utils/json';

/** @deprecated Use HAlignment from `sprotty-protocol` instead */
export type HAlignment = 'left' | 'center' | 'right';

/** @deprecated Use VAlignment from `sprotty-protocol` instead */
export type VAlignment = 'top' | 'center' | 'bottom';

export interface AbstractLayoutOptions extends JsonMap {
Expand Down
5 changes: 3 additions & 2 deletions packages/sprotty/src/features/bounds/stack-layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
* Copyright (c) 2017-2024 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -18,10 +18,11 @@ import { injectable } from 'inversify';
import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
import { AbstractLayout } from './abstract-layout';
import { AbstractLayoutOptions, HAlignment, VAlignment } from './layout-options';
import { AbstractLayoutOptions } from './layout-options';
import { BoundsData } from './hidden-bounds-updater';
import { InternalLayoutContainer, isLayoutableChild } from './model';
import { StatefulLayouter } from './layout';
import { VAlignment, HAlignment } from 'sprotty-protocol/lib/model';

export interface StackLayoutOptions extends AbstractLayoutOptions {
paddingFactor: number
Expand Down
5 changes: 3 additions & 2 deletions packages/sprotty/src/features/bounds/vbox-layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
* Copyright (c) 2017-2024 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -18,10 +18,11 @@ import { injectable } from 'inversify';
import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
import { AbstractLayout } from './abstract-layout';
import { AbstractLayoutOptions, HAlignment } from './layout-options';
import { AbstractLayoutOptions } from './layout-options';
import { BoundsData } from './hidden-bounds-updater';
import { InternalLayoutContainer, isLayoutableChild } from './model';
import { StatefulLayouter } from './layout';
import { HAlignment } from 'sprotty-protocol/lib/model';

export interface VBoxLayoutOptions extends AbstractLayoutOptions {
vGap: number
Expand Down

0 comments on commit e171c12

Please sign in to comment.