UNPKG

16 kBTypeScriptView Raw
1import { IIterable, IIterator } from '@phosphor/algorithm';
2import { IDisposable } from '@phosphor/disposable';
3import { Message } from '@phosphor/messaging';
4import { Widget } from './widget';
5/**
6 * An abstract base class for creating Phosphor 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 /**
287 * No size constraint will be applied to the parent widget.
288 */
289 'set-no-constraint' |
290 /**
291 * The computed min size will be applied to the parent widget.
292 */
293 'set-min-size');
294 /**
295 * An options object for initializing a layout.
296 */
297 interface IOptions {
298 /**
299 * The fit policy for the layout.
300 *
301 * The default is `'set-min-size'`.
302 */
303 fitPolicy?: FitPolicy;
304 }
305 /**
306 * A type alias for the horizontal alignment of a widget.
307 */
308 type HorizontalAlignment = 'left' | 'center' | 'right';
309 /**
310 * A type alias for the vertical alignment of a widget.
311 */
312 type VerticalAlignment = 'top' | 'center' | 'bottom';
313 /**
314 * Get the horizontal alignment for a widget.
315 *
316 * @param widget - The widget of interest.
317 *
318 * @returns The horizontal alignment for the widget.
319 *
320 * #### Notes
321 * If the layout width allocated to a widget is larger than its max
322 * width, the horizontal alignment controls how the widget is placed
323 * within the extra horizontal space.
324 *
325 * If the allocated width is less than the widget's max width, the
326 * horizontal alignment has no effect.
327 *
328 * Some layout implementations may ignore horizontal alignment.
329 */
330 function getHorizontalAlignment(widget: Widget): HorizontalAlignment;
331 /**
332 * Set the horizontal alignment for a widget.
333 *
334 * @param widget - The widget of interest.
335 *
336 * @param value - The value for the horizontal alignment.
337 *
338 * #### Notes
339 * If the layout width allocated to a widget is larger than its max
340 * width, the horizontal alignment controls how the widget is placed
341 * within the extra horizontal space.
342 *
343 * If the allocated width is less than the widget's max width, the
344 * horizontal alignment has no effect.
345 *
346 * Some layout implementations may ignore horizontal alignment.
347 *
348 * Changing the horizontal alignment will post an `update-request`
349 * message to widget's parent, provided the parent has a layout
350 * installed.
351 */
352 function setHorizontalAlignment(widget: Widget, value: HorizontalAlignment): void;
353 /**
354 * Get the vertical alignment for a widget.
355 *
356 * @param widget - The widget of interest.
357 *
358 * @returns The vertical alignment for the widget.
359 *
360 * #### Notes
361 * If the layout height allocated to a widget is larger than its max
362 * height, the vertical alignment controls how the widget is placed
363 * within the extra vertical space.
364 *
365 * If the allocated height is less than the widget's max height, the
366 * vertical alignment has no effect.
367 *
368 * Some layout implementations may ignore vertical alignment.
369 */
370 function getVerticalAlignment(widget: Widget): VerticalAlignment;
371 /**
372 * Set the vertical alignment for a widget.
373 *
374 * @param widget - The widget of interest.
375 *
376 * @param value - The value for the vertical alignment.
377 *
378 * #### Notes
379 * If the layout height allocated to a widget is larger than its max
380 * height, the vertical alignment controls how the widget is placed
381 * within the extra vertical space.
382 *
383 * If the allocated height is less than the widget's max height, the
384 * vertical alignment has no effect.
385 *
386 * Some layout implementations may ignore vertical alignment.
387 *
388 * Changing the horizontal alignment will post an `update-request`
389 * message to widget's parent, provided the parent has a layout
390 * installed.
391 */
392 function setVerticalAlignment(widget: Widget, value: VerticalAlignment): void;
393}
394/**
395 * An object which assists in the absolute layout of widgets.
396 *
397 * #### Notes
398 * This class is useful when implementing a layout which arranges its
399 * widgets using absolute positioning.
400 *
401 * This class is used by nearly all of the built-in Phosphor layouts.
402 */
403export declare class LayoutItem implements IDisposable {
404 /**
405 * Construct a new layout item.
406 *
407 * @param widget - The widget to be managed by the item.
408 *
409 * #### Notes
410 * The widget will be set to absolute positioning.
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 readonly 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 readonly 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 readonly 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 readonly maxHeight: number;
452 /**
453 * Whether the layout item is disposed.
454 */
455 readonly isDisposed: boolean;
456 /**
457 * Whether the managed widget is hidden.
458 */
459 readonly isHidden: boolean;
460 /**
461 * Whether the managed widget is visible.
462 */
463 readonly isVisible: boolean;
464 /**
465 * Whether the managed widget is attached.
466 */
467 readonly 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}