Skip to content

Commit

Permalink
Merge pull request linuxmint#188 from mtwebster/breadcrumbs-themes-suck
Browse files Browse the repository at this point in the history
Fix breadcrumb rendering for all themes.
  • Loading branch information
clefebvre committed Jan 22, 2013
2 parents 124cf7b + 9c31ef8 commit 1320bb1
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 134 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Development: 1/22/2013:

- Breadcrumbs: Stylable by themes, see src/nemo-styles-fallback.css for default style information.
Border radius, color, background color, and text color can be customized through that.
107 changes: 54 additions & 53 deletions libnemo-private/nemo-pathbar-button.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ nemo_pathbar_button_init (NemoPathbarButton *button)
{
button->is_left_end = FALSE;
button->highlight = FALSE;

GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (button));
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
gtk_style_context_add_class (context, "nemo-pathbar-button");
}

static void
Expand All @@ -53,6 +57,15 @@ nemo_pathbar_button_class_init (NemoPathbarButtonClass *klass)

widget_class->draw = nemo_pathbar_button_draw;

gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("border-radius",
"The border radius of the breadcrumbs border",
"The border radius of the breadcrumbs border",
G_MININT,
G_MAXINT,
0,
G_PARAM_READABLE));

}

GtkWidget *
Expand All @@ -68,12 +81,11 @@ nemo_pathbar_button_finalize (GObject *object)
}

#define A_A CAIRO_ANTIALIAS_SUBPIXEL
#define RAD 5.0
#define _270_DEG 270.0 * (M_PI/180.0)
#define _180_DEG 180.0 * (M_PI/180.0)
#define _90_DEG 90.0 * (M_PI/180.0)
#define H_RAD 1 /* Highlight radius */
#define H_O 2 /* Highlight offset */

#define H_O 3 /* Highlight offset */
#define H_T_COMP H_O + 0 /* Highlight tangential compensation */

static void
Expand All @@ -85,13 +97,21 @@ do_draw_middle_element (GtkStyleContext *context,
gint h,
gboolean highlight)
{
GtkStateFlags state = gtk_style_context_get_state (context);
GdkRGBA border_color;
gtk_style_context_get_border_color (context, state, &border_color);

gint offset = rintf ((float) h / PATHBAR_BUTTON_OFFSET_FACTOR);

cairo_save (cr);
cairo_set_antialias (cr, A_A);

cairo_set_source_rgb (cr, .5, .5, .5);
cairo_set_line_width (cr, 2.0);
cairo_set_source_rgba (cr, border_color.red,
border_color.green,
border_color.blue,
border_color.alpha);

cairo_set_line_width (cr, 3.0);

cairo_move_to (cr, x, y);
cairo_line_to (cr, x+w-offset, y);
Expand Down Expand Up @@ -138,21 +158,32 @@ do_draw_end_element (GtkStyleContext *context,
gint h,
gboolean highlight)
{

GtkStateFlags state = gtk_style_context_get_state (context);
GdkRGBA border_color;
gint rad;
gtk_style_context_get_border_color (context, state, &border_color);
gtk_style_context_get_style (context, "border-radius", &rad, NULL);

gint offset = rintf ((float) h / PATHBAR_BUTTON_OFFSET_FACTOR);
cairo_save (cr);
cairo_set_antialias (cr, A_A);

cairo_set_source_rgb (cr, .5, .5, .5);
cairo_set_line_width (cr, 2.0);
cairo_set_source_rgba (cr, border_color.red,
border_color.green,
border_color.blue,
border_color.alpha);

cairo_move_to (cr, x+RAD, y);
cairo_set_line_width (cr, 3.0);

cairo_move_to (cr, x+rad, y);
cairo_line_to (cr, x+w-offset, y);
cairo_line_to (cr, x+w-1, y+(h/2));
cairo_line_to (cr, x+w-offset, y+h);
cairo_line_to (cr, x+RAD, y+h);
cairo_arc (cr, x+RAD, y+h-RAD, RAD, _90_DEG, _180_DEG);
cairo_line_to (cr, x, y+RAD);
cairo_arc (cr, x+RAD, y+RAD, RAD, _180_DEG, _270_DEG);
cairo_line_to (cr, x+rad, y+h);
cairo_arc (cr, x+rad, y+h-rad, rad, _90_DEG, _180_DEG);
cairo_line_to (cr, x, y+rad);
cairo_arc (cr, x+rad, y+rad, rad, _180_DEG, _270_DEG);

cairo_stroke_preserve (cr);
cairo_clip (cr);
Expand All @@ -169,14 +200,14 @@ do_draw_end_element (GtkStyleContext *context,
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, .5);

cairo_move_to (cr, x+H_RAD+H_O, y+H_O);
cairo_move_to (cr, x+(rad-H_O)+H_O, y+H_O);
cairo_line_to (cr, x+w-offset-H_O+H_T_COMP, y+H_O);
cairo_line_to (cr, x+w-1-H_O, y+(h/2));
cairo_line_to (cr, x+w-offset-H_O+H_T_COMP, y+h-H_O);
cairo_line_to (cr, x+H_RAD+H_O, y+h-H_O);
cairo_arc (cr, x+H_RAD+H_O, y+h-H_RAD-H_O, H_RAD, _90_DEG, _180_DEG);
cairo_line_to (cr, x+H_O, y+H_RAD+H_O);
cairo_arc (cr, x+H_RAD+H_O, y+H_RAD+H_O, H_RAD, _180_DEG, _270_DEG);
cairo_line_to (cr, x+(rad-H_O)+H_O, y+h-H_O);
cairo_arc (cr, x+(rad-H_O)+H_O, y+h-(rad-H_O)-H_O, (rad-H_O), _90_DEG, _180_DEG);
cairo_line_to (cr, x+H_O, y+(rad-H_O)+H_O);
cairo_arc (cr, x+(rad-H_O)+H_O, y+(rad-H_O)+H_O, (rad-H_O), _180_DEG, _270_DEG);

cairo_stroke (cr);

Expand All @@ -192,53 +223,23 @@ nemo_pathbar_button_draw (GtkWidget *widget,

GtkAllocation allocation;
GtkStyleContext *context;
GtkStateFlags state;

context = gtk_widget_get_style_context (widget);
state = gtk_style_context_get_state (context);

gtk_style_context_save (context);

switch (state) {
case GTK_STATE_FLAG_NORMAL:
gtk_style_context_add_class (context, "nemo-pathbar-button");
break;
case GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT:
gtk_style_context_add_class (context, "nemo-pathbar-button-active-hover");
break;
case GTK_STATE_FLAG_PRELIGHT:
case GTK_STATE_FLAG_FOCUSED:
case GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_FOCUSED:
gtk_style_context_add_class (context, "nemo-pathbar-button-hover");
break;
case GTK_STATE_FLAG_ACTIVE:
case GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_BACKDROP:
gtk_style_context_add_class (context, "nemo-pathbar-button-active");
break;
default:
gtk_style_context_add_class (context, "nemo-pathbar-button");
break;
}

gtk_widget_get_allocation (widget, &allocation);

x = 0;
y = 0;
width = allocation.width;
height = allocation.height;
x = 2;
y = 1;
width = allocation.width-3;
height = allocation.height-2;

if (button->is_left_end)
do_draw_end_element (context, cr, x, y, width, height, button->highlight);
else
do_draw_middle_element (context, cr, x, y, width, height, button->highlight);

gtk_style_context_restore (context);

gtk_style_context_add_class (context, "no-displacement");
gtk_style_context_add_class (context, "breadcrumbs-no-displacement");

return GTK_WIDGET_CLASS (draw_chain_class)->draw (widget, cr);


}

void
Expand All @@ -262,7 +263,7 @@ nemo_pathbar_button_get_preferred_size (GtkWidget *button, GtkRequisition *requi
{
GtkRequisition req;
gtk_widget_get_preferred_size (button, &req, NULL);
gint offset = rintf ((float) req.height / PATHBAR_BUTTON_OFFSET_FACTOR) + 2;
gint offset = rintf ((float) req.height / PATHBAR_BUTTON_OFFSET_FACTOR) + 4;
if (!NEMO_PATHBAR_BUTTON (button)->is_left_end) {
req.width -= offset;
}
Expand Down
26 changes: 22 additions & 4 deletions src/nemo-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,11 +1079,29 @@ nemo_application_add_app_css_provider (void)

provider = gtk_css_provider_new ();

if (!css_provider_load_from_resource (provider, "/org/nemo/nemo-style.css", &error))
if (!css_provider_load_from_resource (provider, "/org/nemo/nemo-style-fallback.css", &error))
{
g_warning ("Failed to load css file: %s", error->message);
g_warning ("Failed to load fallback css file: %s", error->message);
g_error_free (error);
goto out;
goto out_a;
}

screen = gdk_screen_get_default ();

gtk_style_context_add_provider_for_screen (screen,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);

out_a:
g_object_unref (provider);

provider = gtk_css_provider_new ();

if (!css_provider_load_from_resource (provider, "/org/nemo/nemo-style-application.css", &error))
{
g_warning ("Failed to load application css file: %s", error->message);
g_error_free (error);
goto out_b;
}

screen = gdk_screen_get_default ();
Expand All @@ -1092,7 +1110,7 @@ nemo_application_add_app_css_provider (void)
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

out:
out_b:
g_object_unref (provider);
}

Expand Down
13 changes: 7 additions & 6 deletions src/nemo-pathbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ nemo_path_bar_size_allocate (GtkWidget *widget,

nemo_pathbar_button_get_preferred_size (BUTTON_DATA (path_bar->button_list->data)->button,
&child_requisition, allocation->height);
gint offset = rintf ((float) allocation->height / PATHBAR_BUTTON_OFFSET_FACTOR + 2);
gint offset = rintf ((float) allocation->height / PATHBAR_BUTTON_OFFSET_FACTOR + 4);

width += child_requisition.width;

Expand Down Expand Up @@ -669,9 +669,9 @@ nemo_path_bar_size_allocate (GtkWidget *widget,
child = BUTTON_DATA (list->data)->button;

if (first_element)
gtk_label_set_width_chars (GTK_LABEL (BUTTON_DATA (list->data)->pre_padding), 0);
else
gtk_label_set_width_chars (GTK_LABEL (BUTTON_DATA (list->data)->pre_padding), 1);
else
gtk_label_set_width_chars (GTK_LABEL (BUTTON_DATA (list->data)->pre_padding), 2);

gtk_widget_get_preferred_size (child, &child_requisition, NULL);

Expand Down Expand Up @@ -1731,8 +1731,9 @@ make_directory_button (NemoPathBar *path_bar,

button_data->image = gtk_image_new ();
child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1);
button_data->pre_padding = get_padding_widget(0);
gtk_box_pack_start (GTK_BOX (child), button_data->pre_padding, FALSE, FALSE, 0);
button_data->pre_padding = get_padding_widget(1);

gtk_box_pack_start (GTK_BOX (child), button_data->pre_padding, FALSE, FALSE, 1);
switch (button_data->type) {
case ROOT_BUTTON:
case HOME_BUTTON:
Expand Down Expand Up @@ -1764,7 +1765,7 @@ make_directory_button (NemoPathBar *path_bar,
gtk_box_pack_start (GTK_BOX (child), button_data->alignment, FALSE, FALSE, 1);
button_data->is_base_dir = base_dir;
}
gtk_box_pack_start (GTK_BOX (child), get_padding_widget(1), FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (child), get_padding_widget(2), FALSE, FALSE, 0);

if (button_data->path == NULL) {
button_data->path = g_object_ref (path);
Expand Down
38 changes: 38 additions & 0 deletions src/nemo-style-application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.breadcrumbs-no-displacement {
-GtkButton-child-displacement-x: 0;
-GtkButton-child-displacement-y: 0;
}

.nemo-inactive-pane .view {
background-color: shade(@theme_base_color, 0.9);
}

/* for nemo-cell-renderer-disk.c */

.nemo-disk-renderer-bg {
border-radius: 1px;
border-style: solid;
border-width: 1px;
border-color: shade(@theme_bg_color, .65);
}

.nemo-disk-renderer-bg row:selected {
border-radius: 1px;
border-style: solid;
border-width: 1px;
border-color: shade(@theme_bg_color, 2.0);
}

.nemo-disk-renderer-fg {
border-radius: 1px;
border-style: solid;
border-width: 1px;
border-color: shade(@theme_selected_bg_color, 1.0);
}

.nemo-disk-renderer-fg row:selected {
border-radius: 1px;
border-style: solid;
border-width: 1px;
border-color: shade(@theme_fg_color, 2.0);
}
36 changes: 36 additions & 0 deletions src/nemo-style-fallback.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

.nemo-pathbar-button,
NemoPathbarButton {
background-image: -gtk-gradient(linear, left top, left bottom,
color-stop (0, shade(alpha(@bg_color, 0.8), 1.1)),
color-stop (.3, shade(alpha(@bg_color, 0.8), 1.1)),
color-stop (.7, shade(alpha(@bg_color, 0.8), 0.90)),
color-stop (1, shade(alpha(@bg_color, 0.8), 0.80)));
border-color: #808080;
-NemoPathbarButton-border-radius: 3px;
}

NemoPathbarButton:active {
background-image: -gtk-gradient(linear, left top, left bottom,
color-stop (0, shade(alpha(@bg_color, 0.8), .8)),
color-stop (.3, shade(alpha(@bg_color, 0.8), .9)),
color-stop (1, shade(alpha(@bg_color, 0.8), 1.0)));
border-color: #808080;
}

NemoPathbarButton:hover {
background-image: -gtk-gradient(linear, left top, left bottom,
color-stop (0, shade(alpha(@selected_bg_color, 0.8), 1.25)),
color-stop (.3, shade(alpha(@selected_bg_color, 0.8), 1.25)),
color-stop (.7, shade(alpha(@selected_bg_color, 0.8), 0.95)),
color-stop (1, shade(alpha(@selected_bg_color, 0.8), 0.85)));
border-color: #808080;
}

NemoPathbarButton:active:hover {
background-image: -gtk-gradient(linear, left top, left bottom,
color-stop (0, shade(alpha(@selected_bg_color, 0.8), .80)),
color-stop (.3, shade(alpha(@selected_bg_color, 0.8), .95)),
color-stop (1, shade(alpha(@selected_bg_color, 0.8), 1.25)));
border-color: #808080;
}
Loading

0 comments on commit 1320bb1

Please sign in to comment.