summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-04-13 20:44:23 +0000
committerMatthias Clasen <mclasen@redhat.com>2023-04-13 20:44:23 +0000
commit64a196929351d8fb33f621eee9b643caece03caf (patch)
tree6874e1a8f581d05cdb0a19db5791a5e0aca480a9
parent2baab9732cbfc4ea10ac77c88c6b8179d0920d51 (diff)
parentd625ff81061f9627c6ad2b5d1f1e78c93c424252 (diff)
downloadgtk+-64a196929351d8fb33f621eee9b643caece03caf.tar.gz
Merge branch 'fix_scalebutton_orientation' into 'main'
ScaleButton: fix CSS name in documentation, fix orientation doing nothing See merge request GNOME/gtk!5819
-rw-r--r--gtk/gtkscalebutton.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c
index e1a78b1bfe..4b7617a479 100644
--- a/gtk/gtkscalebutton.c
+++ b/gtk/gtkscalebutton.c
@@ -71,8 +71,14 @@
*
* # CSS nodes
*
- * `GtkScaleButton` has a single CSS node with name button. To differentiate
- * it from a plain `GtkButton`, it gets the .scale style class.
+ * ```
+ * scalebutton.scale
+ * ╰── button.toggle
+ * ╰── <icon>
+ * ```
+ *
+ * `GtkScaleButton` has a single CSS node with name scalebutton and `.scale`
+ * style class, and contains a `button` node with a `.toggle` style class.
*/
@@ -811,6 +817,40 @@ gtk_scale_button_get_active (GtkScaleButton *button)
}
static void
+apply_orientation (GtkScaleButton *button,
+ GtkOrientation orientation)
+{
+ GtkScaleButtonPrivate *priv = gtk_scale_button_get_instance_private (button);
+
+ if (priv->applied_orientation != orientation)
+ {
+ priv->applied_orientation = orientation;
+
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), orientation);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->scale), orientation);
+
+ if (orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ gtk_box_reorder_child_after (GTK_BOX (priv->box), priv->scale,
+ priv->plus_button);
+ gtk_box_reorder_child_after (GTK_BOX (priv->box), priv->minus_button,
+ priv->scale);
+ gtk_widget_set_size_request (GTK_WIDGET (priv->scale), -1, SCALE_SIZE);
+ gtk_range_set_inverted (GTK_RANGE (priv->scale), TRUE);
+ }
+ else
+ {
+ gtk_box_reorder_child_after (GTK_BOX (priv->box), priv->scale,
+ priv->minus_button);
+ gtk_box_reorder_child_after (GTK_BOX (priv->box), priv->plus_button,
+ priv->scale);
+ gtk_widget_set_size_request (GTK_WIDGET (priv->scale), SCALE_SIZE, -1);
+ gtk_range_set_inverted (GTK_RANGE (priv->scale), FALSE);
+ }
+ }
+}
+
+static void
gtk_scale_button_set_orientation_private (GtkScaleButton *button,
GtkOrientation orientation)
{
@@ -819,6 +859,9 @@ gtk_scale_button_set_orientation_private (GtkScaleButton *button,
if (priv->orientation != orientation)
{
priv->orientation = orientation;
+
+ apply_orientation (button, priv->orientation);
+
g_object_notify (G_OBJECT (button), "orientation");
}
}
@@ -855,6 +898,8 @@ gtk_scale_popup (GtkWidget *widget)
GtkScaleButton *button = GTK_SCALE_BUTTON (widget);
GtkScaleButtonPrivate *priv = gtk_scale_button_get_instance_private (button);
+ apply_orientation (button, priv->orientation);
+
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), TRUE);
}