UNPKG

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