Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions demo/Views/ControlsView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public class ControlsView : DemoPage {
tooltip_text = "Gtk.ToggleButton.icon_name"
};

var back_button = new Gtk.Button.with_label ("Granite.CssClass.BACK");
back_button.add_css_class (Granite.CssClass.BACK);
var back_button = new Granite.BackButton ("Granite.BackButton") {
halign = START
};

var destructive_button = new Gtk.Button.with_label ("Granite.CssClass.DESTRUCTIVE");
destructive_button.add_css_class (Granite.CssClass.DESTRUCTIVE);
Expand Down
7 changes: 1 addition & 6 deletions lib/Constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Granite {
/**
* Style class for shaping a {@link Gtk.Button}
*/
[Version (deprecated = true, deprecated_since = "7.7.0", replacement = "Granite.CssClass.BACK")]
[Version (deprecated = true, deprecated_since = "7.7.0", replacement = "Granite.BackButton")]
public const string STYLE_CLASS_BACK_BUTTON = "back-button";
/**
* Style class to match the window background
Expand Down Expand Up @@ -226,11 +226,6 @@ namespace Granite {
*/
public const string ACCENT = "accent";

/**
* Style class for a {@link Gtk.Button} which is used to navigate backwards
*/
public const string BACK = "back-button";

/**
* Style class for adding a small shadow to a container such as for image thumbnails
*/
Expand Down
43 changes: 5 additions & 38 deletions lib/Styles/Gtk/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,6 @@ button {
}
}

// Stopgap since we can't do angled buttons in GtkCSS, and generating all
// the necessary SVGs for light/dark and accent color combinations is
// untenable. Ideally we'd deprecate this in favor of something like a
// Granite.BackButton with custom drawing; until then, stick an icon in it.

&.back-button {
background-repeat: no-repeat no-repeat;
background-size: 16px, cover;

&:dir(ltr) {
background-image:
-gtk-icontheme('go-previous-symbolic'),
linear-gradient(
to bottom,
#{'alpha(@highlight_color, 0.2)'},
rgba(white, 0)
);
padding-left: calc(#{rem(9px)} + 16px);
background-position:
#{rem(6px)} 50%,
center, center;
}

&:dir(rtl) {
background-image:
-gtk-icontheme('go-next-symbolic'),
linear-gradient(
to bottom,
#{'alpha(@highlight_color, 0.2)'},
rgba(white, 0)
);
padding-right: calc(#{rem(9px)} + 16px);
background-position:
calc(100% - #{rem(6px)}) 50%,
center, center;
}
}

&.osd {
@include control;
@include border-interactive-roundrect;
Expand Down Expand Up @@ -150,4 +112,9 @@ button {
shadow(2);
}
}

// Almost certainly a button with text and image
> box.horizontal {
border-spacing: $button-spacing / 2;
}
}
39 changes: 39 additions & 0 deletions lib/Widgets/BackButton.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-2.0-or-later
*/

/**
* BackButton is meant to be used in headers to navigate in
* {@link Adw.NavigationView}.
*
* By default `action_name` is set to `navigation.pop`
*/
[Version (since = "7.7.0")]
public class Granite.BackButton : Gtk.Button {
/**
* Text of the label inside of #this
*/
public new string label { get; set; }

public BackButton (string label) {
Object (label: label);
}

construct {
var image = new Gtk.Image.from_icon_name ("go-previous-symbolic");

var label_widget = new Gtk.Label ("");

var box = new Gtk.Box (HORIZONTAL, 0);
box.append (image);
box.append (label_widget);

action_name = "navigation.pop";
child = box;
tooltip_markup = Granite.markup_accel_tooltip ({"<alt>Left"});

add_css_class ("text-button");
bind_property ("label", label_widget, "label");
}
}
1 change: 1 addition & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ libgranite_sources = files(
'Widgets/AbstractSettingsPage.vala',
'Widgets/AbstractSimpleSettingsPage.vala',
'Widgets/AccelLabel.vala',
'Widgets/BackButton.vala',
'Widgets/Bin.vala',
'Widgets/Box.vala',
'Widgets/DatePicker.vala',
Expand Down