[libdazzle] suggestions: take style into account when positioning



commit 29912c7ca77af351b00a596cef3f7248925feb1c
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 10 20:29:01 2017 -0700

    suggestions: take style into account when positioning
    
    We need to take the margin into account of the box child. We
    have to style shadows on the box so that animations in and out
    are clipped correctly.

 data/themes/shared/shared-suggestions.css |   16 ++++----------
 src/suggestions/dzl-suggestion-entry.c    |    2 +
 src/suggestions/dzl-suggestion-popover.c  |   31 +++++++++++++++++++++++++++++
 src/suggestions/dzl-suggestion-popover.ui |    2 +-
 src/suggestions/dzl-suggestion-private.h  |    2 +
 5 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/data/themes/shared/shared-suggestions.css b/data/themes/shared/shared-suggestions.css
index dce4ac6..f2ea108 100644
--- a/data/themes/shared/shared-suggestions.css
+++ b/data/themes/shared/shared-suggestions.css
@@ -3,16 +3,16 @@ dzlsuggestionpopover {
 }
 
 dzlsuggestionpopover > revealer > box {
-  margin: 0px 0px 60px 0px;
-  border-radius: 0px;
-  border-width: 0px;
+  margin: 0px 40px 60px 40px;
+  border-top: none;
   border-bottom: 1px solid @borders;
-  box-shadow: 0px -6px 12px #000;
+  border-right: 1px solid @borders;
+  border-left: 1px solid @borders;
+  box-shadow: 0px -6px 12px @wm_shadow;
 }
 
 dzlsuggestionpopover > revealer > box > elastic > scrolledwindow {
   background: alpha(@content_view_bg, 0.97);
-  border-radius: 0 0 7px 7px;
 }
 
 dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list {
@@ -25,8 +25,6 @@ dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > li
 
 dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row {
   transition: none;
-  margin-left: 100px;
-  margin-right: 100px;
 }
 
 dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row:selected .title {
@@ -37,10 +35,6 @@ dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > li
   color: @theme_fg_color;
 }
 
-dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > 
row:first-child:selected {
-  border-radius: 0;
-}
-
 dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row > box {
   margin: 4px 8px 4px 8px;
 }
diff --git a/src/suggestions/dzl-suggestion-entry.c b/src/suggestions/dzl-suggestion-entry.c
index 295a5b3..54dd71c 100644
--- a/src/suggestions/dzl-suggestion-entry.c
+++ b/src/suggestions/dzl-suggestion-entry.c
@@ -817,6 +817,8 @@ _dzl_suggestion_entry_reposition (DzlSuggestionEntry   *self,
       alloc.y += y;
     }
 
+  _dzl_suggestion_popover_adjust_margin (popover, &alloc);
+
   gtk_widget_set_size_request (GTK_WIDGET (popover), alloc.width, -1);
   gtk_window_move (GTK_WINDOW (popover), alloc.x, alloc.y);
 }
diff --git a/src/suggestions/dzl-suggestion-popover.c b/src/suggestions/dzl-suggestion-popover.c
index 50a8c4c..a4fb521 100644
--- a/src/suggestions/dzl-suggestion-popover.c
+++ b/src/suggestions/dzl-suggestion-popover.c
@@ -39,6 +39,7 @@ struct _DzlSuggestionPopover
   GtkRevealer        *revealer;
   GtkScrolledWindow  *scrolled_window;
   DzlListBox         *list_box;
+  GtkBox             *top_box;
 
   DzlAnimation       *scroll_anim;
 
@@ -528,6 +529,7 @@ dzl_suggestion_popover_class_init (DzlSuggestionPopoverClass *klass)
   gtk_widget_class_bind_template_child (widget_class, DzlSuggestionPopover, revealer);
   gtk_widget_class_bind_template_child (widget_class, DzlSuggestionPopover, list_box);
   gtk_widget_class_bind_template_child (widget_class, DzlSuggestionPopover, scrolled_window);
+  gtk_widget_class_bind_template_child (widget_class, DzlSuggestionPopover, top_box);
 
   gtk_widget_class_set_css_name (widget_class, "dzlsuggestionpopover");
 
@@ -932,3 +934,32 @@ _dzl_suggestion_popover_set_max_height (DzlSuggestionPopover *self,
                 "max-content-height", max_height,
                 NULL);
 }
+
+void
+_dzl_suggestion_popover_adjust_margin (DzlSuggestionPopover *self,
+                                       GdkRectangle         *area)
+{
+  GtkStyleContext *style_context;
+  GtkBorder margin;
+
+  g_return_if_fail (DZL_IS_SUGGESTION_POPOVER (self));
+  g_return_if_fail (area != NULL);
+
+  /*
+   * This is our last chance to adjust the allocation.  We need to subtract any
+   * margins needed by the box for theming. We style the shadow in the box so
+   * that we can do the show/hide with the revealer and have things come out
+   * looking correct.
+   */
+
+  style_context = gtk_widget_get_style_context (GTK_WIDGET (self->top_box));
+  gtk_style_context_get_margin (style_context,
+                                gtk_style_context_get_state (style_context),
+                                &margin);
+
+  area->x -= margin.right;
+  area->y -= margin.top;
+  area->width += margin.right + margin.left;
+  area->height += margin.top + margin.bottom;
+}
+
diff --git a/src/suggestions/dzl-suggestion-popover.ui b/src/suggestions/dzl-suggestion-popover.ui
index c16a0d5..b0292c1 100644
--- a/src/suggestions/dzl-suggestion-popover.ui
+++ b/src/suggestions/dzl-suggestion-popover.ui
@@ -8,7 +8,7 @@
         <property name="transition-type">slide-down</property>
         <property name="visible">true</property>
         <child>
-          <object class="GtkBox">
+          <object class="GtkBox" id="top_box">
             <property name="orientation">vertical</property>
             <property name="visible">true</property>
             <child>
diff --git a/src/suggestions/dzl-suggestion-private.h b/src/suggestions/dzl-suggestion-private.h
index fd922b6..62a59ca 100644
--- a/src/suggestions/dzl-suggestion-private.h
+++ b/src/suggestions/dzl-suggestion-private.h
@@ -27,5 +27,7 @@ void _dzl_suggestion_entry_reposition       (DzlSuggestionEntry   *entry,
                                              DzlSuggestionPopover *popover);
 void _dzl_suggestion_popover_set_max_height (DzlSuggestionPopover *popover,
                                              gint                  max_height);
+void _dzl_suggestion_popover_adjust_margin  (DzlSuggestionPopover *popover,
+                                             GdkRectangle         *area);
 
 #endif /* DZL_SUGGESTION_PRIVATE_H */


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