Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve interfaces for layout and layout options #426

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
gfontorbe marked this conversation as resolved.
Show resolved Hide resolved

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
Loading