diff options
author | Timm Bäder <mail@baedert.org> | 2019-07-15 06:38:51 +0200 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2019-07-15 06:38:51 +0200 |
commit | 831309eed2c56894e7b0bfbf4878f38cac41ab54 (patch) | |
tree | 346f9402c5af836a9f83d549a12ece5ccf39788d /gtk/gtkprogressbar.c | |
parent | 4bb4a98493a139dfb22bd6a87b1f0ca18140399a (diff) | |
download | gtk+-831309eed2c56894e7b0bfbf4878f38cac41ab54.tar.gz |
progressbar: Use box layout
Instead of the custom layouting we did before.
Diffstat (limited to 'gtk/gtkprogressbar.c')
-rw-r--r-- | gtk/gtkprogressbar.c | 160 |
1 files changed, 25 insertions, 135 deletions
diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c index 3fc53ff35b..74a975c914 100644 --- a/gtk/gtkprogressbar.c +++ b/gtk/gtkprogressbar.c @@ -38,6 +38,7 @@ #include "gtkprivate.h" #include "gtkstylecontextprivate.h" #include "gtkwidgetprivate.h" +#include "gtkboxlayout.h" #include "a11y/gtkprogressbaraccessible.h" @@ -155,11 +156,6 @@ static void gtk_progress_bar_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gtk_progress_bar_size_allocate (GtkWidget *widget, - int width, - int height, - int baseline); - static void gtk_progress_bar_act_mode_enter (GtkProgressBar *progress); static void gtk_progress_bar_act_mode_leave (GtkProgressBar *progress); static void gtk_progress_bar_finalize (GObject *object); @@ -168,14 +164,6 @@ static void gtk_progress_bar_set_orientation (GtkProgressBar *progress, static void gtk_progress_bar_direction_changed (GtkWidget *widget, GtkTextDirection previous_dir); -static void gtk_progress_bar_measure (GtkWidget *widget, - GtkOrientation orientation, - gint for_size, - gint *minimum, - gint *natural, - gint *minimum_baseline, - gint *natural_baseline); - G_DEFINE_TYPE_WITH_CODE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_WIDGET, G_ADD_PRIVATE (GtkProgressBar) G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)) @@ -193,8 +181,6 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class) gobject_class->get_property = gtk_progress_bar_get_property; gobject_class->finalize = gtk_progress_bar_finalize; - widget_class->measure = gtk_progress_bar_measure; - widget_class->size_allocate = gtk_progress_bar_size_allocate; widget_class->direction_changed = gtk_progress_bar_direction_changed; g_object_class_override_property (gobject_class, PROP_ORIENTATION, "orientation"); @@ -274,6 +260,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class) gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_PROGRESS_BAR_ACCESSIBLE); gtk_widget_class_set_css_name (widget_class, I_("progressbar")); + gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT); } static void @@ -475,7 +462,6 @@ gtk_progress_bar_init (GtkProgressBar *pbar) { GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); - priv->orientation = GTK_ORIENTATION_HORIZONTAL; priv->inverted = FALSE; priv->pulse_fraction = 0.1; priv->activity_pos = 0; @@ -487,8 +473,6 @@ gtk_progress_bar_init (GtkProgressBar *pbar) priv->text = NULL; priv->fraction = 0.0; - _gtk_orientable_set_style_classes (GTK_ORIENTABLE (pbar)); - priv->trough_widget = gtk_gizmo_new ("trough", NULL, allocate_trough, @@ -499,7 +483,10 @@ gtk_progress_bar_init (GtkProgressBar *pbar) priv->progress_widget = gtk_gizmo_new ("progress", NULL, NULL, NULL, NULL); gtk_widget_set_parent (priv->progress_widget, priv->trough_widget); - update_node_classes (pbar); + /* horizontal is default */ + priv->orientation = GTK_ORIENTATION_VERTICAL; /* Just to force an update... */ + gtk_progress_bar_set_orientation (pbar, GTK_ORIENTATION_HORIZONTAL); + _gtk_orientable_set_style_classes (GTK_ORIENTABLE (pbar)); } static void @@ -626,122 +613,6 @@ get_current_text (GtkProgressBar *pbar) return g_strdup_printf (C_("progress bar label", "%.0f %%"), priv->fraction * 100.0); } -static void -gtk_progress_bar_size_allocate (GtkWidget *widget, - int width, - int height, - int baseline) -{ - GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (GTK_PROGRESS_BAR (widget)); - gint bar_width, bar_height; - gint text_width, text_height, text_min, text_nat; - GtkAllocation alloc; - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - gtk_widget_measure (priv->trough_widget, GTK_ORIENTATION_VERTICAL, -1, - &bar_height, NULL, - NULL, NULL); - bar_width = width; - } - else - { - gtk_widget_measure (priv->trough_widget, GTK_ORIENTATION_HORIZONTAL, -1, - &bar_width, NULL, - NULL, NULL); - bar_height = height; - } - - alloc.x = width - bar_width; - alloc.y = height - bar_height; - alloc.width = bar_width; - alloc.height = bar_height; - - gtk_widget_size_allocate (priv->trough_widget, &alloc, -1); - - if (!priv->show_text) - return; - - gtk_widget_measure (priv->label, GTK_ORIENTATION_HORIZONTAL, -1, - &text_min, &text_nat, - NULL, NULL); - gtk_widget_measure (priv->label, GTK_ORIENTATION_VERTICAL, -1, - &text_height, NULL, - NULL, NULL); - - text_width = CLAMP (text_nat, text_min, width); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - alloc.x = (width - text_width) / 2; - alloc.y = 0; - alloc.width = text_width; - alloc.height = text_height; - } - else - { - alloc.x = width - text_width; - alloc.y = (height - text_height) / 2; - alloc.width = text_width; - alloc.height = text_height; - } - - gtk_widget_size_allocate (priv->label, &alloc, -1); -} - -static void -gtk_progress_bar_measure (GtkWidget *widget, - GtkOrientation orientation, - int for_size, - int *minimum, - int *natural, - int *minimum_baseline, - int *natural_baseline) -{ - GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget); - GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); - gint text_minimum, text_natural; - gint trough_minimum, trough_natural; - - if (priv->show_text) - gtk_widget_measure (priv->label, orientation, -1, - &text_minimum, &text_natural, - NULL, NULL); - else - text_minimum = text_natural = 0; - - gtk_widget_measure (priv->trough_widget, orientation, -1, - &trough_minimum, &trough_natural, - NULL, NULL); - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - *minimum = MAX (text_minimum, trough_minimum); - *natural = MAX (text_natural, trough_natural); - } - else - { - *minimum = text_minimum + trough_minimum; - *natural = text_natural + trough_natural; - } - } - else - { - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - *minimum = text_minimum + trough_minimum; - *natural = text_natural + trough_natural; - } - else - { - *minimum = MAX (text_minimum, trough_minimum); - *natural = MAX (text_natural, trough_natural); - } - } -} - static gboolean tick_cb (GtkWidget *widget, GdkFrameClock *frame_clock, @@ -1087,16 +958,35 @@ gtk_progress_bar_set_orientation (GtkProgressBar *pbar, GtkOrientation orientation) { GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); + GtkBoxLayout *layout; if (priv->orientation == orientation) return; priv->orientation = orientation; + if (orientation == GTK_ORIENTATION_HORIZONTAL) + { + gtk_widget_set_vexpand (priv->trough_widget, FALSE); + gtk_widget_set_hexpand (priv->trough_widget, TRUE); + gtk_widget_set_halign (priv->trough_widget, GTK_ALIGN_FILL); + gtk_widget_set_valign (priv->trough_widget, GTK_ALIGN_CENTER); + } + else + { + gtk_widget_set_vexpand (priv->trough_widget, TRUE); + gtk_widget_set_hexpand (priv->trough_widget, FALSE); + gtk_widget_set_halign (priv->trough_widget, GTK_ALIGN_CENTER); + gtk_widget_set_valign (priv->trough_widget, GTK_ALIGN_FILL); + } + _gtk_orientable_set_style_classes (GTK_ORIENTABLE (pbar)); update_node_classes (pbar); gtk_widget_queue_resize (GTK_WIDGET (pbar)); + layout = GTK_BOX_LAYOUT (gtk_widget_get_layout_manager (GTK_WIDGET (pbar))); + gtk_orientable_set_orientation (GTK_ORIENTABLE (layout), GTK_ORIENTATION_VERTICAL); + g_object_notify (G_OBJECT (pbar), "orientation"); } |