Skip to content

Commit e171c12

Browse files
authored
Improve interfaces for layout and layout options (#426)
* 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]>
1 parent 2056562 commit e171c12

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

packages/sprotty-protocol/src/model.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,48 @@ export interface BoundsAware extends Locateable {
142142
size: Dimension
143143
}
144144

145-
export type ModelLayoutOptions = { [key: string]: string | number | boolean };
146-
147145
/**
148146
* Feature extension interface for `layoutableChildFeature`. This is used when the parent
149147
* element has a `layout` property (meaning it's a `LayoutContainer`).
150-
*/
148+
*/
151149
export interface LayoutableChild extends BoundsAware {
152150
layoutOptions?: ModelLayoutOptions
153151
}
154152

153+
/**
154+
* Layout options of a `LayoutableChild`.
155+
*/
156+
export interface ModelLayoutOptions {
157+
hAlign?: HAlignment
158+
hGap?: number
159+
vAlign?: VAlignment
160+
vGap?: number
161+
paddingTop?: number
162+
paddingRight?: number
163+
paddingBottom?: number
164+
paddingLeft?: number
165+
paddingFactor?: number
166+
minWidth?: number
167+
minHeight?: number
168+
resizeContainer?: boolean
169+
[key: string]: string | number | boolean | undefined
170+
};
171+
172+
export type HAlignment = 'left' | 'center' | 'right';
173+
export type VAlignment = 'top' | 'center' | 'bottom';
174+
155175
/**
156176
* Used to identify model elements that specify a layout to apply to their children.
157177
*/
158178
export interface LayoutContainer extends LayoutableChild {
159-
layout: string
179+
layout: LayoutKind
160180
}
161181

182+
/**
183+
* Type for the layout property of a `LayoutContainer`.
184+
*/
185+
export type LayoutKind = 'stack' | 'vbox' | 'hbox' | (string & {});
186+
162187
/**
163188
* Feature extension interface for `alignFeature`.
164189
* Used to adjust elements whose bounding box is not at the origin, e.g. labels

packages/sprotty/src/features/bounds/abstract-layout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2017-2018 TypeFox and others.
2+
* Copyright (c) 2017-2024 TypeFox and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -18,9 +18,10 @@ import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
1818
import { SParentElementImpl, SModelElementImpl, SChildElementImpl } from '../../base/model/smodel';
1919
import { isLayoutContainer, isLayoutableChild, InternalLayoutContainer, isBoundsAware } from './model';
2020
import { ILayout, StatefulLayouter } from './layout';
21-
import { AbstractLayoutOptions, HAlignment, VAlignment } from './layout-options';
21+
import { AbstractLayoutOptions } from './layout-options';
2222
import { BoundsData } from './hidden-bounds-updater';
2323
import { injectable } from 'inversify';
24+
import { HAlignment, VAlignment } from 'sprotty-protocol/lib/model';
2425

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

packages/sprotty/src/features/bounds/hbox-layout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2017-2018 TypeFox and others.
2+
* Copyright (c) 2017-2024 TypeFox and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -18,10 +18,11 @@ import { injectable } from 'inversify';
1818
import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
1919
import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
2020
import { AbstractLayout } from './abstract-layout';
21-
import { AbstractLayoutOptions, VAlignment } from './layout-options';
21+
import { AbstractLayoutOptions } from './layout-options';
2222
import { BoundsData } from './hidden-bounds-updater';
2323
import { InternalLayoutContainer, isLayoutableChild } from './model';
2424
import { StatefulLayouter } from './layout';
25+
import { VAlignment } from 'sprotty-protocol/lib/model';
2526

2627
export interface HBoxLayoutOptions extends AbstractLayoutOptions {
2728
hGap: number

packages/sprotty/src/features/bounds/layout-options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2017-2018 TypeFox and others.
2+
* Copyright (c) 2017-2024 TypeFox and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -16,8 +16,10 @@
1616

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

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

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

2325
export interface AbstractLayoutOptions extends JsonMap {

packages/sprotty/src/features/bounds/stack-layout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2017-2018 TypeFox and others.
2+
* Copyright (c) 2017-2024 TypeFox and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -18,10 +18,11 @@ import { injectable } from 'inversify';
1818
import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
1919
import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
2020
import { AbstractLayout } from './abstract-layout';
21-
import { AbstractLayoutOptions, HAlignment, VAlignment } from './layout-options';
21+
import { AbstractLayoutOptions } from './layout-options';
2222
import { BoundsData } from './hidden-bounds-updater';
2323
import { InternalLayoutContainer, isLayoutableChild } from './model';
2424
import { StatefulLayouter } from './layout';
25+
import { VAlignment, HAlignment } from 'sprotty-protocol/lib/model';
2526

2627
export interface StackLayoutOptions extends AbstractLayoutOptions {
2728
paddingFactor: number

packages/sprotty/src/features/bounds/vbox-layout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2017-2018 TypeFox and others.
2+
* Copyright (c) 2017-2024 TypeFox and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -18,10 +18,11 @@ import { injectable } from 'inversify';
1818
import { Bounds, Dimension, Point } from 'sprotty-protocol/lib/utils/geometry';
1919
import { SParentElementImpl, SChildElementImpl } from "../../base/model/smodel";
2020
import { AbstractLayout } from './abstract-layout';
21-
import { AbstractLayoutOptions, HAlignment } from './layout-options';
21+
import { AbstractLayoutOptions } from './layout-options';
2222
import { BoundsData } from './hidden-bounds-updater';
2323
import { InternalLayoutContainer, isLayoutableChild } from './model';
2424
import { StatefulLayouter } from './layout';
25+
import { HAlignment } from 'sprotty-protocol/lib/model';
2526

2627
export interface VBoxLayoutOptions extends AbstractLayoutOptions {
2728
vGap: number

0 commit comments

Comments
 (0)