[glom] Details: Buttons: Use horizontal aligment from formatting.



commit 835dacd80f94a6248c8df3619264fc2c16e589fc
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Jan 24 10:39:43 2010 +0100

    Details: Buttons: Use horizontal aligment from formatting.
    
    * glom/mode_data/flowtablewithfields.cc: add_button_at_position():
    Use a Gtk::HBox with either pack_start() or pack_end(), putting it in the
    FlowTable with expand=true to have alignment in the button's space, if we
    don't want the FlowTable's default (left) alignment.

 ChangeLog                             |    9 +++++++++
 glom/mode_data/flowtablewithfields.cc |   25 ++++++++++++++++++++++---
 2 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a61747c..e167718 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2010-01-24  Murray Cumming  <murrayc murrayc com>
 
+  Details: Buttons: Use horizontal aligment from formatting.
+  
+	* glom/mode_data/flowtablewithfields.cc: add_button_at_position():
+	Use a Gtk::HBox with either pack_start() or pack_end(), putting it in the 
+	FlowTable with expand=true to have alignment in the button's space, if we 
+	don't want the FlowTable's default (left) alignment.
+
+2010-01-24  Murray Cumming  <murrayc murrayc com>
+
   Details: Static Text items: Use horizontal alignment from formatting.
   
 	* glom/utility_widgets/labelglom.[h|cc]: Add a constructor that does not 
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 472e7dc..a72f4b5 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -594,13 +594,32 @@ void FlowTableWithFields::add_button_at_position(const sharedptr<LayoutItem_Butt
     
   add_layoutwidgetbase(button, add_before);
   //add_view(button); //So it can get the document.
+  
+  const FieldFormatting::HorizontalAlignment alignment =
+    layoutitem_button->get_formatting_used_horizontal_alignment();
+  Gtk::Widget* widget_to_add = button;
+  bool expand = false;
+  if(alignment != FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT)
+  {
+    //Put the button in a Gtk::HBox so we can have non-default alignment in 
+    //its space. Note that we will need a different technique if we ever 
+    //support center alignment.
+    Gtk::HBox* box_button = Gtk::manage(new Gtk::HBox());
+    box_button->show();
+    if(alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_RIGHT)
+      box_button->pack_end(*button, Gtk::PACK_SHRINK);
+    else
+      box_button->pack_start(*button, Gtk::PACK_SHRINK);
+      
+    widget_to_add = box_button;
+    expand = true;
+  }
 
-  //TODO: Align the button to the right of its space if using right alignment?
   Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
   if(widget)
-    insert_before (*button, *widget, false /* expand */);
+    insert_before (*widget_to_add, *widget, expand);
   else
-    add(*button, false /* expand */);
+    add(*widget_to_add, expand);
 
   apply_formatting(*button, layoutitem_button);
 }



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