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)
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;
}
}
+ /* 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)
button1 = gtk_button_new_with_label("Square");
button2 = gtk_button_new_with_label("Rectangle");
aspect_bin_set_body_widget(ASPECT_BIN(aspectbin), button1, 1);
- gtk_container_add(GTK_CONTAINER(aspectbin), button2);
+ ASPECT_BIN(aspectbin)->constrain = TRUE;
+ ASPECT_BIN(aspectbin)->align = 0.5;
+
+ gtk_container_add(GTK_CONTAINER(aspectbin), button2);
gtk_container_add(GTK_CONTAINER(window), aspectbin);
gtk_widget_show_all(window);