[libdazzle: 1/2] dzl-column-layout: Improve columns estimation
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle: 1/2] dzl-column-layout: Improve columns estimation
- Date: Thu, 24 Oct 2019 00:29:51 +0000 (UTC)
commit 39026b50c24342e9cca2d08b3d85be1687946d81
Author: Diego Escalante Urrelo <diegoe gnome org>
Date: Fri Oct 18 04:09:07 2019 -0500
dzl-column-layout: Improve columns estimation
Improve the n_columns calculation in dzl_column_layout_layout() to avoid
overshooting the required width by one count of column_spacing.
Fixes: https://gitlab.gnome.org/GNOME/gnome-builder/issues/1037
src/widgets/dzl-column-layout.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/src/widgets/dzl-column-layout.c b/src/widgets/dzl-column-layout.c
index 8151957..37f1409 100644
--- a/src/widgets/dzl-column-layout.c
+++ b/src/widgets/dzl-column-layout.c
@@ -18,6 +18,8 @@
#include "config.h"
+#include <math.h>
+
#define G_LOG_DOMAIN "dzl-column-layout"
#include "util/dzl-macros.h"
@@ -120,9 +122,22 @@ dzl_column_layout_layout (DzlColumnLayout *self,
}
if (total_height <= height)
- n_columns = 1;
+ {
+ n_columns = 1;
+ }
else
- n_columns = MAX (1, (width - (border_width * 2)) / (priv->column_width + priv->column_spacing));
+ {
+ int estimated_cols;
+ int leftover;
+
+ estimated_cols = round(width / priv->column_width);
+ leftover = (width % priv->column_width) - (border_width * 2) - (priv->column_spacing * (estimated_cols
- 1));
+
+ if (leftover >= 0)
+ n_columns = estimated_cols;
+ else
+ n_columns = MAX(1, (estimated_cols - 1));
+ }
if (priv->max_columns > 0)
n_columns = MIN (n_columns, (gint)priv->max_columns);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]