diff options
| author | Julian Hurst <julian.hurst92@gmail.com> | 2022-05-16 00:35:21 +0200 |
|---|---|---|
| committer | Julian Hurst <julian.hurst92@gmail.com> | 2022-05-16 00:35:21 +0200 |
| commit | 9740eee555cac43cc27e08a39a38e09a96ecb002 (patch) | |
| tree | 555c0fd89906364a8f527c8f1c72ab81b8303adf /libui/layout/layout.ha | |
| parent | 35639332a5dc8e9b26e8299c999940a9b6ca2ddb (diff) | |
| download | ilhare-9740eee555cac43cc27e08a39a38e09a96ecb002.tar.gz | |
Add layout and a common widget type
Diffstat (limited to 'libui/layout/layout.ha')
| -rw-r--r-- | libui/layout/layout.ha | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libui/layout/layout.ha b/libui/layout/layout.ha new file mode 100644 index 0000000..ef6bf71 --- /dev/null +++ b/libui/layout/layout.ha @@ -0,0 +1,42 @@ +use libui::widget; +use io; +use unix::tty; +use fmt; +use os; + +export type layout = struct { + widgets: []*widget::widget, +}; + +// Create and return a new layout from a list of widgets. [[finishall]] must be +// called to properly free the widget's nad layout's resources. +export fn newlayout(widgets: *widget::widget...) layout = { + return layout { + widgets = widgets, + }; +}; + +// Display all the widgets contained in the given layout. +export fn print(layout: layout) (void | widget::error) = { + for (let i = 0z; i < len(layout.widgets); i += 1) { + match (layout.widgets[i].print) { + case null => + return; + case let f: *widget::print => + f(layout.widgets[i])?; + }; + }; +}; + +// Finish and free the widgets in the given layout. +export fn finishall(layout: *layout) void = { + for (let i = 0z; i < len(layout.widgets); i += 1) { + match (layout.widgets[i].finish) { + case null => + return; + case let f: *widget::finish => + f(layout.widgets[i]); + }; + }; + free(layout.widgets); +}; |
