After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 643685 - Normalise marks positions internally in GtkScale
Normalise marks positions internally in GtkScale
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks: 642165
 
 
Reported: 2011-03-02 16:30 UTC by Bastien Nocera
Modified: 2011-03-03 21:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Normalise marks positions internally in GtkScale (2.33 KB, patch)
2011-03-02 16:30 UTC, Bastien Nocera
none Details | Review
Add style classes to scales when they have marks (4.00 KB, patch)
2011-03-02 16:31 UTC, Bastien Nocera
none Details | Review
Add style classes to scales when they have marks (3.88 KB, patch)
2011-03-03 11:58 UTC, Bastien Nocera
none Details | Review

Description Bastien Nocera 2011-03-02 16:30:26 UTC
.
Comment 1 Bastien Nocera 2011-03-02 16:30:29 UTC
Created attachment 182264 [details] [review]
Normalise marks positions internally in GtkScale

This means that marks added to the top will go left when
the orientation is changed. This also means that we can
rely on the position of the marks regardless of orientation.
Comment 2 Bastien Nocera 2011-03-02 16:31:02 UTC
Created attachment 182265 [details] [review]
Add style classes to scales when they have marks

So that theme engines can draw their sliders in more meaningful
ways when marks are used, or marks are not present.
Comment 3 Matthias Clasen 2011-03-03 03:45:37 UTC
Review of attachment 182264 [details] [review]:

Looks like a reasonable idea, but you will have to fix some more places where mark->position is currently compared. 
Eg. the calls to find_next_pos (...GTK_POS_LEFT...)

::: gtk/gtkscale.c
@@ +1535,3 @@
+    mark->position = GTK_POS_TOP;
+  else
+    mark->position = GTK_POS_BOTTOM;

This contradicts the gtk_scale_add_mark docs:

* @position: where to draw the mark. For a horizontal scale, #GTK_POS_TOP
 *   is drawn above the scale, anything else below. For a vertical scale,
 *   #GTK_POS_LEFT is drawn to the left of the scale, anything else to the
 *   right.
Comment 4 Matthias Clasen 2011-03-03 03:50:34 UTC
Comment on attachment 182265 [details] [review]
Add style classes to scales when they have marks


> 
>+  /* Set the style classes for the slider, so it could
>+   * point to the right direction when marks are present */

Pet peeve of mine: move the closing */ to the next line and line
up the stars

>+  context = gtk_widget_get_style_context (GTK_WIDGET (scale));
>+  if (all_pos != GTK_POS_MULTIPLE &&
>+      all_pos != GTK_POS_UNSET)
>+    {
>+      if (all_pos == GTK_POS_TOP)
>+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
>+      else if (all_pos == GTK_POS_BOTTOM)
>+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
>+    }
>+  else
>+    {
>+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
>+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
>+    }

Shouldn't this be a straight if-else cascade a la:

remove_all_classes()
if (all_pos == GTK_POS_MULTIPLE)
  add_class (GTK_STYLE_CLASS_MARK)
else if (all_class == GTK_POS_TOP)
  add_class (GTK_STYLE_CLASS_HAS_MARK_ABOVE)
else if (all_class == GTK_POS_BOTTOM)
  add_class (GTK_STYLE_CLASS_HAS_MARK_BELOW)

?
Comment 5 Bastien Nocera 2011-03-03 11:58:43 UTC
Created attachment 182337 [details] [review]
Add style classes to scales when they have marks

So that theme engines can draw their sliders in more meaningful
ways when marks are used, or marks are not present.
Comment 6 Bastien Nocera 2011-03-03 12:01:17 UTC
(In reply to comment #4)
> (From update of attachment 182265 [details] [review])
> 
> > 
> >+  /* Set the style classes for the slider, so it could
> >+   * point to the right direction when marks are present */
> 
> Pet peeve of mine: move the closing */ to the next line and line
> up the stars

Done.

> >+  context = gtk_widget_get_style_context (GTK_WIDGET (scale));
> >+  if (all_pos != GTK_POS_MULTIPLE &&
> >+      all_pos != GTK_POS_UNSET)
> >+    {
> >+      if (all_pos == GTK_POS_TOP)
> >+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
> >+      else if (all_pos == GTK_POS_BOTTOM)
> >+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
> >+    }
> >+  else
> >+    {
> >+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
> >+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
> >+    }
> 
> Shouldn't this be a straight if-else cascade a la:

Simplified. Didn't know whether adding/removing classes had a possible speed impact.

> remove_all_classes()
> if (all_pos == GTK_POS_MULTIPLE)
>   add_class (GTK_STYLE_CLASS_MARK)

GTK_STYLE_CLASS_MARK is only added to the style context when the marks will actually be drawn in _draw() (and is then restored without that class).
Comment 7 Carlos Garnacho 2011-03-03 14:03:00 UTC
Comment on attachment 182337 [details] [review]
Add style classes to scales when they have marks

The approach looks good to me. For completeness, I think that gtk_scale_add_mark() should handle GTK_POS_MULTIPLE, adding both classes in that case.
Comment 8 Bastien Nocera 2011-03-03 14:08:40 UTC
(In reply to comment #7)
> (From update of attachment 182337 [details] [review])
> The approach looks good to me. For completeness, I think that
> gtk_scale_add_mark() should handle GTK_POS_MULTIPLE, adding both classes in
> that case.

What would this be useful for though?
Comment 9 Carlos Garnacho 2011-03-03 14:21:15 UTC
Doubly pointy sliders? :), just for completeness as I said, it makes sense to me that the slider is able to accurately pinpoint the position on both sides if there are marks there and the engine wants so.