[hyena] ListView: Rework handling of cell state for rendering



commit 466515b2ca6555f93e9b694930769521a5aa462b
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Mon Jun 23 15:45:57 2014 +0200

    ListView: Rework handling of cell state for rendering
    
    Despite my previous attempt in commit ee28b59d, the cell state rendering
    still wasn't right: either widget state would be lost, or the selected
    state for one cell would spill over to the next ones.
    
    So now, whether a cell is selected is stored in the new
    CellContext.Selected property. CellContext.State is now only a getter,
    calculated from other properties (only Selected for now).
    In addition, cells are now responsible for setting the right
    StyleContext.State, by merging CellContext.State into it, along with any
    other adjustments.
    
    To help clear things up, the redundant ColumnCell.Render overload that
    took a StateFlags parameter is removed.

 Hyena.Gui/Hyena.Data.Gui/CellContext.cs            |    5 ++++-
 Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs             |    5 -----
 Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs     |    9 +++++----
 .../Hyena.Data.Gui/ListView/ListView_Rendering.cs  |   20 ++++++++++----------
 4 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/Hyena.Gui/Hyena.Data.Gui/CellContext.cs b/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
index b343903..cac5321 100644
--- a/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
@@ -46,7 +46,10 @@ namespace Hyena.Data.Gui
         public Gtk.StyleContext StyleContext {
             get { return Widget.StyleContext; }
         }
-        public Gtk.StateFlags State { get; set; }
+        public bool Selected { get; set; }
+        public Gtk.StateFlags State {
+            get { return (Selected ? Gtk.StateFlags.Selected : Gtk.StateFlags.Normal); }
+        }
         public Theme Theme { get; set; }
         public Gdk.Rectangle Area { get; set; }
         public Gdk.Rectangle Clip { get; set; }
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
index 9815807..d9d89ed 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
@@ -81,11 +81,6 @@ namespace Hyena.Data.Gui
 
         public virtual void Render (CellContext context, double cellWidth, double cellHeight)
         {
-            Render (context, context.State, cellWidth, cellHeight);
-        }
-
-        public virtual void Render (CellContext context, Gtk.StateFlags state, double cellWidth, double 
cellHeight)
-        {
         }
 
         public bool Expand { get; set; }
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
index f0bf079..78bcff1 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
@@ -55,12 +55,13 @@ namespace Hyena.Data.Gui
             int x = Xpad + ((cell_width - Size) / 2);
             int y = Ypad + ((cell_height - Size) / 2);
 
-            if (context.State.HasFlag (StateFlags.Normal) && last_hover_bound == BoundObjectParent) {
-                context.State |= StateFlags.Prelight;
-            }
             context.StyleContext.Save ();
             context.StyleContext.AddClass ("check");
-            context.StyleContext.State |= context.State | (Value ? StateFlags.Active : StateFlags.Normal);
+            if (!context.Selected && last_hover_bound == BoundObjectParent) {
+                context.StyleContext.State |= StateFlags.Prelight;
+            }
+            context.StyleContext.State |= (Value ? StateFlags.Active : StateFlags.Normal);
+            context.StyleContext.State |= context.State;
             context.StyleContext.RenderCheck (context.Context, x, y, Size, Size);
             context.StyleContext.Restore ();
         }
diff --git a/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs 
b/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
index c616bf1..b35cbd6 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
@@ -237,7 +237,7 @@ namespace Hyena.Data.Gui
                 cr.Save ();
                 cr.Translate (area.X, area.Y);
                 cell_context.Area = area;
-                cell_context.State = StateFlags.Normal;
+                cell_context.Selected = false;
                 cell.Render (cell_context, area.Width, area.Height);
                 cr.Restore ();
             }
@@ -338,7 +338,7 @@ namespace Hyena.Data.Gui
                         selection_height = 0;
                     }
 
-                    PaintRow (cr, ri, single_list_alloc, StateFlags.Normal);
+                    PaintRow (cr, ri, single_list_alloc, false);
                 }
 
                 single_list_alloc.Y += single_list_alloc.Height;
@@ -366,7 +366,7 @@ namespace Hyena.Data.Gui
 
             foreach (int ri in selected_rows) {
                 single_list_alloc.Y = offset + ((ri - first_row) * single_list_alloc.Height);
-                PaintRow (cr, ri, single_list_alloc, StateFlags.Selected);
+                PaintRow (cr, ri, single_list_alloc, true);
             }
 
             cr.ResetClip ();
@@ -406,7 +406,7 @@ namespace Hyena.Data.Gui
             }
         }
 
-        private void PaintRow (Cairo.Context cr, int row_index, Rectangle area, StateFlags state)
+        private void PaintRow (Cairo.Context cr, int row_index, Rectangle area, bool selected)
         {
             if (column_cache == null) {
                 return;
@@ -431,19 +431,19 @@ namespace Hyena.Data.Gui
 
                 cell_area.Width = column_cache[ci].Width;
                 cell_area.X = column_cache[ci].X1 + area.X;
-                PaintCell (cr, item, ci, row_index, cell_area, opaque, bold, state, false);
+                PaintCell (cr, item, ci, row_index, cell_area, opaque, bold, selected, false);
             }
 
             if (pressed_column_is_dragging && pressed_column_index >= 0) {
                 cell_area.Width = column_cache[pressed_column_index].Width;
                 cell_area.X = pressed_column_x_drag + list_rendering_alloc.X -
                     list_interaction_alloc.X - HadjustmentValue;
-                PaintCell (cr, item, pressed_column_index, row_index, cell_area, opaque, bold, state, true);
+                PaintCell (cr, item, pressed_column_index, row_index, cell_area, opaque, bold, selected, 
true);
             }
         }
 
         private void PaintCell (Cairo.Context cr, object item, int column_index, int row_index, Rectangle 
area, bool opaque, bool bold,
-            StateFlags state, bool dragging)
+                                bool selected, bool dragging)
         {
             ColumnCell cell = column_cache[column_index].Column.GetCell (0);
             cell.Bind (item);
@@ -470,7 +470,7 @@ namespace Hyena.Data.Gui
             cr.Translate (area.X, area.Y);
             cell_context.Area = area;
             cell_context.Opaque = opaque;
-            cell_context.State |= dragging ? StateFlags.Normal : state;
+            cell_context.Selected = dragging ? false : selected;
             cell.Render (cell_context, area.Width, area.Height);
             cr.Restore ();
 
@@ -540,9 +540,9 @@ namespace Hyena.Data.Gui
                     PaintRowSelection (cr, (int)child_allocation.X, (int)child_allocation.Y,
                         (int)child_allocation.Width, (int)child_allocation.Height);
 
-                    cell_context.State = StyleContext.State | StateFlags.Selected;
+                    cell_context.Selected = true;
                 } else {
-                    cell_context.State = StyleContext.State;
+                    cell_context.Selected = false;
                 }
 
                 layout_child.Render (cell_context);


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