X-Git-Url: http://git.draconx.ca/gitweb/aspectbin.git/blobdiff_plain/ae774d97cc05fdcc8baf5b916be66f99f4f33a77..e6565598a4a1c371cfc091c00ba905b5e96ecc15:/aspectbin.c diff --git a/aspectbin.c b/aspectbin.c index 339c8ae..c9fe6a5 100644 --- a/aspectbin.c +++ b/aspectbin.c @@ -10,8 +10,10 @@ G_DEFINE_TYPE(AspectBin, aspect_bin, GTK_TYPE_BIN) static void aspect_bin_init(AspectBin *ab) { - ab->child = NULL; - ab->ratio = 1; + ab->child = NULL; + ab->ratio = 1; + ab->constrain = FALSE; + ab->align = 0; } static void aspect_bin_class_init(AspectBinClass *abc) @@ -94,6 +96,7 @@ aspect_bin_size_allocate(GtkWidget *widget, GtkAllocation *allocation) GtkRequisition creq = {0}; GtkAllocation csize = {0}, asize = {0}; + /* First find the best fit for the constrained child. */ if (abin->child && GTK_WIDGET_VISIBLE(abin->child)) { asize.height = allocation->height; asize.width = asize.height * abin->ratio + 0.5; @@ -104,20 +107,27 @@ aspect_bin_size_allocate(GtkWidget *widget, GtkAllocation *allocation) } } + /* Now try to fit the other child. */ if (bin->child && GTK_WIDGET_VISIBLE(bin->child)) { gtk_widget_get_child_requisition(bin->child, &creq); if (allocation->width - asize.width < creq.width) { + /* It didn't fit, squish the constrained guy. */ asize.width = allocation->width - creq.width; asize.height = asize.width / abin->ratio + 0.5; } - csize.width = allocation->width - asize.width; - csize.height = allocation->height; + csize.width = allocation->width - asize.width; + csize.height = MIN(allocation->height, creq.height); + if (abin->constrain) { + csize.height = MAX(csize.height, asize.height); + } csize.x = asize.width; - csize.y = 0; } + csize.y = (allocation->height - csize.height) * abin->align + 0.5; + asize.y = (allocation->height - asize.height) * abin->align + 0.5; + if (bin->child) gtk_widget_size_allocate(bin->child, &csize); if (abin->child)