UNPKG

7.43 kBTypeScriptView Raw
1import { Message } from '@phosphor/messaging';
2import { PanelLayout } from './panellayout';
3import { Widget } from './widget';
4/**
5 * A layout which arranges its widgets into resizable sections.
6 */
7export declare class SplitLayout extends PanelLayout {
8 /**
9 * Construct a new split layout.
10 *
11 * @param options - The options for initializing the layout.
12 */
13 constructor(options: SplitLayout.IOptions);
14 /**
15 * Dispose of the resources held by the layout.
16 */
17 dispose(): void;
18 /**
19 * The renderer used by the split layout.
20 */
21 readonly renderer: SplitLayout.IRenderer;
22 /**
23 * Get the layout orientation for the split layout.
24 */
25 /**
26 * Set the layout orientation for the split layout.
27 */
28 orientation: SplitLayout.Orientation;
29 /**
30 * Get the content alignment for the split layout.
31 *
32 * #### Notes
33 * This is the alignment of the widgets in the layout direction.
34 *
35 * The alignment has no effect if the widgets can expand to fill the
36 * entire split layout.
37 */
38 /**
39 * Set the content alignment for the split layout.
40 *
41 * #### Notes
42 * This is the alignment of the widgets in the layout direction.
43 *
44 * The alignment has no effect if the widgets can expand to fill the
45 * entire split layout.
46 */
47 alignment: SplitLayout.Alignment;
48 /**
49 * Get the inter-element spacing for the split layout.
50 */
51 /**
52 * Set the inter-element spacing for the split layout.
53 */
54 spacing: number;
55 /**
56 * A read-only array of the split handles in the layout.
57 */
58 readonly handles: ReadonlyArray<HTMLDivElement>;
59 /**
60 * Get the relative sizes of the widgets in the layout.
61 *
62 * @returns A new array of the relative sizes of the widgets.
63 *
64 * #### Notes
65 * The returned sizes reflect the sizes of the widgets normalized
66 * relative to their siblings.
67 *
68 * This method **does not** measure the DOM nodes.
69 */
70 relativeSizes(): number[];
71 /**
72 * Set the relative sizes for the widgets in the layout.
73 *
74 * @param sizes - The relative sizes for the widgets in the panel.
75 *
76 * #### Notes
77 * Extra values are ignored, too few will yield an undefined layout.
78 *
79 * The actual geometry of the DOM nodes is updated asynchronously.
80 */
81 setRelativeSizes(sizes: number[]): void;
82 /**
83 * Move the offset position of a split handle.
84 *
85 * @param index - The index of the handle of the interest.
86 *
87 * @param position - The desired offset position of the handle.
88 *
89 * #### Notes
90 * The position is relative to the offset parent.
91 *
92 * This will move the handle as close as possible to the desired
93 * position. The sibling widgets will be adjusted as necessary.
94 */
95 moveHandle(index: number, position: number): void;
96 /**
97 * Perform layout initialization which requires the parent widget.
98 */
99 protected init(): void;
100 /**
101 * Attach a widget to the parent's DOM node.
102 *
103 * @param index - The current index of the widget in the layout.
104 *
105 * @param widget - The widget to attach to the parent.
106 *
107 * #### Notes
108 * This is a reimplementation of the superclass method.
109 */
110 protected attachWidget(index: number, widget: Widget): void;
111 /**
112 * Move a widget in the parent's DOM node.
113 *
114 * @param fromIndex - The previous index of the widget in the layout.
115 *
116 * @param toIndex - The current index of the widget in the layout.
117 *
118 * @param widget - The widget to move in the parent.
119 *
120 * #### Notes
121 * This is a reimplementation of the superclass method.
122 */
123 protected moveWidget(fromIndex: number, toIndex: number, widget: Widget): void;
124 /**
125 * Detach a widget from the parent's DOM node.
126 *
127 * @param index - The previous index of the widget in the layout.
128 *
129 * @param widget - The widget to detach from the parent.
130 *
131 * #### Notes
132 * This is a reimplementation of the superclass method.
133 */
134 protected detachWidget(index: number, widget: Widget): void;
135 /**
136 * A message handler invoked on a `'before-show'` message.
137 */
138 protected onBeforeShow(msg: Message): void;
139 /**
140 * A message handler invoked on a `'before-attach'` message.
141 */
142 protected onBeforeAttach(msg: Message): void;
143 /**
144 * A message handler invoked on a `'child-shown'` message.
145 */
146 protected onChildShown(msg: Widget.ChildMessage): void;
147 /**
148 * A message handler invoked on a `'child-hidden'` message.
149 */
150 protected onChildHidden(msg: Widget.ChildMessage): void;
151 /**
152 * A message handler invoked on a `'resize'` message.
153 */
154 protected onResize(msg: Widget.ResizeMessage): void;
155 /**
156 * A message handler invoked on an `'update-request'` message.
157 */
158 protected onUpdateRequest(msg: Message): void;
159 /**
160 * A message handler invoked on a `'fit-request'` message.
161 */
162 protected onFitRequest(msg: Message): void;
163 /**
164 * Fit the layout to the total size required by the widgets.
165 */
166 private _fit;
167 /**
168 * Update the layout position and size of the widgets.
169 *
170 * The parent offset dimensions should be `-1` if unknown.
171 */
172 private _update;
173 private _fixed;
174 private _spacing;
175 private _dirty;
176 private _hasNormedSizes;
177 private _sizers;
178 private _items;
179 private _handles;
180 private _box;
181 private _alignment;
182 private _orientation;
183}
184/**
185 * The namespace for the `SplitLayout` class statics.
186 */
187export declare namespace SplitLayout {
188 /**
189 * A type alias for a split layout orientation.
190 */
191 type Orientation = 'horizontal' | 'vertical';
192 /**
193 * A type alias for a split layout alignment.
194 */
195 type Alignment = 'start' | 'center' | 'end' | 'justify';
196 /**
197 * An options object for initializing a split layout.
198 */
199 interface IOptions {
200 /**
201 * The renderer to use for the split layout.
202 */
203 renderer: IRenderer;
204 /**
205 * The orientation of the layout.
206 *
207 * The default is `'horizontal'`.
208 */
209 orientation?: Orientation;
210 /**
211 * The content alignment of the layout.
212 *
213 * The default is `'start'`.
214 */
215 alignment?: Alignment;
216 /**
217 * The spacing between items in the layout.
218 *
219 * The default is `4`.
220 */
221 spacing?: number;
222 }
223 /**
224 * A renderer for use with a split layout.
225 */
226 interface IRenderer {
227 /**
228 * Create a new handle for use with a split layout.
229 *
230 * @returns A new handle element.
231 */
232 createHandle(): HTMLDivElement;
233 }
234 /**
235 * Get the split layout stretch factor for the given widget.
236 *
237 * @param widget - The widget of interest.
238 *
239 * @returns The split layout stretch factor for the widget.
240 */
241 function getStretch(widget: Widget): number;
242 /**
243 * Set the split layout stretch factor for the given widget.
244 *
245 * @param widget - The widget of interest.
246 *
247 * @param value - The value for the stretch factor.
248 */
249 function setStretch(widget: Widget, value: number): void;
250}