UNPKG

16 kBTypeScriptView Raw
1import { IIterable, IIterator } from '@lumino/algorithm';
2import { IDisposable } from '@lumino/disposable';
3import { Message } from '@lumino/messaging';
4import { Widget } from './widget';
5/**
6 * An abstract base class for creating lumino layouts.
7 *
8 * #### Notes
9 * A layout is used to add widgets to a parent and to arrange those
10 * widgets within the parent's DOM node.
11 *
12 * This class implements the base functionality which is required of
13 * nearly all layouts. It must be subclassed in order to be useful.
14 *
15 * Notably, this class does not define a uniform interface for adding
16 * widgets to the layout. A subclass should define that API in a way
17 * which is meaningful for its intended use.
18 */
19export declare abstract class Layout implements IIterable<Widget>, IDisposable {
20 /**
21 * Construct a new layout.
22 *
23 * @param options - The options for initializing the layout.
24 */
25 constructor(options?: Layout.IOptions);
26 /**
27 * Dispose of the resources held by the layout.
28 *
29 * #### Notes
30 * This should be reimplemented to clear and dispose of the widgets.
31 *
32 * All reimplementations should call the superclass method.
33 *
34 * This method is called automatically when the parent is disposed.
35 */
36 dispose(): void;
37 /**
38 * Test whether the layout is disposed.
39 */
40 readonly isDisposed: boolean;
41 /**
42 * Get the parent widget of the layout.
43 */
44 /**
45 * Set the parent widget of the layout.
46 *
47 * #### Notes
48 * This is set automatically when installing the layout on the parent
49 * widget. The parent widget should not be set directly by user code.
50 */
51 parent: Widget | null;
52 /**
53 * Get the fit policy for the layout.
54 *
55 * #### Notes
56 * The fit policy controls the computed size constraints which are
57 * applied to the parent widget by the layout.
58 *
59 * Some layout implementations may ignore the fit policy.
60 */
61 /**
62 * Set the fit policy for the layout.
63 *
64 * #### Notes
65 * The fit policy controls the computed size constraints which are
66 * applied to the parent widget by the layout.
67 *
68 * Some layout implementations may ignore the fit policy.
69 *
70 * Changing the fit policy will clear the current size constraint
71 * for the parent widget and then re-fit the parent.
72 */
73 fitPolicy: Layout.FitPolicy;
74 /**
75 * Create an iterator over the widgets in the layout.
76 *
77 * @returns A new iterator over the widgets in the layout.
78 *
79 * #### Notes
80 * This abstract method must be implemented by a subclass.
81 */
82 abstract iter(): IIterator<Widget>;
83 /**
84 * Remove a widget from the layout.
85 *
86 * @param widget - The widget to remove from the layout.
87 *
88 * #### Notes
89 * A widget is automatically removed from the layout when its `parent`
90 * is set to `null`. This method should only be invoked directly when
91 * removing a widget from a layout which has yet to be installed on a
92 * parent widget.
93 *
94 * This method should *not* modify the widget's `parent`.
95 */
96 abstract removeWidget(widget: Widget): void;
97 /**
98 * Process a message sent to the parent widget.
99 *
100 * @param msg - The message sent to the parent widget.
101 *
102 * #### Notes
103 * This method is called by the parent widget to process a message.
104 *
105 * Subclasses may reimplement this method as needed.
106 */
107 processParentMessage(msg: Message): void;
108 /**
109 * Perform layout initialization which requires the parent widget.
110 *
111 * #### Notes
112 * This method is invoked immediately after the layout is installed
113 * on the parent widget.
114 *
115 * The default implementation reparents all of the widgets to the
116 * layout parent widget.
117 *
118 * Subclasses should reimplement this method and attach the child
119 * widget nodes to the parent widget's node.
120 */
121 protected init(): void;
122 /**
123 * A message handler invoked on a `'resize'` message.
124 *
125 * #### Notes
126 * The layout should ensure that its widgets are resized according
127 * to the specified layout space, and that they are sent a `'resize'`
128 * message if appropriate.
129 *
130 * The default implementation of this method sends an `UnknownSize`
131 * resize message to all widgets.
132 *
133 * This may be reimplemented by subclasses as needed.
134 */
135 protected onResize(msg: Widget.ResizeMessage): void;
136 /**
137 * A message handler invoked on an `'update-request'` message.
138 *
139 * #### Notes
140 * The layout should ensure that its widgets are resized according
141 * to the available layout space, and that they are sent a `'resize'`
142 * message if appropriate.
143 *
144 * The default implementation of this method sends an `UnknownSize`
145 * resize message to all widgets.
146 *
147 * This may be reimplemented by subclasses as needed.
148 */
149 protected onUpdateRequest(msg: Message): void;
150 /**
151 * A message handler invoked on a `'before-attach'` message.
152 *
153 * #### Notes
154 * The default implementation of this method forwards the message
155 * to all widgets. It assumes all widget nodes are attached to the
156 * parent widget node.
157 *
158 * This may be reimplemented by subclasses as needed.
159 */
160 protected onBeforeAttach(msg: Message): void;
161 /**
162 * A message handler invoked on an `'after-attach'` message.
163 *
164 * #### Notes
165 * The default implementation of this method forwards the message
166 * to all widgets. It assumes all widget nodes are attached to the
167 * parent widget node.
168 *
169 * This may be reimplemented by subclasses as needed.
170 */
171 protected onAfterAttach(msg: Message): void;
172 /**
173 * A message handler invoked on a `'before-detach'` message.
174 *
175 * #### Notes
176 * The default implementation of this method forwards the message
177 * to all widgets. It assumes all widget nodes are attached to the
178 * parent widget node.
179 *
180 * This may be reimplemented by subclasses as needed.
181 */
182 protected onBeforeDetach(msg: Message): void;
183 /**
184 * A message handler invoked on an `'after-detach'` message.
185 *
186 * #### Notes
187 * The default implementation of this method forwards the message
188 * to all widgets. It assumes all widget nodes are attached to the
189 * parent widget node.
190 *
191 * This may be reimplemented by subclasses as needed.
192 */
193 protected onAfterDetach(msg: Message): void;
194 /**
195 * A message handler invoked on a `'before-show'` message.
196 *
197 * #### Notes
198 * The default implementation of this method forwards the message to
199 * all non-hidden widgets. It assumes all widget nodes are attached
200 * to the parent widget node.
201 *
202 * This may be reimplemented by subclasses as needed.
203 */
204 protected onBeforeShow(msg: Message): void;
205 /**
206 * A message handler invoked on an `'after-show'` message.
207 *
208 * #### Notes
209 * The default implementation of this method forwards the message to
210 * all non-hidden widgets. It assumes all widget nodes are attached
211 * to the parent widget node.
212 *
213 * This may be reimplemented by subclasses as needed.
214 */
215 protected onAfterShow(msg: Message): void;
216 /**
217 * A message handler invoked on a `'before-hide'` message.
218 *
219 * #### Notes
220 * The default implementation of this method forwards the message to
221 * all non-hidden widgets. It assumes all widget nodes are attached
222 * to the parent widget node.
223 *
224 * This may be reimplemented by subclasses as needed.
225 */
226 protected onBeforeHide(msg: Message): void;
227 /**
228 * A message handler invoked on an `'after-hide'` message.
229 *
230 * #### Notes
231 * The default implementation of this method forwards the message to
232 * all non-hidden widgets. It assumes all widget nodes are attached
233 * to the parent widget node.
234 *
235 * This may be reimplemented by subclasses as needed.
236 */
237 protected onAfterHide(msg: Message): void;
238 /**
239 * A message handler invoked on a `'child-removed'` message.
240 *
241 * #### Notes
242 * This will remove the child widget from the layout.
243 *
244 * Subclasses should **not** typically reimplement this method.
245 */
246 protected onChildRemoved(msg: Widget.ChildMessage): void;
247 /**
248 * A message handler invoked on a `'fit-request'` message.
249 *
250 * #### Notes
251 * The default implementation of this handler is a no-op.
252 */
253 protected onFitRequest(msg: Message): void;
254 /**
255 * A message handler invoked on a `'child-shown'` message.
256 *
257 * #### Notes
258 * The default implementation of this handler is a no-op.
259 */
260 protected onChildShown(msg: Widget.ChildMessage): void;
261 /**
262 * A message handler invoked on a `'child-hidden'` message.
263 *
264 * #### Notes
265 * The default implementation of this handler is a no-op.
266 */
267 protected onChildHidden(msg: Widget.ChildMessage): void;
268 private _disposed;
269 private _fitPolicy;
270 private _parent;
271}
272/**
273 * The namespace for the `Layout` class statics.
274 */
275export declare namespace Layout {
276 /**
277 * A type alias for the layout fit policy.
278 *
279 * #### Notes
280 * The fit policy controls the computed size constraints which are
281 * applied to the parent widget by the layout.
282 *
283 * Some layout implementations may ignore the fit policy.
284 */
285 type FitPolicy = /**
286 * No size constraint will be applied to the parent widget.
287 */ 'set-no-constraint'
288 /**
289 * The computed min size will be applied to the parent widget.
290 */
291 | 'set-min-size';
292 /**
293 * An options object for initializing a layout.
294 */
295 interface IOptions {
296 /**
297 * The fit policy for the layout.
298 *
299 * The default is `'set-min-size'`.
300 */
301 fitPolicy?: FitPolicy;
302 }
303 /**
304 * A type alias for the horizontal alignment of a widget.
305 */
306 type HorizontalAlignment = 'left' | 'center' | 'right';
307 /**
308 * A type alias for the vertical alignment of a widget.
309 */
310 type VerticalAlignment = 'top' | 'center' | 'bottom';
311 /**
312 * Get the horizontal alignment for a widget.
313 *
314 * @param widget - The widget of interest.
315 *
316 * @returns The horizontal alignment for the widget.
317 *
318 * #### Notes
319 * If the layout width allocated to a widget is larger than its max
320 * width, the horizontal alignment controls how the widget is placed
321 * within the extra horizontal space.
322 *
323 * If the allocated width is less than the widget's max width, the
324 * horizontal alignment has no effect.
325 *
326 * Some layout implementations may ignore horizontal alignment.
327 */
328 function getHorizontalAlignment(widget: Widget): HorizontalAlignment;
329 /**
330 * Set the horizontal alignment for a widget.
331 *
332 * @param widget - The widget of interest.
333 *
334 * @param value - The value for the horizontal alignment.
335 *
336 * #### Notes
337 * If the layout width allocated to a widget is larger than its max
338 * width, the horizontal alignment controls how the widget is placed
339 * within the extra horizontal space.
340 *
341 * If the allocated width is less than the widget's max width, the
342 * horizontal alignment has no effect.
343 *
344 * Some layout implementations may ignore horizontal alignment.
345 *
346 * Changing the horizontal alignment will post an `update-request`
347 * message to widget's parent, provided the parent has a layout
348 * installed.
349 */
350 function setHorizontalAlignment(widget: Widget, value: HorizontalAlignment): void;
351 /**
352 * Get the vertical alignment for a widget.
353 *
354 * @param widget - The widget of interest.
355 *
356 * @returns The vertical alignment for the widget.
357 *
358 * #### Notes
359 * If the layout height allocated to a widget is larger than its max
360 * height, the vertical alignment controls how the widget is placed
361 * within the extra vertical space.
362 *
363 * If the allocated height is less than the widget's max height, the
364 * vertical alignment has no effect.
365 *
366 * Some layout implementations may ignore vertical alignment.
367 */
368 function getVerticalAlignment(widget: Widget): VerticalAlignment;
369 /**
370 * Set the vertical alignment for a widget.
371 *
372 * @param widget - The widget of interest.
373 *
374 * @param value - The value for the vertical alignment.
375 *
376 * #### Notes
377 * If the layout height allocated to a widget is larger than its max
378 * height, the vertical alignment controls how the widget is placed
379 * within the extra vertical space.
380 *
381 * If the allocated height is less than the widget's max height, the
382 * vertical alignment has no effect.
383 *
384 * Some layout implementations may ignore vertical alignment.
385 *
386 * Changing the horizontal alignment will post an `update-request`
387 * message to widget's parent, provided the parent has a layout
388 * installed.
389 */
390 function setVerticalAlignment(widget: Widget, value: VerticalAlignment): void;
391}
392/**
393 * An object which assists in the absolute layout of widgets.
394 *
395 * #### Notes
396 * This class is useful when implementing a layout which arranges its
397 * widgets using absolute positioning.
398 *
399 * This class is used by nearly all of the built-in lumino layouts.
400 */
401export declare class LayoutItem implements IDisposable {
402 /**
403 * Construct a new layout item.
404 *
405 * @param widget - The widget to be managed by the item.
406 *
407 * #### Notes
408 * The widget will be set to absolute positioning.
409 */
410 constructor(widget: Widget);
411 /**
412 * Dispose of the the layout item.
413 *
414 * #### Notes
415 * This will reset the positioning of the widget.
416 */
417 dispose(): void;
418 /**
419 * The widget managed by the layout item.
420 */
421 readonly widget: Widget;
422 /**
423 * The computed minimum width of the widget.
424 *
425 * #### Notes
426 * This value can be updated by calling the `fit` method.
427 */
428 readonly minWidth: number;
429 /**
430 * The computed minimum height of the widget.
431 *
432 * #### Notes
433 * This value can be updated by calling the `fit` method.
434 */
435 readonly minHeight: number;
436 /**
437 * The computed maximum width of the widget.
438 *
439 * #### Notes
440 * This value can be updated by calling the `fit` method.
441 */
442 readonly maxWidth: number;
443 /**
444 * The computed maximum height of the widget.
445 *
446 * #### Notes
447 * This value can be updated by calling the `fit` method.
448 */
449 readonly maxHeight: number;
450 /**
451 * Whether the layout item is disposed.
452 */
453 readonly isDisposed: boolean;
454 /**
455 * Whether the managed widget is hidden.
456 */
457 readonly isHidden: boolean;
458 /**
459 * Whether the managed widget is visible.
460 */
461 readonly isVisible: boolean;
462 /**
463 * Whether the managed widget is attached.
464 */
465 readonly isAttached: boolean;
466 /**
467 * Update the computed size limits of the managed widget.
468 */
469 fit(): void;
470 /**
471 * Update the position and size of the managed widget.
472 *
473 * @param left - The left edge position of the layout box.
474 *
475 * @param top - The top edge position of the layout box.
476 *
477 * @param width - The width of the layout box.
478 *
479 * @param height - The height of the layout box.
480 */
481 update(left: number, top: number, width: number, height: number): void;
482 private _top;
483 private _left;
484 private _width;
485 private _height;
486 private _minWidth;
487 private _minHeight;
488 private _maxWidth;
489 private _maxHeight;
490 private _disposed;
491}
492//# sourceMappingURL=layout.d.ts.map
\No newline at end of file