paned: Compute the right handle size

Testcase included

Fixes #4469
This commit is contained in:
Benjamin Otte 2021-11-21 01:46:32 +01:00
parent 170bc0a8de
commit c025bc5098
5 changed files with 134 additions and 8 deletions

View File

@ -1160,7 +1160,7 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget,
int *natural) int *natural)
{ {
GtkPaned *paned = GTK_PANED (widget); GtkPaned *paned = GTK_PANED (widget);
int for_start_child, for_end_child; int for_start_child, for_end_child, for_handle;
int child_min, child_nat; int child_min, child_nat;
if (size > -1 && if (size > -1 &&
@ -1168,22 +1168,21 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget,
paned->end_child && gtk_widget_get_visible (paned->end_child)) paned->end_child && gtk_widget_get_visible (paned->end_child))
{ {
int start_child_req, end_child_req; int start_child_req, end_child_req;
int handle_size;
gtk_widget_measure (paned->handle_widget, gtk_widget_measure (paned->handle_widget,
OPPOSITE_ORIENTATION (paned->orientation), paned->orientation,
-1, -1,
NULL, &handle_size, NULL, &for_handle,
NULL, NULL); NULL, NULL);
gtk_widget_measure (paned->start_child, paned->orientation, -1, &start_child_req, NULL, NULL, NULL); gtk_widget_measure (paned->start_child, paned->orientation, -1, &start_child_req, NULL, NULL, NULL);
gtk_widget_measure (paned->end_child, paned->orientation, -1, &end_child_req, NULL, NULL, NULL); gtk_widget_measure (paned->end_child, paned->orientation, -1, &end_child_req, NULL, NULL, NULL);
gtk_paned_compute_position (paned, gtk_paned_compute_position (paned,
size - handle_size, start_child_req, end_child_req, size - for_handle, start_child_req, end_child_req,
NULL, NULL, &for_start_child); NULL, NULL, &for_start_child);
for_end_child = size - for_start_child - handle_size; for_end_child = size - for_start_child - for_handle;
if (paned->shrink_start_child) if (paned->shrink_start_child)
for_start_child = MAX (start_child_req, for_start_child); for_start_child = MAX (start_child_req, for_start_child);
@ -1194,6 +1193,7 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget,
{ {
for_start_child = size; for_start_child = size;
for_end_child = size; for_end_child = size;
for_handle = -1;
} }
*minimum = *natural = 0; *minimum = *natural = 0;
@ -1202,7 +1202,7 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget,
{ {
gtk_widget_measure (paned->start_child, gtk_widget_measure (paned->start_child,
OPPOSITE_ORIENTATION (paned->orientation), OPPOSITE_ORIENTATION (paned->orientation),
MAX (for_start_child, -1), for_start_child,
&child_min, &child_nat, &child_min, &child_nat,
NULL, NULL); NULL, NULL);
@ -1214,7 +1214,20 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget,
{ {
gtk_widget_measure (paned->end_child, gtk_widget_measure (paned->end_child,
OPPOSITE_ORIENTATION (paned->orientation), OPPOSITE_ORIENTATION (paned->orientation),
MAX (for_end_child, -1), for_end_child,
&child_min, &child_nat,
NULL, NULL);
*minimum = MAX (*minimum, child_min);
*natural = MAX (*natural, child_nat);
}
if (paned->start_child && gtk_widget_get_visible (paned->start_child) &&
paned->end_child && gtk_widget_get_visible (paned->end_child))
{
gtk_widget_measure (paned->handle_widget,
OPPOSITE_ORIENTATION (paned->orientation),
for_handle,
&child_min, &child_nat, &child_min, &child_nat,
NULL, NULL); NULL, NULL);

View File

@ -427,6 +427,9 @@ testdata = [
'opacity-initial.ui', 'opacity-initial.ui',
'overlay-no-main-widget.ref.ui', 'overlay-no-main-widget.ref.ui',
'overlay-no-main-widget.ui', 'overlay-no-main-widget.ui',
'paned-handle-size.css',
'paned-handle-size.ref.ui',
'paned-handle-size.ui',
'paned-undersized.css', 'paned-undersized.css',
'paned-undersized.ref.ui', 'paned-undersized.ref.ui',
'paned-undersized.ui', 'paned-undersized.ui',

View File

@ -0,0 +1,15 @@
paned separator,
picture {
all: unset;
background: firebrick;
}
paned.vertical > separator {
min-width: 10px;
min-height: 20px;
}
paned.horizontal > separator {
min-width: 20px;
min-height: 10px;
}

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<object class="GtkWindow">
<property name="decorated">0</property>
<child>
<object class="GtkBox">
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="label">top left</property>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="height-request">20</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">bottom left</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="width-request">20</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="label">top right</property>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="height-request">20</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">bottom right</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<object class="GtkWindow">
<property name="decorated">0</property>
<child>
<object class="GtkPaned">
<child>
<object class="GtkPaned">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="label">top left</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">bottom left</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkPaned">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="label">top right</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">bottom right</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>