[gnome-todo/wip/gbsneto/nonexpanding-rows] rows: Implement maximum size



commit 233e188dfb545bfa021295c4776415233af0f25a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Oct 19 17:26:26 2017 -0200

    rows: Implement maximum size
    
    This is in prototype stage still. We can potentially evaluate
    calculating the maximum row size to be a ratio of the window's
    width.

 data/ui/dnd-row.ui            |  1 +
 data/ui/new-task-row.ui       |  1 +
 data/ui/task-row.ui           |  1 +
 src/gtd-dnd-row.c             |  8 +++++++-
 src/gtd-new-task-row.c        |  2 ++
 src/gtd-rows-common-private.h | 32 ++++++++++++++++++++++++++++++++
 src/gtd-rows-common.c         | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/gtd-task-row.c            |  2 ++
 src/meson.build               |  1 +
 9 files changed, 90 insertions(+), 1 deletion(-)
---
diff --git a/data/ui/dnd-row.ui b/data/ui/dnd-row.ui
index 5e2cf6b..4e21f5d 100644
--- a/data/ui/dnd-row.ui
+++ b/data/ui/dnd-row.ui
@@ -5,6 +5,7 @@
     <property name="can_focus">True</property>
     <property name="activatable">False</property>
     <property name="selectable">False</property>
+    <property name="halign">center</property>
     <child>
       <object class="GtkBox" id="box">
         <property name="visible">True</property>
diff --git a/data/ui/new-task-row.ui b/data/ui/new-task-row.ui
index b0d3c83..8c2b106 100644
--- a/data/ui/new-task-row.ui
+++ b/data/ui/new-task-row.ui
@@ -7,6 +7,7 @@
     <property name="activatable">True</property>
     <property name="selectable">False</property>
     <property name="height-request">38</property>
+    <property name="halign">center</property>
     <property name="margin">3</property>
     <style>
       <class name="new-task-row" />
diff --git a/data/ui/task-row.ui b/data/ui/task-row.ui
index d190c20..ac6d6b5 100644
--- a/data/ui/task-row.ui
+++ b/data/ui/task-row.ui
@@ -5,6 +5,7 @@
     <property name="visible">True</property>
     <property name="activatable">True</property>
     <property name="selectable">False</property>
+    <property name="halign">center</property>
     <property name="margin">3</property>
     <child>
       <object class="GtkRevealer" id="revealer">
diff --git a/src/gtd-dnd-row.c b/src/gtd-dnd-row.c
index 5b4520d..e83af84 100644
--- a/src/gtd-dnd-row.c
+++ b/src/gtd-dnd-row.c
@@ -19,6 +19,7 @@
 #include "gtd-dnd-row.h"
 #include "gtd-new-task-row.h"
 #include "gtd-provider.h"
+#include "gtd-rows-common-private.h"
 #include "gtd-task.h"
 #include "gtd-task-list.h"
 #include "gtd-task-row.h"
@@ -126,6 +127,8 @@ gtd_dnd_row_class_init (GtdDndRowClass *klass)
   object_class->get_property = gtd_dnd_row_get_property;
   object_class->set_property = gtd_dnd_row_set_property;
 
+  widget_class->get_preferred_width = gtd_row_get_preferred_width_with_max;
+
   properties[PROP_ROW_ABOVE] = g_param_spec_object ("row-above",
                                                     "Row above",
                                                     "The task row above this row",
@@ -183,10 +186,13 @@ gtd_dnd_row_drag_motion (GtkWidget      *widget,
                          gint            y,
                          guint           time)
 {
+  GtkAllocation alloc;
   GtdDndRow *self;
 
   self = GTD_DND_ROW (widget);
 
+  gtk_widget_get_allocation (widget, &alloc);
+
   if (self->row_above && GTD_IS_TASK_ROW (self->row_above))
     {
       GtdTask *task;
@@ -194,7 +200,7 @@ gtd_dnd_row_drag_motion (GtkWidget      *widget,
 
       task = gtd_task_row_get_task (GTD_TASK_ROW (self->row_above));
       offset = gtk_widget_get_margin_start (self->box) + gtk_widget_get_allocated_width (self->icon) + 12;
-      self->depth = CLAMP (floor ((x - offset) / 32),
+      self->depth = CLAMP (floor ((x - alloc.x - offset) / 32),
                            0,
                            gtd_task_get_depth (task) + 1);
     }
diff --git a/src/gtd-new-task-row.c b/src/gtd-new-task-row.c
index fa97f19..a8eb993 100644
--- a/src/gtd-new-task-row.c
+++ b/src/gtd-new-task-row.c
@@ -19,6 +19,7 @@
 #include "gtd-manager.h"
 #include "gtd-new-task-row.h"
 #include "gtd-provider.h"
+#include "gtd-rows-common-private.h"
 #include "gtd-task.h"
 #include "gtd-task-list.h"
 
@@ -284,6 +285,7 @@ gtd_new_task_row_class_init (GtdNewTaskRowClass *klass)
   object_class->set_property = gtd_new_task_row_set_property;
 
   widget_class->focus_in_event = gtd_new_task_row_focus_in_event;
+  widget_class->get_preferred_width = gtd_row_get_preferred_width_with_max;
 
   /**
    * GtdNewTaskRow::enter:
diff --git a/src/gtd-rows-common-private.h b/src/gtd-rows-common-private.h
new file mode 100644
index 0000000..97e7719
--- /dev/null
+++ b/src/gtd-rows-common-private.h
@@ -0,0 +1,32 @@
+/* gtd-rows-common-private.h
+ *
+ * Copyright (C) 2017 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTD_ROWS_COMMON_PRIVATE_H
+#define GTD_ROWS_COMMON_PRIVATE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+void                 gtd_row_get_preferred_width_with_max        (GtkWidget          *widget,
+                                                                  gint               *minimum_width,
+                                                                  gint               *natural_width);
+
+G_END_DECLS
+
+#endif /* GTD_ROWS_COMMON_PRIVATE_H */
diff --git a/src/gtd-rows-common.c b/src/gtd-rows-common.c
new file mode 100644
index 0000000..e31d165
--- /dev/null
+++ b/src/gtd-rows-common.c
@@ -0,0 +1,43 @@
+/* gtd-rows-common.c
+ *
+ * Copyright (C) 2017 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtd-rows-common-private.h"
+
+#define MAX_WIDTH                  700
+
+void
+gtd_row_get_preferred_width_with_max (GtkWidget *widget,
+                                      gint      *minimum_width,
+                                      gint      *natural_width)
+{
+  gint local_minimum_width, local_natural_width;
+  gint scale_factor;
+
+  scale_factor = gtk_widget_get_scale_factor (widget);
+
+  gtk_widget_get_preferred_width (gtk_bin_get_child (GTK_BIN (widget)),
+                                  &local_minimum_width,
+                                  &local_natural_width);
+
+  if (minimum_width)
+    *minimum_width = MIN (local_minimum_width, MAX_WIDTH) * scale_factor;
+
+  if (natural_width)
+    *natural_width = MAX (local_minimum_width, MAX_WIDTH) * scale_factor;
+}
+
diff --git a/src/gtd-task-row.c b/src/gtd-task-row.c
index 8bbae34..090fd36 100644
--- a/src/gtd-task-row.c
+++ b/src/gtd-task-row.c
@@ -19,6 +19,7 @@
 #include "gtd-edit-pane.h"
 #include "gtd-manager.h"
 #include "gtd-provider.h"
+#include "gtd-rows-common-private.h"
 #include "gtd-task-row.h"
 #include "gtd-task.h"
 #include "gtd-task-list.h"
@@ -539,6 +540,7 @@ gtd_task_row_class_init (GtdTaskRowClass *klass)
 
   widget_class->focus_in_event = gtd_task_row_focus_in_event;
   widget_class->key_press_event = gtd_task_row__key_press_event;
+  widget_class->get_preferred_width = gtd_row_get_preferred_width_with_max;
 
   /**
    * GtdTaskRow::handle-subtasks:
diff --git a/src/meson.build b/src/meson.build
index f108dfe..bca9a3d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -52,6 +52,7 @@ sources = files(
   'gtd-object.c',
   'gtd-plugin-dialog.c',
   'gtd-plugin-dialog-row.c',
+  'gtd-rows-common.c',
   'gtd-task.c',
   'gtd-task-list.c',
   'gtd-task-list-view.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]