Update the design for progress bars

We now use a narrower trough and paint the optional text
beside the trough instead of inside it. This makes for a much
cleaner appearance and more readable text.
This commit is contained in:
William Jon McCann 2014-05-07 05:13:59 -04:00
parent 644f08a771
commit 74405cc964

View File

@ -63,8 +63,8 @@
*/ */
#define MIN_HORIZONTAL_BAR_WIDTH 150 #define MIN_HORIZONTAL_BAR_WIDTH 150
#define MIN_HORIZONTAL_BAR_HEIGHT 20 #define MIN_HORIZONTAL_BAR_HEIGHT 6
#define MIN_VERTICAL_BAR_WIDTH 22 #define MIN_VERTICAL_BAR_WIDTH 7
#define MIN_VERTICAL_BAR_HEIGHT 80 #define MIN_VERTICAL_BAR_HEIGHT 80
@ -728,6 +728,8 @@ gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
cairo_t *cr, cairo_t *cr,
GtkOrientation orientation, GtkOrientation orientation,
gboolean inverted, gboolean inverted,
int x,
int y,
int width, int width,
int height) int height)
{ {
@ -744,13 +746,13 @@ gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
if (orientation == GTK_ORIENTATION_HORIZONTAL) if (orientation == GTK_ORIENTATION_HORIZONTAL)
{ {
gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width); gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
area.y = padding.top; area.y = y + padding.top;
area.height = height - padding.top - padding.bottom; area.height = height - padding.top - padding.bottom;
} }
else else
{ {
gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height); gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
area.x = padding.left; area.x = x + padding.left;
area.width = width - padding.left - padding.right; area.width = width - padding.left - padding.right;
} }
@ -769,6 +771,8 @@ gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
gint amount, gint amount,
GtkOrientation orientation, GtkOrientation orientation,
gboolean inverted, gboolean inverted,
int x,
int y,
int width, int width,
int height) int height)
{ {
@ -789,10 +793,10 @@ gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
{ {
area.width = amount; area.width = amount;
area.height = height - padding.top - padding.bottom; area.height = height - padding.top - padding.bottom;
area.y = padding.top; area.y = y + padding.top;
if (!inverted) if (!inverted)
area.x = padding.left; area.x = x + padding.left;
else else
area.x = width - amount - padding.right; area.x = width - amount - padding.right;
} }
@ -800,10 +804,10 @@ gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
{ {
area.width = width - padding.left - padding.right; area.width = width - padding.left - padding.right;
area.height = amount; area.height = amount;
area.x = padding.left; area.x = x + padding.left;
if (!inverted) if (!inverted)
area.y = padding.top; area.y = y + padding.top;
else else
area.y = height - amount - padding.bottom; area.y = height - amount - padding.bottom;
} }
@ -839,7 +843,7 @@ gtk_progress_bar_paint_text (GtkProgressBar *pbar,
PangoRectangle logical_rect; PangoRectangle logical_rect;
GdkRectangle prelight_clip, start_clip, end_clip; GdkRectangle prelight_clip, start_clip, end_clip;
gfloat text_xalign = 0.5; gfloat text_xalign = 0.5;
gfloat text_yalign = 0.5; gfloat text_yalign = 0.0;
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget); state = gtk_widget_get_state_flags (widget);
@ -967,6 +971,7 @@ gtk_progress_bar_draw (GtkWidget *widget,
GtkStateFlags state; GtkStateFlags state;
GtkBorder padding; GtkBorder padding;
int width, height; int width, height;
int bar_width, bar_height;
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget); state = gtk_widget_get_state_flags (widget);
@ -982,11 +987,22 @@ gtk_progress_bar_draw (GtkWidget *widget,
width = gtk_widget_get_allocated_width (widget); width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget); height = gtk_widget_get_allocated_height (widget);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
bar_height = MIN_HORIZONTAL_BAR_HEIGHT;
bar_width = width;
}
else
{
bar_width = MIN_VERTICAL_BAR_WIDTH;
bar_height = height;
}
gtk_style_context_save (context); gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH); gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
gtk_render_background (context, cr, 0, 0, width, height); gtk_render_background (context, cr, width - bar_width, height - bar_height, bar_width, bar_height);
gtk_render_frame (context, cr, 0, 0, width, height); gtk_render_frame (context, cr, width - bar_width, height - bar_height, bar_width, bar_height);
gtk_style_context_restore (context); gtk_style_context_restore (context);
@ -994,7 +1010,8 @@ gtk_progress_bar_draw (GtkWidget *widget,
{ {
gtk_progress_bar_paint_activity (pbar, cr, gtk_progress_bar_paint_activity (pbar, cr,
orientation, inverted, orientation, inverted,
width, height); width - bar_width, height - bar_height,
bar_width, bar_height);
if (priv->show_text) if (priv->show_text)
{ {
@ -1014,13 +1031,15 @@ gtk_progress_bar_draw (GtkWidget *widget,
gint space; gint space;
if (orientation == GTK_ORIENTATION_HORIZONTAL) if (orientation == GTK_ORIENTATION_HORIZONTAL)
space = width - padding.left - padding.right; space = bar_width - padding.left - padding.right;
else else
space = height - padding.top - padding.bottom; space = bar_height - padding.top - padding.bottom;
amount = space * gtk_progress_bar_get_fraction (pbar); amount = space * gtk_progress_bar_get_fraction (pbar);
gtk_progress_bar_paint_continuous (pbar, cr, amount, orientation, inverted, width, height); gtk_progress_bar_paint_continuous (pbar, cr, amount, orientation, inverted,
width - bar_width, height - bar_height,
bar_width, bar_height);
if (priv->show_text) if (priv->show_text)
gtk_progress_bar_paint_text (pbar, cr, -1, amount, orientation, inverted, width, height); gtk_progress_bar_paint_text (pbar, cr, -1, amount, orientation, inverted, width, height);