mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-06 14:02:47 -05:00
Improve the align_next_to mechanism.
Various alignments I want to do in the host CA box have shown up deficiencies in this system, so I've reworked it a bit. Firstly, you can now specify more than two controls to be tied together with an align_next_to (e.g. multiple checkboxes alongside something else). Secondly, as well as forcing the controls to be the same height as each other, the layout algorithm will also move the later controls further _downward_, so that their top y positions also line up. Until now that hasn't been necessary, because they lined up already. In the GTK implementation of this via the Columns class, I've renamed 'columns_force_same_height' to 'columns_align_next_to', and similarly for some of the internal fields, since the latter change makes the previous names a misnomer. In the Windows implementation, I found it most convenient to set this up by following a linked list of align_next_to fields backwards. But it won't always be convenient to initialise them that way, so I've also written a crude normaliser that will rewrite those links into a canonical form. But I only call that on Windows; it's unnecessary in GTK, where the Columns class provides plenty of per-widget extra storage so I just keep each alignment class as a circular list.
This commit is contained in:
@ -332,7 +332,6 @@ static void columns_remove(GtkContainer *container, GtkWidget *widget)
|
||||
ColumnsChild *child;
|
||||
GtkWidget *childw;
|
||||
GList *children;
|
||||
bool was_visible;
|
||||
|
||||
g_return_if_fail(container != NULL);
|
||||
g_return_if_fail(IS_COLUMNS(container));
|
||||
@ -346,23 +345,28 @@ static void columns_remove(GtkContainer *container, GtkWidget *widget)
|
||||
if (child->widget != widget)
|
||||
continue;
|
||||
|
||||
was_visible = gtk_widget_get_visible(widget);
|
||||
bool need_layout = false;
|
||||
if (gtk_widget_get_visible(widget))
|
||||
need_layout = true;
|
||||
gtk_widget_unparent(widget);
|
||||
cols->children = g_list_remove_link(cols->children, children);
|
||||
g_list_free(children);
|
||||
|
||||
if (child->same_height_as) {
|
||||
g_return_if_fail(child->same_height_as->same_height_as == child);
|
||||
child->same_height_as->same_height_as = NULL;
|
||||
if (gtk_widget_get_visible(child->same_height_as->widget))
|
||||
gtk_widget_queue_resize(GTK_WIDGET(container));
|
||||
}
|
||||
/* Unlink this widget from its valign list, and if anything
|
||||
* else on the list is still visible, ensure we recompute our
|
||||
* layout */
|
||||
for (ColumnsChild *ch = child->valign_next; ch != child;
|
||||
ch = ch->valign_next)
|
||||
if (gtk_widget_get_visible(ch->widget))
|
||||
need_layout = true;
|
||||
child->valign_next->valign_prev = child->valign_prev;
|
||||
child->valign_prev->valign_next = child->valign_next;
|
||||
|
||||
if (cols->vexpand == child)
|
||||
cols->vexpand = NULL;
|
||||
|
||||
g_free(child);
|
||||
if (was_visible)
|
||||
if (need_layout)
|
||||
gtk_widget_queue_resize(GTK_WIDGET(container));
|
||||
break;
|
||||
}
|
||||
@ -465,7 +469,8 @@ void columns_add(Columns *cols, GtkWidget *child,
|
||||
childdata->colstart = colstart;
|
||||
childdata->colspan = colspan;
|
||||
childdata->force_left = false;
|
||||
childdata->same_height_as = NULL;
|
||||
childdata->valign_next = childdata;
|
||||
childdata->valign_prev = childdata;
|
||||
childdata->percentages = NULL;
|
||||
|
||||
cols->children = g_list_append(cols->children, childdata);
|
||||
@ -516,7 +521,7 @@ void columns_force_left_align(Columns *cols, GtkWidget *widget)
|
||||
gtk_widget_queue_resize(GTK_WIDGET(cols));
|
||||
}
|
||||
|
||||
void columns_force_same_height(Columns *cols, GtkWidget *cw1, GtkWidget *cw2)
|
||||
void columns_align_next_to(Columns *cols, GtkWidget *cw1, GtkWidget *cw2)
|
||||
{
|
||||
ColumnsChild *child1, *child2;
|
||||
|
||||
@ -530,8 +535,13 @@ void columns_force_same_height(Columns *cols, GtkWidget *cw1, GtkWidget *cw2)
|
||||
child2 = columns_find_child(cols, cw2);
|
||||
g_return_if_fail(child2 != NULL);
|
||||
|
||||
child1->same_height_as = child2;
|
||||
child2->same_height_as = child1;
|
||||
ColumnsChild *child1prev = child1->valign_prev;
|
||||
ColumnsChild *child2prev = child2->valign_prev;
|
||||
child1prev->valign_next = child2;
|
||||
child2->valign_prev = child1prev;
|
||||
child2prev->valign_next = child1;
|
||||
child1->valign_prev = child2prev;
|
||||
|
||||
if (gtk_widget_get_visible(cw1) || gtk_widget_get_visible(cw2))
|
||||
gtk_widget_queue_resize(GTK_WIDGET(cols));
|
||||
}
|
||||
@ -843,8 +853,9 @@ static gint columns_compute_height(Columns *cols, widget_dim_fn_t get_height)
|
||||
continue;
|
||||
|
||||
childheight = get_height(child);
|
||||
if (child->same_height_as) {
|
||||
gint childheight2 = get_height(child->same_height_as);
|
||||
for (ColumnsChild *ch = child->valign_next; ch != child;
|
||||
ch = ch->valign_next) {
|
||||
gint childheight2 = get_height(ch);
|
||||
if (childheight < childheight2)
|
||||
childheight = childheight2;
|
||||
}
|
||||
@ -902,6 +913,11 @@ static void columns_alloc_vert(Columns *cols, gint ourheight,
|
||||
colypos = g_new(gint, 1);
|
||||
colypos[0] = 0;
|
||||
|
||||
for (children = cols->children;
|
||||
children && (child = children->data);
|
||||
children = children->next)
|
||||
child->visited = false;
|
||||
|
||||
for (children = cols->children;
|
||||
children && (child = children->data);
|
||||
children = children->next) {
|
||||
@ -922,14 +938,19 @@ static void columns_alloc_vert(Columns *cols, gint ourheight,
|
||||
if (!gtk_widget_get_visible(child->widget))
|
||||
continue;
|
||||
|
||||
int ymin = 0;
|
||||
|
||||
realheight = get_height(child);
|
||||
if (child == cols->vexpand)
|
||||
realheight += vexpand_extra;
|
||||
fakeheight = realheight;
|
||||
if (child->same_height_as) {
|
||||
gint childheight2 = get_height(child->same_height_as);
|
||||
for (ColumnsChild *ch = child->valign_next; ch != child;
|
||||
ch = ch->valign_next) {
|
||||
gint childheight2 = get_height(ch);
|
||||
if (fakeheight < childheight2)
|
||||
fakeheight = childheight2;
|
||||
if (ch->visited && ymin < ch->y)
|
||||
ymin = ch->y;
|
||||
}
|
||||
colspan = child->colspan ? child->colspan : ncols-child->colstart;
|
||||
|
||||
@ -943,13 +964,14 @@ static void columns_alloc_vert(Columns *cols, gint ourheight,
|
||||
{
|
||||
int topy, boty;
|
||||
|
||||
topy = 0;
|
||||
topy = ymin;
|
||||
for (i = 0; i < colspan; i++) {
|
||||
if (topy < colypos[child->colstart+i])
|
||||
topy = colypos[child->colstart+i];
|
||||
}
|
||||
child->y = topy + fakeheight/2 - realheight/2;
|
||||
child->h = realheight;
|
||||
child->visited = true;
|
||||
boty = topy + fakeheight + cols->spacing;
|
||||
for (i = 0; i < colspan; i++) {
|
||||
colypos[child->colstart+i] = boty;
|
||||
|
Reference in New Issue
Block a user