From d549fa23ab74e2d8ce6aaa8de222a35c8a70c8b8 Mon Sep 17 00:00:00 2001 From: Guillaume Fontorbe Date: Thu, 8 Feb 2024 11:39:01 +0100 Subject: [PATCH 1/2] Improve interfaces for layout and layout options Signed-off-by: Guillaume Fontorbe --- packages/sprotty-protocol/src/model.ts | 32 ++++++++++++++++--- .../src/features/bounds/abstract-layout.ts | 5 +-- .../src/features/bounds/hbox-layout.ts | 5 +-- .../src/features/bounds/layout-options.ts | 6 +--- .../src/features/bounds/stack-layout.ts | 5 +-- .../src/features/bounds/vbox-layout.ts | 5 +-- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/packages/sprotty-protocol/src/model.ts b/packages/sprotty-protocol/src/model.ts index ef613993..9b2802e7 100644 --- a/packages/sprotty-protocol/src/model.ts +++ b/packages/sprotty-protocol/src/model.ts @@ -142,23 +142,47 @@ 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: Layout } +/** + * Type for the layout property of a `LayoutContainer`. + */ +export type Layout = 'stack' | 'vbox' | 'hbox' | (string & {}); + /** * Feature extension interface for `alignFeature`. * Used to adjust elements whose bounding box is not at the origin, e.g. labels diff --git a/packages/sprotty/src/features/bounds/abstract-layout.ts b/packages/sprotty/src/features/bounds/abstract-layout.ts index 7f62dcbf..f9d2ec41 100644 --- a/packages/sprotty/src/features/bounds/abstract-layout.ts +++ b/packages/sprotty/src/features/bounds/abstract-layout.ts @@ -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 @@ -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 implements ILayout { diff --git a/packages/sprotty/src/features/bounds/hbox-layout.ts b/packages/sprotty/src/features/bounds/hbox-layout.ts index 96f7c1eb..9da86af2 100644 --- a/packages/sprotty/src/features/bounds/hbox-layout.ts +++ b/packages/sprotty/src/features/bounds/hbox-layout.ts @@ -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 @@ -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 diff --git a/packages/sprotty/src/features/bounds/layout-options.ts b/packages/sprotty/src/features/bounds/layout-options.ts index db396861..f735b372 100644 --- a/packages/sprotty/src/features/bounds/layout-options.ts +++ b/packages/sprotty/src/features/bounds/layout-options.ts @@ -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 @@ -16,10 +16,6 @@ import { JsonMap } from 'sprotty-protocol/lib/utils/json'; -export type HAlignment = 'left' | 'center' | 'right'; - -export type VAlignment = 'top' | 'center' | 'bottom'; - export interface AbstractLayoutOptions extends JsonMap { resizeContainer: boolean paddingTop: number diff --git a/packages/sprotty/src/features/bounds/stack-layout.ts b/packages/sprotty/src/features/bounds/stack-layout.ts index 683333f2..5a86c106 100644 --- a/packages/sprotty/src/features/bounds/stack-layout.ts +++ b/packages/sprotty/src/features/bounds/stack-layout.ts @@ -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 @@ -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 diff --git a/packages/sprotty/src/features/bounds/vbox-layout.ts b/packages/sprotty/src/features/bounds/vbox-layout.ts index 674c8d3b..48b034c9 100644 --- a/packages/sprotty/src/features/bounds/vbox-layout.ts +++ b/packages/sprotty/src/features/bounds/vbox-layout.ts @@ -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 @@ -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 From ad34d59608b255a85aed5d6de9d910f84d69bcb5 Mon Sep 17 00:00:00 2001 From: Guillaume Fontorbe Date: Mon, 12 Feb 2024 14:45:45 +0100 Subject: [PATCH 2/2] Update with spoenemann comments Signed-off-by: Guillaume Fontorbe --- packages/sprotty-protocol/src/model.ts | 7 ++++--- packages/sprotty/src/features/bounds/layout-options.ts | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/sprotty-protocol/src/model.ts b/packages/sprotty-protocol/src/model.ts index 9b2802e7..0fabd586 100644 --- a/packages/sprotty-protocol/src/model.ts +++ b/packages/sprotty-protocol/src/model.ts @@ -166,7 +166,8 @@ export interface ModelLayoutOptions { minWidth?: number minHeight?: number resizeContainer?: boolean - [key: string]: string | number | boolean | undefined}; + [key: string]: string | number | boolean | undefined +}; export type HAlignment = 'left' | 'center' | 'right'; export type VAlignment = 'top' | 'center' | 'bottom'; @@ -175,13 +176,13 @@ 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: Layout + layout: LayoutKind } /** * Type for the layout property of a `LayoutContainer`. */ -export type Layout = 'stack' | 'vbox' | 'hbox' | (string & {}); +export type LayoutKind = 'stack' | 'vbox' | 'hbox' | (string & {}); /** * Feature extension interface for `alignFeature`. diff --git a/packages/sprotty/src/features/bounds/layout-options.ts b/packages/sprotty/src/features/bounds/layout-options.ts index f735b372..cac51f10 100644 --- a/packages/sprotty/src/features/bounds/layout-options.ts +++ b/packages/sprotty/src/features/bounds/layout-options.ts @@ -16,6 +16,12 @@ 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 { resizeContainer: boolean paddingTop: number