[glom] Details View: Left-align numbers when using automatic alignment.



commit 9b6b994545fff689c01ee4053e69a3a63e632139
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Nov 20 15:31:27 2011 +0100

    Details View: Left-align numbers when using automatic alignment.
    
    * glom/libglom/data_structure/layout/layoutitem_field.[h|cc]:
    * glom/libglom/data_structure/layout/layoutitem_withformatting.[h|cc]:
    get_formatting_used_horizontal_alignment(): Add a for_details_view()
    and return left-alignment for auto-alignment on a details view.
    * glom/mode_data/datawidget/entry.cc:
    * glom/utility_widgets/layoutwidgetbase.cc: Pass true to get that
    effect.
    
    Right-aligned numbers on the detailed view just look sillier now that
    the entry widgets are full width, and when there are no other numbers
    above or below them. Note that we probably did not purposefully
    change it show numbers with full width, but I would still want this
    alignment change.

 ChangeLog                                          |   18 ++++++++++++++++++
 .../data_structure/layout/layoutitem_field.cc      |    7 ++++---
 .../data_structure/layout/layoutitem_field.h       |    4 +++-
 .../layout/layoutitem_withformatting.cc            |    2 +-
 .../layout/layoutitem_withformatting.h             |    2 +-
 glom/mode_data/datawidget/entry.cc                 |    2 +-
 glom/utility_widgets/layoutwidgetbase.cc           |    2 +-
 7 files changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4f22ac3..03e165e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2011-11-20  Murray Cumming  <murrayc murrayc com>
+
+	Details View: Left-align numbers when using automatic alignment.
+
+	* glom/libglom/data_structure/layout/layoutitem_field.[h|cc]:
+	* glom/libglom/data_structure/layout/layoutitem_withformatting.[h|cc]:
+	get_formatting_used_horizontal_alignment(): Add a for_details_view() 
+	and return left-alignment for auto-alignment on a details view.
+	* glom/mode_data/datawidget/entry.cc:
+	* glom/utility_widgets/layoutwidgetbase.cc: Pass true to get that 
+	effect.
+
+	Right-aligned numbers on the detailed view just look sillier now that
+	the entry widgets are full width, and when there are no other numbers
+	above or below them. Note that we probably did not purposefully 
+	change it show numbers with full width, but I would still want this
+	alignment change.
+
 2011-11-18  Murray Cumming  <murrayc murrayc com>
 
 	Recognize GdaBlob as suitable for Image field types.
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.cc b/glom/libglom/data_structure/layout/layoutitem_field.cc
index 484bf49..3cd9b35 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_field.cc
@@ -242,7 +242,7 @@ const FieldFormatting& LayoutItem_Field::get_formatting_used() const
     return m_formatting;
 }
 
-FieldFormatting::HorizontalAlignment LayoutItem_Field::get_formatting_used_horizontal_alignment() const
+FieldFormatting::HorizontalAlignment LayoutItem_Field::get_formatting_used_horizontal_alignment(bool for_details_view) const
 {
   const FieldFormatting& format = get_formatting_used();
   FieldFormatting::HorizontalAlignment alignment = 
@@ -250,8 +250,9 @@ FieldFormatting::HorizontalAlignment LayoutItem_Field::get_formatting_used_horiz
   
   if(alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_AUTO)
   {
-    //By default, right-align numbers unless they are ID fields:
-    if(m_field && !m_field->get_primary_key()) //TODO: Also prevent this when it is a foreign key.
+    //By default, right-align numbers on list views, unless they are ID fields.
+    //And left-align them on details views, because that looks silly otherwise.
+    if(!for_details_view && (m_field && !m_field->get_primary_key())) //TODO: Also prevent this when it is a foreign key.
     {
       //Align numbers to the right by default:
       alignment = (m_field->get_glom_type() == Field::TYPE_NUMERIC ? FieldFormatting::HORIZONTAL_ALIGNMENT_RIGHT : FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT);
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.h b/glom/libglom/data_structure/layout/layoutitem_field.h
index c9d84bb..33fb777 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.h
+++ b/glom/libglom/data_structure/layout/layoutitem_field.h
@@ -146,8 +146,10 @@ public:
   /** Get the alignment for the formatting used (see get_formatting_used()),
    * choosing an appropriate alignment if it is set to HORIZONTAL_ALIGNMENT_AUTO.
    * Note that this never returns HORIZONTAL_ALIGNMENT_AUTO.
+   *
+   * @param for_details_view This can change the effect of HORIZONTAL_ALIGNMENT_AUTO.
    */
-  virtual FieldFormatting::HorizontalAlignment get_formatting_used_horizontal_alignment() const;
+  virtual FieldFormatting::HorizontalAlignment get_formatting_used_horizontal_alignment(bool for_details_view = false) const;
 
   /** Compare the name, relationship, and related_relationship.
    */
diff --git a/glom/libglom/data_structure/layout/layoutitem_withformatting.cc b/glom/libglom/data_structure/layout/layoutitem_withformatting.cc
index ee35e18..49aa5c2 100644
--- a/glom/libglom/data_structure/layout/layoutitem_withformatting.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_withformatting.cc
@@ -61,7 +61,7 @@ const FieldFormatting& LayoutItem_WithFormatting::get_formatting_used() const
   return m_formatting;
 }
 
-FieldFormatting::HorizontalAlignment LayoutItem_WithFormatting::get_formatting_used_horizontal_alignment() const
+FieldFormatting::HorizontalAlignment LayoutItem_WithFormatting::get_formatting_used_horizontal_alignment(bool /* for_details_view */) const
 {
   const FieldFormatting& format = get_formatting_used();
   FieldFormatting::HorizontalAlignment alignment = 
diff --git a/glom/libglom/data_structure/layout/layoutitem_withformatting.h b/glom/libglom/data_structure/layout/layoutitem_withformatting.h
index e78775a..9748d83 100644
--- a/glom/libglom/data_structure/layout/layoutitem_withformatting.h
+++ b/glom/libglom/data_structure/layout/layoutitem_withformatting.h
@@ -53,7 +53,7 @@ public:
    * choosing an appropriate alignment if it is set to HORIZONTAL_ALIGNMENT_AUTO.
    * Note that this never returns HORIZONTAL_ALIGNMENT_AUTO.
    */
-  virtual FieldFormatting::HorizontalAlignment get_formatting_used_horizontal_alignment() const;
+  virtual FieldFormatting::HorizontalAlignment get_formatting_used_horizontal_alignment(bool for_details_view = false) const;
 };
 
 } //namespace Glom
diff --git a/glom/mode_data/datawidget/entry.cc b/glom/mode_data/datawidget/entry.cc
index 43616e6..c3c9d91 100644
--- a/glom/mode_data/datawidget/entry.cc
+++ b/glom/mode_data/datawidget/entry.cc
@@ -80,7 +80,7 @@ void Entry::set_layout_item(const sharedptr<LayoutItem>& layout_item, const Glib
   sharedptr<LayoutItem_Field> layout_field =
     sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
   if(layout_field)
-    alignment = layout_field->get_formatting_used_horizontal_alignment();
+    alignment = layout_field->get_formatting_used_horizontal_alignment(true /* for details view */);
 
   const float x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? 0.0 : 1.0);
   set_alignment(x_align);
diff --git a/glom/utility_widgets/layoutwidgetbase.cc b/glom/utility_widgets/layoutwidgetbase.cc
index 3426223..f7758e4 100644
--- a/glom/utility_widgets/layoutwidgetbase.cc
+++ b/glom/utility_widgets/layoutwidgetbase.cc
@@ -108,7 +108,7 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<con
 
   //Horizontal alignment:
   const FieldFormatting::HorizontalAlignment alignment =
-    layout_item->get_formatting_used_horizontal_alignment();
+    layout_item->get_formatting_used_horizontal_alignment(true /* for details view */);
   const float x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? 0.0 : 1.0);
   Gtk::Misc* misc = dynamic_cast<Gtk::Misc*>(widget_to_change);
   if(misc)



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