commit - a3b5b286f3bc8991a6fa36dbcadb098b5e4b0be2
commit + 2d01cf0a86e0e42ff032a682edae1b28675f49a8
blob - af3a0824989abaeafa2af19497dc2ebe1e3dab27
blob + 0106a7c1cc9ef90a3965a6743bf1fa20259b7b28
--- README
+++ README
libaui - A User Interface Library
-Minimal, portable and simple. This library is
-inspired by Tk.
-
-FAQ
-
-Q: Why?
-A: Why not?
+Minimal, portable and simple. This library is inspired by Tk.
+The goal of this library is not to be competing with popular
+UI toolkits but rather offer a simple codebase that can be
+used for studying.
blob - b24b74b8223102c8100367fcaf6aea99fe427e4a
blob + 31b0fd16a57399bf1bdd828c8d96964bbfd23d13
--- aui.h
+++ aui.h
struct aui_packpar {
unsigned char anchor;
+#define AUI_FILL_NONE 0
+#define AUI_FILL_X 1
+#define AUI_FILL_Y 2
+#define AUI_FILL_BOTH 3
+ unsigned char fill;
#define AUI_SIDE_TOP 1
#define AUI_SIDE_RIGHT 2
#define AUI_SIDE_LEFT 3
blob - 920984852cc2190f7582bb59cff1b68acc2ee2ea
blob + ae2e2a9a978e050ed1cabb0be1cd48ac9a165227
--- layout.c
+++ layout.c
{
struct aui_container *con = (struct aui_container *)widget;
struct aui_widget *child;
- int dx, dy;
switch (con->layout_type) {
case AUI_LAYOUT_PLACE:
continue;
struct aui_placepar *par = &child->placepar;
+ int dx = 0, dy = 0;
struct aui_geometry geom = {
.x = widget->geom.x + child->placepar.x + widget->geom.width * child->placepar.relx,
/*
* As far as I'm aware of, Tk's pack is just a rectangle that shrinks
* depending on the side of the widget being added.
+ *
+ * The fill attribute is a bit tricky. You can set it to x, y and both
+ * but you have to keep in mind that x only works on side top and bottom
+ * and y works on side left and right.
*/
case AUI_LAYOUT_PACK: {
struct aui_geometry space = widget->in_ops->get_min_size(widget);
struct aui_geometry cgeom = child->in_ops->get_min_size(child);
switch (child->packpar.side) {
- case AUI_SIDE_TOP:
- cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width;
- cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height;
+ case AUI_SIDE_TOP:
+ cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width;
+ cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height;
+ switch (child->packpar.anchor) {
+ case AUI_ANCHOR_CENTER:
+ case AUI_ANCHOR_N:
+ case AUI_ANCHOR_S:
cgeom.x = space.x + space.width / 2 - cgeom.width / 2;
cgeom.y = space.y;
- space.y += cgeom.height;
- space.height -= cgeom.height;
break;
- case AUI_SIDE_LEFT:
- cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width;
- cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height;
+ case AUI_ANCHOR_NW:
+ case AUI_ANCHOR_SW:
+ case AUI_ANCHOR_W:
cgeom.x = space.x;
+ cgeom.y = space.y;
+ break;
+ case AUI_ANCHOR_NE:
+ case AUI_ANCHOR_SE:
+ case AUI_ANCHOR_E:
+ cgeom.x = space.x + space.width - cgeom.width;
+ cgeom.y = space.y;
+ break;
+ default:
+ break;
+ }
+ space.y += cgeom.height;
+ space.height -= cgeom.height;
+ break;
+ case AUI_SIDE_LEFT:
+ cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width;
+ cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height;
+ cgeom.x = space.x;
+ cgeom.y = space.y + space.height / 2 - cgeom.height / 2;
+ switch (child->packpar.anchor) {
+ case AUI_ANCHOR_CENTER:
+ case AUI_ANCHOR_E:
+ case AUI_ANCHOR_W:
+ cgeom.x = space.x;
cgeom.y = space.y + space.height / 2 - cgeom.height / 2;
- space.width -= cgeom.width;
- space.x += cgeom.width;
break;
- case AUI_SIDE_RIGHT:
- cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width;
- cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height;
+ case AUI_ANCHOR_N:
+ case AUI_ANCHOR_NE:
+ case AUI_ANCHOR_NW:
+ cgeom.x = space.x;
+ cgeom.y = space.y;
+ break;
+ case AUI_ANCHOR_S:
+ case AUI_ANCHOR_SE:
+ case AUI_ANCHOR_SW:
+ cgeom.x = space.x;
+ cgeom.y = space.y + space.height - cgeom.height;
+ break;
+ default:
+ break;
+ }
+ space.width -= cgeom.width;
+ space.x += cgeom.width;
+ break;
+ case AUI_SIDE_RIGHT:
+ cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width;
+ cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height;
+ switch (child->packpar.anchor) {
+ case AUI_ANCHOR_CENTER:
+ case AUI_ANCHOR_E:
+ case AUI_ANCHOR_W:
cgeom.x = space.x + space.width - cgeom.width;
cgeom.y = space.y + space.height / 2 - cgeom.height / 2;
- space.width -= cgeom.width;
break;
- case AUI_SIDE_BOTTOM:
- cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width;
- cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height;
+ case AUI_ANCHOR_N:
+ case AUI_ANCHOR_NE:
+ case AUI_ANCHOR_NW:
+ cgeom.x = space.x + space.width - cgeom.width;
+ cgeom.y = space.y;
+ break;
+ case AUI_ANCHOR_S:
+ case AUI_ANCHOR_SE:
+ case AUI_ANCHOR_SW:
+ cgeom.x = space.x + space.width - cgeom.width;
+ cgeom.y = space.y + space.height - cgeom.height;
+ break;
+ default:
+ break;
+ }
+ space.width -= cgeom.width;
+ break;
+ case AUI_SIDE_BOTTOM:
+ cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width;
+ cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height;
+ switch (child->packpar.anchor) {
+ case AUI_ANCHOR_CENTER:
+ case AUI_ANCHOR_N:
+ case AUI_ANCHOR_S:
cgeom.x = space.x + space.width / 2 - cgeom.width / 2;
cgeom.y = space.y + space.height - cgeom.height;
- space.height -= cgeom.height;
break;
+ case AUI_ANCHOR_NW:
+ case AUI_ANCHOR_SW:
+ case AUI_ANCHOR_W:
+ cgeom.x = space.x;
+ cgeom.y = space.y + space.height - cgeom.height;
+ break;
+ case AUI_ANCHOR_NE:
+ case AUI_ANCHOR_SE:
+ case AUI_ANCHOR_E:
+ cgeom.x = space.x + space.width - cgeom.width;
+ cgeom.y = space.y + space.height - cgeom.height;
+ break;
default:
- continue;
+ break;
+ }
+ space.height -= cgeom.height;
+ break;
+ default:
+ continue;
}
child->in_ops->set_geometry(child, &cgeom);
}