spinbutton: Use a box layout

This commit is contained in:
Timm Bäder 2019-08-23 09:32:00 +02:00
parent c0214cfcc1
commit 822547dfef
5 changed files with 52 additions and 99 deletions

View File

@ -53,6 +53,7 @@
#include "gtktypebuiltins.h"
#include "gtkwidgetpath.h"
#include "gtkwidgetprivate.h"
#include "gtkboxlayout.h"
#include "a11y/gtkspinbuttonaccessible.h"
@ -94,22 +95,20 @@
*
* |[<!-- language="plain" -->
* spinbutton.horizontal
* box.horizontal
* text
* undershoot.left
* undershoot.right
* button.down
* button.up
* text
* undershoot.left
* undershoot.right
* button.down
* button.up
* ]|
*
* |[<!-- language="plain" -->
* spinbutton.vertical
* box.vertical
* button.up
* text
* undershoot.left
* undershoot.right
* button.down
* button.up
* text
* undershoot.left
* undershoot.right
* button.down
* ]|
*
* GtkSpinButtons main CSS node has the name spinbutton. It creates subnodes
@ -273,17 +272,6 @@ static void gtk_spin_button_get_property (GObject *object,
GParamSpec *pspec);
static void gtk_spin_button_destroy (GtkWidget *widget);
static void gtk_spin_button_realize (GtkWidget *widget);
static void gtk_spin_button_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline);
static void gtk_spin_button_size_allocate (GtkWidget *widget,
int width,
int height,
int baseline);
static void gtk_spin_button_grab_notify (GtkWidget *widget,
gboolean was_grabbed);
static void gtk_spin_button_state_flags_changed (GtkWidget *widget,
@ -363,8 +351,6 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
widget_class->destroy = gtk_spin_button_destroy;
widget_class->realize = gtk_spin_button_realize;
widget_class->measure = gtk_spin_button_measure;
widget_class->size_allocate = gtk_spin_button_size_allocate;
widget_class->grab_notify = gtk_spin_button_grab_notify;
widget_class->state_flags_changed = gtk_spin_button_state_flags_changed;
widget_class->grab_focus = gtk_spin_button_grab_focus;
@ -568,6 +554,7 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
add_spin_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_START);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SPIN_BUTTON_ACCESSIBLE);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("spinbutton"));
}
@ -890,9 +877,6 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
_gtk_orientable_set_style_classes (GTK_ORIENTABLE (spin_button));
priv->box = gtk_box_new (priv->orientation, 0);
gtk_widget_set_parent (priv->box, GTK_WIDGET (spin_button));
priv->entry = gtk_text_new ();
gtk_editable_init_delegate (GTK_EDITABLE (spin_button));
gtk_editable_set_width_chars (GTK_EDITABLE (priv->entry), 0);
@ -900,12 +884,12 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
gtk_widget_set_hexpand (priv->entry, TRUE);
gtk_widget_set_vexpand (priv->entry, TRUE);
g_signal_connect (priv->entry, "activate", G_CALLBACK (gtk_spin_button_activate), spin_button);
gtk_container_add (GTK_CONTAINER (priv->box), priv->entry);
gtk_widget_set_parent (priv->entry, GTK_WIDGET (spin_button));
priv->down_button = gtk_button_new_from_icon_name ("value-decrease-symbolic");
gtk_style_context_add_class (gtk_widget_get_style_context (priv->down_button), "down");
gtk_widget_set_can_focus (priv->down_button, FALSE);
gtk_container_add (GTK_CONTAINER (priv->box), priv->down_button);
gtk_widget_set_parent (priv->down_button, GTK_WIDGET (spin_button));
gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
@ -920,7 +904,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
priv->up_button = gtk_button_new_from_icon_name ("value-increase-symbolic");
gtk_style_context_add_class (gtk_widget_get_style_context (priv->up_button), "up");
gtk_widget_set_can_focus (priv->up_button, FALSE);
gtk_container_add (GTK_CONTAINER (priv->box), priv->up_button);
gtk_widget_set_parent (priv->up_button, GTK_WIDGET (spin_button));
gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
@ -968,7 +952,9 @@ gtk_spin_button_finalize (GObject *object)
gtk_editable_finish_delegate (GTK_EDITABLE (spin_button));
gtk_widget_unparent (priv->box);
gtk_widget_unparent (priv->entry);
gtk_widget_unparent (priv->up_button);
gtk_widget_unparent (priv->down_button);
G_OBJECT_CLASS (gtk_spin_button_parent_class)->finalize (object);
}
@ -1054,6 +1040,7 @@ gtk_spin_button_set_orientation (GtkSpinButton *spin,
GtkOrientation orientation)
{
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin);
GtkBoxLayout *layout_manager;
GtkEditable *editable = GTK_EDITABLE (priv->entry);
if (priv->orientation == orientation)
@ -1073,17 +1060,16 @@ gtk_spin_button_set_orientation (GtkSpinButton *spin,
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
/* Current orientation of the box is vertical! */
gtk_box_reorder_child_after (GTK_BOX (priv->box), priv->up_button, NULL);
gtk_box_reorder_child_after (GTK_BOX (priv->box), priv->entry, NULL);
gtk_widget_insert_after (priv->up_button, GTK_WIDGET (spin), priv->down_button);
}
else
{
/* Current orientation of the box is horizontal! */
gtk_box_reorder_child_after (GTK_BOX (priv->box), priv->entry, NULL);
gtk_box_reorder_child_after (GTK_BOX (priv->box), priv->up_button, NULL);
gtk_widget_insert_before (priv->up_button, GTK_WIDGET (spin), priv->entry);
}
gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), priv->orientation);
layout_manager = GTK_BOX_LAYOUT (gtk_widget_get_layout_manager (GTK_WIDGET (spin)));
gtk_orientable_set_orientation (GTK_ORIENTABLE (layout_manager), priv->orientation);
g_object_notify (G_OBJECT (spin), "orientation");
}
@ -1112,38 +1098,6 @@ gtk_spin_button_format_for_value (GtkSpinButton *spin_button,
return weed_out_neg_zero (buf, priv->digits);
}
static void
gtk_spin_button_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (GTK_SPIN_BUTTON (widget));
gtk_widget_measure (priv->box, orientation, for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
static void
gtk_spin_button_size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (GTK_SPIN_BUTTON (widget));
gtk_widget_size_allocate (priv->box,
&(GtkAllocation) {
0, 0,
width, height
},
baseline);
}
static void
gtk_spin_button_grab_notify (GtkWidget *widget,
gboolean was_grabbed)

View File

@ -1170,8 +1170,8 @@ spinbutton {
@extend %spinbutton_horz_entry;
}
> box > button.image-button.up,
> box > button.image-button.down {
> button.image-button.up,
> button.image-button.down {
min-height: 16px;
margin: 0;
padding-bottom: 0;

View File

@ -520,25 +520,25 @@ spinbutton:not(.vertical) text, .osd spinbutton:not(.vertical) text { min-width:
spinbutton:not(.vertical) text:backdrop:disabled { background-color: transparent; }
spinbutton:not(.vertical) > box > button.image-button.up, spinbutton:not(.vertical) > box > button.image-button.down { min-height: 16px; margin: 0; padding-bottom: 0; padding-top: 0; color: #dbdbd9; background-image: none; border-style: none none none solid; border-color: rgba(27, 27, 27, 0.3); border-radius: 0; box-shadow: none; }
spinbutton:not(.vertical) > button.image-button.up, spinbutton:not(.vertical) > button.image-button.down { min-height: 16px; margin: 0; padding-bottom: 0; padding-top: 0; color: #dbdbd9; background-image: none; border-style: none none none solid; border-color: rgba(27, 27, 27, 0.3); border-radius: 0; box-shadow: none; }
spinbutton:not(.vertical) > box > button.image-button.up:dir(rtl), spinbutton:not(.vertical) > box > button.image-button.down:dir(rtl) { border-style: none solid none none; }
spinbutton:not(.vertical) > button.image-button.up:dir(rtl), spinbutton:not(.vertical) > button.image-button.down:dir(rtl) { border-style: none solid none none; }
spinbutton:not(.vertical) > box > button.image-button.up:hover, spinbutton:not(.vertical) > box > button.image-button.down:hover { color: #eeeeec; background-color: rgba(238, 238, 236, 0.05); }
spinbutton:not(.vertical) > button.image-button.up:hover, spinbutton:not(.vertical) > button.image-button.down:hover { color: #eeeeec; background-color: rgba(238, 238, 236, 0.05); }
spinbutton:not(.vertical) > box > button.image-button.up:disabled, spinbutton:not(.vertical) > box > button.image-button.down:disabled { color: rgba(145, 145, 144, 0.3); background-color: transparent; }
spinbutton:not(.vertical) > button.image-button.up:disabled, spinbutton:not(.vertical) > button.image-button.down:disabled { color: rgba(145, 145, 144, 0.3); background-color: transparent; }
spinbutton:not(.vertical) > box > button.image-button.up:active, spinbutton:not(.vertical) > box > button.image-button.down:active { background-color: rgba(0, 0, 0, 0.1); box-shadow: inset 0 2px 3px -1px rgba(0, 0, 0, 0.2); }
spinbutton:not(.vertical) > button.image-button.up:active, spinbutton:not(.vertical) > button.image-button.down:active { background-color: rgba(0, 0, 0, 0.1); box-shadow: inset 0 2px 3px -1px rgba(0, 0, 0, 0.2); }
spinbutton:not(.vertical) > box > button.image-button.up:backdrop, spinbutton:not(.vertical) > box > button.image-button.down:backdrop { color: #878786; background-color: transparent; border-color: rgba(32, 32, 32, 0.3); transition: 200ms ease-out; }
spinbutton:not(.vertical) > button.image-button.up:backdrop, spinbutton:not(.vertical) > button.image-button.down:backdrop { color: #878786; background-color: transparent; border-color: rgba(32, 32, 32, 0.3); transition: 200ms ease-out; }
spinbutton:not(.vertical) > box > button.image-button.up:backdrop:disabled, spinbutton:not(.vertical) > box > button.image-button.down:backdrop:disabled { color: rgba(91, 91, 91, 0.3); background-color: transparent; border-style: none none none solid; }
spinbutton:not(.vertical) > button.image-button.up:backdrop:disabled, spinbutton:not(.vertical) > button.image-button.down:backdrop:disabled { color: rgba(91, 91, 91, 0.3); background-color: transparent; border-style: none none none solid; }
spinbutton:not(.vertical) > box > button.image-button.up:backdrop:disabled:dir(rtl), spinbutton:not(.vertical) > box > button.image-button.down:backdrop:disabled:dir(rtl) { border-style: none solid none none; }
spinbutton:not(.vertical) > button.image-button.up:backdrop:disabled:dir(rtl), spinbutton:not(.vertical) > button.image-button.down:backdrop:disabled:dir(rtl) { border-style: none solid none none; }
spinbutton:not(.vertical) > box > button.image-button.up:dir(ltr):last-child, spinbutton:not(.vertical) > box > button.image-button.down:dir(ltr):last-child { border-radius: 0 5px 5px 0; }
spinbutton:not(.vertical) > button.image-button.up:dir(ltr):last-child, spinbutton:not(.vertical) > button.image-button.down:dir(ltr):last-child { border-radius: 0 5px 5px 0; }
spinbutton:not(.vertical) > box > button.image-button.up:dir(rtl):first-child, spinbutton:not(.vertical) > box > button.image-button.down:dir(rtl):first-child { border-radius: 5px 0 0 5px; }
spinbutton:not(.vertical) > button.image-button.up:dir(rtl):first-child, spinbutton:not(.vertical) > button.image-button.down:dir(rtl):first-child { border-radius: 5px 0 0 5px; }
.osd spinbutton:not(.vertical) button { border-color: transparent; background-color: transparent; background-image: none; box-shadow: inset 0 1px rgba(255, 255, 255, 0); text-shadow: none; -gtk-icon-shadow: none; color: #eeeeec; border-style: none none none solid; border-color: rgba(0, 0, 0, 0.4); border-radius: 0; box-shadow: none; -gtk-icon-shadow: 0 1px black; }

View File

@ -528,25 +528,25 @@ spinbutton:not(.vertical) text, .osd spinbutton:not(.vertical) text { min-width:
spinbutton:not(.vertical) text:backdrop:disabled { background-color: transparent; }
spinbutton:not(.vertical) > box > button.image-button.up, spinbutton:not(.vertical) > box > button.image-button.down { min-height: 16px; margin: 0; padding-bottom: 0; padding-top: 0; color: #43484a; background-image: none; border-style: none none none solid; border-color: rgba(205, 199, 194, 0.3); border-radius: 0; box-shadow: none; }
spinbutton:not(.vertical) > button.image-button.up, spinbutton:not(.vertical) > button.image-button.down { min-height: 16px; margin: 0; padding-bottom: 0; padding-top: 0; color: #43484a; background-image: none; border-style: none none none solid; border-color: rgba(205, 199, 194, 0.3); border-radius: 0; box-shadow: none; }
spinbutton:not(.vertical) > box > button.image-button.up:dir(rtl), spinbutton:not(.vertical) > box > button.image-button.down:dir(rtl) { border-style: none solid none none; }
spinbutton:not(.vertical) > button.image-button.up:dir(rtl), spinbutton:not(.vertical) > button.image-button.down:dir(rtl) { border-style: none solid none none; }
spinbutton:not(.vertical) > box > button.image-button.up:hover, spinbutton:not(.vertical) > box > button.image-button.down:hover { color: #2e3436; background-color: rgba(46, 52, 54, 0.05); }
spinbutton:not(.vertical) > button.image-button.up:hover, spinbutton:not(.vertical) > button.image-button.down:hover { color: #2e3436; background-color: rgba(46, 52, 54, 0.05); }
spinbutton:not(.vertical) > box > button.image-button.up:disabled, spinbutton:not(.vertical) > box > button.image-button.down:disabled { color: rgba(146, 149, 149, 0.3); background-color: transparent; }
spinbutton:not(.vertical) > button.image-button.up:disabled, spinbutton:not(.vertical) > button.image-button.down:disabled { color: rgba(146, 149, 149, 0.3); background-color: transparent; }
spinbutton:not(.vertical) > box > button.image-button.up:active, spinbutton:not(.vertical) > box > button.image-button.down:active { background-color: rgba(0, 0, 0, 0.1); box-shadow: inset 0 2px 3px -1px rgba(0, 0, 0, 0.2); }
spinbutton:not(.vertical) > button.image-button.up:active, spinbutton:not(.vertical) > button.image-button.down:active { background-color: rgba(0, 0, 0, 0.1); box-shadow: inset 0 2px 3px -1px rgba(0, 0, 0, 0.2); }
spinbutton:not(.vertical) > box > button.image-button.up:backdrop, spinbutton:not(.vertical) > box > button.image-button.down:backdrop { color: #9d9f9f; background-color: transparent; border-color: rgba(213, 208, 204, 0.3); transition: 200ms ease-out; }
spinbutton:not(.vertical) > button.image-button.up:backdrop, spinbutton:not(.vertical) > button.image-button.down:backdrop { color: #9d9f9f; background-color: transparent; border-color: rgba(213, 208, 204, 0.3); transition: 200ms ease-out; }
spinbutton:not(.vertical) > box > button.image-button.up:backdrop:disabled, spinbutton:not(.vertical) > box > button.image-button.down:backdrop:disabled { color: rgba(212, 207, 202, 0.3); background-color: transparent; border-style: none none none solid; }
spinbutton:not(.vertical) > button.image-button.up:backdrop:disabled, spinbutton:not(.vertical) > button.image-button.down:backdrop:disabled { color: rgba(212, 207, 202, 0.3); background-color: transparent; border-style: none none none solid; }
spinbutton:not(.vertical) > box > button.image-button.up:backdrop:disabled:dir(rtl), spinbutton:not(.vertical) > box > button.image-button.down:backdrop:disabled:dir(rtl) { border-style: none solid none none; }
spinbutton:not(.vertical) > button.image-button.up:backdrop:disabled:dir(rtl), spinbutton:not(.vertical) > button.image-button.down:backdrop:disabled:dir(rtl) { border-style: none solid none none; }
spinbutton:not(.vertical) > box > button.image-button.up:dir(ltr):last-child, spinbutton:not(.vertical) > box > button.image-button.down:dir(ltr):last-child { border-radius: 0 5px 5px 0; }
spinbutton:not(.vertical) > button.image-button.up:dir(ltr):last-child, spinbutton:not(.vertical) > button.image-button.down:dir(ltr):last-child { border-radius: 0 5px 5px 0; }
spinbutton:not(.vertical) > box > button.image-button.up:dir(rtl):first-child, spinbutton:not(.vertical) > box > button.image-button.down:dir(rtl):first-child { border-radius: 5px 0 0 5px; }
spinbutton:not(.vertical) > button.image-button.up:dir(rtl):first-child, spinbutton:not(.vertical) > button.image-button.down:dir(rtl):first-child { border-radius: 5px 0 0 5px; }
.osd spinbutton:not(.vertical) button { border-color: transparent; background-color: transparent; background-image: none; box-shadow: inset 0 1px rgba(255, 255, 255, 0); text-shadow: none; -gtk-icon-shadow: none; color: #eeeeec; border-style: none none none solid; border-color: rgba(0, 0, 0, 0.4); border-radius: 0; box-shadow: none; -gtk-icon-shadow: 0 1px black; }

View File

@ -22,11 +22,10 @@
undershoot.right:dir(ltr)
image.right:dir(ltr)
spinbutton.horizontal:dir(ltr)
box.horizontal:dir(ltr)
text:dir(ltr)
undershoot.left:dir(ltr)
undershoot.right:dir(ltr)
button.image-button.down:dir(ltr)
image:dir(ltr)
button.image-button.up:dir(ltr)
image:dir(ltr)
text:dir(ltr)
undershoot.left:dir(ltr)
undershoot.right:dir(ltr)
button.image-button.down:dir(ltr)
image:dir(ltr)
button.image-button.up:dir(ltr)
image:dir(ltr)