-
-
Notifications
You must be signed in to change notification settings - Fork 61
Add BackButton #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leolost2605
wants to merge
8
commits into
main
Choose a base branch
from
leolost/back-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add BackButton #692
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cbd7dd0
Add BackButton
leolost2605 bc9594d
Hide when last page
leolost2605 2d92c89
Use Gtk.Image, deprecate style class, demo (#694)
danirabbit 476bde9
Don't warn when used outside navigation view
leolost2605 79aaada
Don't hide
leolost2605 cb566a7
Bind title
leolost2605 c63f8bb
Fix build
leolost2605 2ca97ea
Merge branch 'main' into leolost/back-button
zeebok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2024 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}s. It will automatically detect when under a | ||
* {@link Adw.NavigationView} and label itself with the title of the preceding page. | ||
*/ | ||
[Version (since = "7.5.0")] | ||
public class Granite.BackButton : Gtk.Button { | ||
/** | ||
* A manually set label when used outside of {@link Adw.NavigationView} | ||
*/ | ||
public new string label { get; set; } | ||
|
||
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); | ||
|
||
child = box; | ||
|
||
map.connect (on_map); | ||
clicked.connect (on_click); | ||
|
||
bind_property ("label", label_widget, "label"); | ||
} | ||
|
||
private void on_map () { | ||
var navigation_view = (Adw.NavigationView) get_ancestor (typeof (Adw.NavigationView)); | ||
|
||
if (navigation_view == null) { | ||
return; | ||
} | ||
|
||
var navigation_page = (Adw.NavigationPage) get_ancestor (typeof (Adw.NavigationPage)); | ||
|
||
if (navigation_view == null) { | ||
return; | ||
} | ||
|
||
var previous_page = navigation_view.get_previous_page (navigation_page); | ||
|
||
if (previous_page != null) { | ||
label = previous_page.title; | ||
} | ||
} | ||
|
||
private void on_click () { | ||
var navigation_view = (Adw.NavigationView) get_ancestor (typeof (Adw.NavigationView)); | ||
|
||
if (navigation_view != null) { | ||
navigation_view.pop (); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that page title can and will change.
The logic in libadwaita's own back buttons is also a lot more complicated because navigation views can be nested, and can also be structured like:
navigation split view
sidebar: navigation view
content: navigation view
and that situation is handled correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, tho the latter involves private api - forgot about that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed although I think that would be kinda questionable UX while the page itself is not visible?
I'm guessing that if the button is on the deepest view and there is no page left it still appears and instead navigates one above?
I think for now and for our use case it might be enough to leave that out (since we also don't hide when there is no preceding page)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questionable yes, but I mean the property is writable, so...
Correct.
As you prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the nested part cc @danirabbit ?