[hyena] Hyena.Gui: Fix handling of StateFlags when rendering custom widgets
- From: Bertrand Lorentz <blorentz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hyena] Hyena.Gui: Fix handling of StateFlags when rendering custom widgets
- Date: Sat, 14 Jun 2014 18:48:22 +0000 (UTC)
commit ee28b59d6d195a1c12834c9005408503dae4a2dd
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date: Sat Jun 14 16:56:29 2014 +0200
Hyena.Gui: Fix handling of StateFlags when rendering custom widgets
GTK+ 3.x has added several flags to the StateFlags enum, and some of
them after 3.0. Of particular interest is the "backdrop" flag which
indicated that the window does not have the focus, and is heavily used
by the Adwaita theme to "tone down" stuff in the background.
This means we shoud never blindly overwrite a StateFlag value. So we
need to merge the StateFlags we want to set with the ones currently
set. For example, the result then follows both the cell state, like
"selected", and the overall widget state, like "backdrop".
We also to make sure that, after any modification to StyleContext.State,
the previous value is restored, so that we don't mess up the rest of
the rendering.
Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs | 6 +++---
Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs | 4 +++-
Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs | 4 ++--
Hyena.Gui/Hyena.Widgets/WrapLabel.cs | 4 +++-
4 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
index 24acd4a..f0bf079 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
@@ -55,12 +55,12 @@ namespace Hyena.Data.Gui
int x = Xpad + ((cell_width - Size) / 2);
int y = Ypad + ((cell_height - Size) / 2);
- if (context.State == StateFlags.Normal && last_hover_bound == BoundObjectParent) {
- context.State = StateFlags.Prelight;
+ 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);
+ context.StyleContext.State |= context.State | (Value ? StateFlags.Active : StateFlags.Normal);
context.StyleContext.RenderCheck (context.Context, x, y, Size, Size);
context.StyleContext.Restore ();
}
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
index 62bd413..4a3b3d6 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
@@ -107,8 +107,10 @@ namespace Hyena.Data.Gui
}
int y_pos = ((int)cellHeight - text_height) / 2;
- context.StyleContext.State = context.State;
+ context.StyleContext.Save ();
+ context.StyleContext.State |= context.State;
context.StyleContext.RenderLayout (context.Context, Padding.Left, y_pos, context.Layout);
+ context.StyleContext.Restore ();
}
public void UpdateText (CellContext context, double cellWidth)
diff --git a/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs b/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs
index 370c586..4de4b27 100644
--- a/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs
+++ b/Hyena.Gui/Hyena.Widgets/ComplexMenuItem.cs
@@ -83,7 +83,7 @@ namespace Hyena.Widgets
StyleContext.Save ();
StyleContext.AddClass ("menuitem");
- StyleContext.State = StateFlags.Prelight | StateFlags.Selected;
+ StyleContext.State |= StateFlags.Prelight | StateFlags.Selected;
StyleContext.RenderFrame (args.Cr, x, y, width, height);
StyleContext.RenderBackground (args.Cr, x, y, width, height);
StyleContext.Restore ();
@@ -112,7 +112,7 @@ namespace Hyena.Widgets
StyleContext.Save ();
StyleContext.AddClass ("menuitem");
- StyleContext.State = StateFlags.Normal;
+ StyleContext.State |= StateFlags.Normal;
StyleContext.RenderFrame (args.Cr, x, y, width, height);
StyleContext.RenderBackground (args.Cr, x, y, width, height);
StyleContext.Restore ();
diff --git a/Hyena.Gui/Hyena.Widgets/WrapLabel.cs b/Hyena.Gui/Hyena.Widgets/WrapLabel.cs
index 174b8c6..5e56175 100644
--- a/Hyena.Gui/Hyena.Widgets/WrapLabel.cs
+++ b/Hyena.Gui/Hyena.Widgets/WrapLabel.cs
@@ -108,8 +108,10 @@ namespace Hyena.Widgets
layout.GetPixelSize (out lw, out lh);
int y = (Allocation.Height - lh) / 2;
- StyleContext.State = StateFlags;
+ StyleContext.Save ();
+ StyleContext.State |= StateFlags;
StyleContext.RenderLayout (cr, 0, y, layout);
+ StyleContext.Restore ();
}
return true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]