diff options
| -rw-r--r-- | docs/LAYOUT.md | 35 | ||||
| -rw-r--r-- | docs/TODO.md | 23 | ||||
| -rw-r--r-- | src/saffron_widget.c | 4 |
3 files changed, 62 insertions, 0 deletions
diff --git a/docs/LAYOUT.md b/docs/LAYOUT.md new file mode 100644 index 0000000..e4992c7 --- /dev/null +++ b/docs/LAYOUT.md @@ -0,0 +1,35 @@ +# Saffron layout system + +> Note: at this moment, these docs exist solely for me, the maintainer, to place down ideas and to help with the massive task of architecting a UI framework and layout engine. This message will be removed when these docs are ready. + +## Size requests + +A widget's width and height are not commands to the layout engine. They are simply requests. The layout engine will attempt to give each widget its required size, but if the window is too small, the sizes will be reduced. Widgets must be ready to handle rendering at any size. + +### Size requests based on size modes + +- `SAFFRON_SIZE_FIXED`: The widget will take only the required space on this axis, but will take less if needed. +- `SAFFRON_SIZE_STRETCH`: The widget has a minimum required size on this axis, and will take as much extra space as possible. Can take less if needed. +- `SAFFRON_SIZE_SCALE`: The widget will fill the available space while preserving its aspect ratio, even if it sacrifices the requested size. + +## Layout pass + +1. Calculate inner area +2. Position children sequentially (including child boxes), horizontally or vertically +3. Recurse into child boxes + +Children are positioned before recursion. This ensures that child boxes have already been positioned and have set bounds before attempting to layout their children, keeping layouts responsive. + +## pixel_perfect + +If a widget has the attribute `pixel_perfect` set to `true`, it is excluded from layouting and must manage its own position and size. The layout engine will literally skip these widgets with a simple condition. + +## Spacing + +Spacing is added between children, not before the first or after the last. + +## Overflow + +Children never overflow outside the inner area (unless they have `pixel_perfect` set to `true`, because they are excluded from layouting). If total requested size exceeds available space, the layout engine will reduce children in size to make space. As mentioned above, widgets must be ready to handle any size, whether it is ridiculously small or ridiculously large. + +TODO for future: add scroll containers, in that case only they can overflow for scrolling diff --git a/docs/TODO.md b/docs/TODO.md new file mode 100644 index 0000000..09c918a --- /dev/null +++ b/docs/TODO.md @@ -0,0 +1,23 @@ +# Saffron TODO + +> Note: as mentioned in LAYOUT.md, these docs exist solely for me, the maintainer, to assist with the massive undertaking of creating a UI framework from scratch. This message will be removed then the docs are ready. + +## Layouting + +- Implement SCALE and STRETCH support instead of assuming FIXED +- Implement alignment support instead of defaulting to LEFT/TOP +- Implement scrollable boxes/containers + +## Widgets + +- Implement text widget +- Implement button widget +- Implement input widget +- Implement textfield widget + +## Examples + +- Add more tests and examples, for example: + - Calculator app + - Image viewer + - Todo list diff --git a/src/saffron_widget.c b/src/saffron_widget.c index 779253b..b673e48 100644 --- a/src/saffron_widget.c +++ b/src/saffron_widget.c @@ -66,6 +66,10 @@ void saffron_widget_add_child(SaffronWidget *parent, SaffronWidget *child) { parent->children = realloc(parent->children, sizeof(SaffronWidget*) * (parent->child_count + 1)); parent->children[parent->child_count] = child; parent->child_count++; + + if (parent->type == SAFFRON_WIDGET_BOX) { + saffron_box_layout((SaffronBox*)parent); + } } SaffronWidget* saffron_widget_hit_test(SaffronWidget* widget, int x, int y) { |
