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.
2022-05-02 13:37:11 +00:00
|
|
|
/*
|
|
|
|
* Helper function from the dialog.h mechanism.
|
|
|
|
*/
|
|
|
|
|
2022-07-05 17:11:54 +00:00
|
|
|
#include "putty.h"
|
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.
2022-05-02 13:37:11 +00:00
|
|
|
#include "misc.h"
|
|
|
|
#include "dialog.h"
|
|
|
|
|
|
|
|
void ctrlset_normalise_aligns(struct controlset *s)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The algorithm in here is quadratic time. Never on very much data, but
|
|
|
|
* even so, let's avoid bothering to use it where possible. In most
|
|
|
|
* controlsets, there's no use of align_next_to in any case, so we have
|
|
|
|
* nothing to do.
|
|
|
|
*/
|
|
|
|
for (size_t j = 0; j < s->ncontrols; j++)
|
|
|
|
if (s->ctrls[j]->align_next_to)
|
|
|
|
goto must_do_something;
|
|
|
|
/* If we fell out of this loop, there's nothing to do here */
|
|
|
|
return;
|
|
|
|
must_do_something:;
|
|
|
|
|
|
|
|
size_t *idx = snewn(s->ncontrols, size_t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Follow align_next_to links to identify, for each control, the least
|
|
|
|
* index within this controlset of things it's linked to. That way,
|
|
|
|
* controls with the same idx[j] will be in the same alignment class.
|
|
|
|
*/
|
|
|
|
for (size_t j = 0; j < s->ncontrols; j++) {
|
|
|
|
dlgcontrol *c = s->ctrls[j];
|
|
|
|
idx[j] = j;
|
|
|
|
if (c->align_next_to) {
|
|
|
|
for (size_t k = 0; k < j; k++) {
|
|
|
|
if (s->ctrls[k] == c->align_next_to) {
|
|
|
|
idx[j] = idx[k];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Having done that, re-link each control to the most recent one in its
|
|
|
|
* class, so that the links form a backward linked list.
|
|
|
|
*/
|
|
|
|
for (size_t j = 0; j < s->ncontrols; j++) {
|
|
|
|
dlgcontrol *c = s->ctrls[j];
|
|
|
|
c->align_next_to = NULL;
|
|
|
|
for (size_t k = j; k-- > 0 ;) {
|
|
|
|
if (idx[k] == idx[j]) {
|
|
|
|
c->align_next_to = s->ctrls[k];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sfree(idx);
|
|
|
|
}
|