UNPKG

7.28 kBTypeScriptView Raw
1import { Message } from '@lumino/messaging';
2import { Layout } from './layout';
3import { Widget } from './widget';
4/**
5 * A layout which arranges its widgets in a grid.
6 */
7export declare class GridLayout extends Layout {
8 /**
9 * Construct a new grid layout.
10 *
11 * @param options - The options for initializing the layout.
12 */
13 constructor(options?: GridLayout.IOptions);
14 /**
15 * Dispose of the resources held by the layout.
16 */
17 dispose(): void;
18 /**
19 * Get the number of rows in the layout.
20 */
21 get rowCount(): number;
22 /**
23 * Set the number of rows in the layout.
24 *
25 * #### Notes
26 * The minimum row count is `1`.
27 */
28 set rowCount(value: number);
29 /**
30 * Get the number of columns in the layout.
31 */
32 get columnCount(): number;
33 /**
34 * Set the number of columns in the layout.
35 *
36 * #### Notes
37 * The minimum column count is `1`.
38 */
39 set columnCount(value: number);
40 /**
41 * Get the row spacing for the layout.
42 */
43 get rowSpacing(): number;
44 /**
45 * Set the row spacing for the layout.
46 */
47 set rowSpacing(value: number);
48 /**
49 * Get the column spacing for the layout.
50 */
51 get columnSpacing(): number;
52 /**
53 * Set the col spacing for the layout.
54 */
55 set columnSpacing(value: number);
56 /**
57 * Get the stretch factor for a specific row.
58 *
59 * @param index - The row index of interest.
60 *
61 * @returns The stretch factor for the row.
62 *
63 * #### Notes
64 * This returns `-1` if the index is out of range.
65 */
66 rowStretch(index: number): number;
67 /**
68 * Set the stretch factor for a specific row.
69 *
70 * @param index - The row index of interest.
71 *
72 * @param value - The stretch factor for the row.
73 *
74 * #### Notes
75 * This is a no-op if the index is out of range.
76 */
77 setRowStretch(index: number, value: number): void;
78 /**
79 * Get the stretch factor for a specific column.
80 *
81 * @param index - The column index of interest.
82 *
83 * @returns The stretch factor for the column.
84 *
85 * #### Notes
86 * This returns `-1` if the index is out of range.
87 */
88 columnStretch(index: number): number;
89 /**
90 * Set the stretch factor for a specific column.
91 *
92 * @param index - The column index of interest.
93 *
94 * @param value - The stretch factor for the column.
95 *
96 * #### Notes
97 * This is a no-op if the index is out of range.
98 */
99 setColumnStretch(index: number, value: number): void;
100 /**
101 * Create an iterator over the widgets in the layout.
102 *
103 * @returns A new iterator over the widgets in the layout.
104 */
105 [Symbol.iterator](): IterableIterator<Widget>;
106 /**
107 * Add a widget to the grid layout.
108 *
109 * @param widget - The widget to add to the layout.
110 *
111 * #### Notes
112 * If the widget is already contained in the layout, this is no-op.
113 */
114 addWidget(widget: Widget): void;
115 /**
116 * Remove a widget from the grid layout.
117 *
118 * @param widget - The widget to remove from the layout.
119 *
120 * #### Notes
121 * A widget is automatically removed from the layout when its `parent`
122 * is set to `null`. This method should only be invoked directly when
123 * removing a widget from a layout which has yet to be installed on a
124 * parent widget.
125 *
126 * This method does *not* modify the widget's `parent`.
127 */
128 removeWidget(widget: Widget): void;
129 /**
130 * Perform layout initialization which requires the parent widget.
131 */
132 protected init(): void;
133 /**
134 * Attach a widget to the parent's DOM node.
135 *
136 * @param widget - The widget to attach to the parent.
137 */
138 protected attachWidget(widget: Widget): void;
139 /**
140 * Detach a widget from the parent's DOM node.
141 *
142 * @param widget - The widget to detach from the parent.
143 */
144 protected detachWidget(widget: Widget): void;
145 /**
146 * A message handler invoked on a `'before-show'` message.
147 */
148 protected onBeforeShow(msg: Message): void;
149 /**
150 * A message handler invoked on a `'before-attach'` message.
151 */
152 protected onBeforeAttach(msg: Message): void;
153 /**
154 * A message handler invoked on a `'child-shown'` message.
155 */
156 protected onChildShown(msg: Widget.ChildMessage): void;
157 /**
158 * A message handler invoked on a `'child-hidden'` message.
159 */
160 protected onChildHidden(msg: Widget.ChildMessage): void;
161 /**
162 * A message handler invoked on a `'resize'` message.
163 */
164 protected onResize(msg: Widget.ResizeMessage): void;
165 /**
166 * A message handler invoked on an `'update-request'` message.
167 */
168 protected onUpdateRequest(msg: Message): void;
169 /**
170 * A message handler invoked on a `'fit-request'` message.
171 */
172 protected onFitRequest(msg: Message): void;
173 /**
174 * Fit the layout to the total size required by the widgets.
175 */
176 private _fit;
177 /**
178 * Update the layout position and size of the widgets.
179 *
180 * The parent offset dimensions should be `-1` if unknown.
181 */
182 private _update;
183 private _dirty;
184 private _rowSpacing;
185 private _columnSpacing;
186 private _items;
187 private _rowStarts;
188 private _columnStarts;
189 private _rowSizers;
190 private _columnSizers;
191 private _box;
192}
193/**
194 * The namespace for the `GridLayout` class statics.
195 */
196export declare namespace GridLayout {
197 /**
198 * An options object for initializing a grid layout.
199 */
200 interface IOptions extends Layout.IOptions {
201 /**
202 * The initial row count for the layout.
203 *
204 * The default is `1`.
205 */
206 rowCount?: number;
207 /**
208 * The initial column count for the layout.
209 *
210 * The default is `1`.
211 */
212 columnCount?: number;
213 /**
214 * The spacing between rows in the layout.
215 *
216 * The default is `4`.
217 */
218 rowSpacing?: number;
219 /**
220 * The spacing between columns in the layout.
221 *
222 * The default is `4`.
223 */
224 columnSpacing?: number;
225 }
226 /**
227 * An object which holds the cell configuration for a widget.
228 */
229 interface ICellConfig {
230 /**
231 * The row index for the widget.
232 */
233 readonly row: number;
234 /**
235 * The column index for the widget.
236 */
237 readonly column: number;
238 /**
239 * The row span for the widget.
240 */
241 readonly rowSpan: number;
242 /**
243 * The column span for the widget.
244 */
245 readonly columnSpan: number;
246 }
247 /**
248 * Get the cell config for the given widget.
249 *
250 * @param widget - The widget of interest.
251 *
252 * @returns The cell config for the widget.
253 */
254 function getCellConfig(widget: Widget): ICellConfig;
255 /**
256 * Set the cell config for the given widget.
257 *
258 * @param widget - The widget of interest.
259 *
260 * @param value - The value for the cell config.
261 */
262 function setCellConfig(widget: Widget, value: Partial<ICellConfig>): void;
263}