UNPKG

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