app: walk back through the screens you came from
The arrow was hardwired per screen: from a review it led to the match history, even when the review was opened from a clip's card, and the clip view was torn down on the way out. App now keeps the trail of screens behind the one on screen. Opening a row, a card, or an exported clip pushes the screen it came from; the arrow and Escape pop. The title bar's Clips and Settings buttons and the number keys jump to a root with the match history behind them. A clip or a review that back can still reach is kept, paused where it was, so returning shows it again rather than reopening it; either is dropped once the trail no longer holds it.
This commit is contained in:
1 parent
c452fab735
commit
7213c119da
4 files changed
+115
-75
No files matched your search
+100
-61
@@ -115,6 +115,8 @@ pub struct Notice {
|
||||
|
||||
pub struct App {
|
||||
pub screen: Screen,
|
||||
/// The screens behind this one, oldest first: the back arrow returns through them.
|
||||
pub behind: Vec<Screen>,
|
||||
pub settings_tab: SettingsTab,
|
||||
pub dark: bool,
|
||||
pub daemon: Daemon,
|
||||
@@ -190,6 +192,7 @@ impl App {
|
||||
let live = std::env::args().any(|arg| arg == "--live");
|
||||
let mut app = Self {
|
||||
screen: Screen::History,
|
||||
behind: Vec::new(),
|
||||
settings_tab: SettingsTab::Quick,
|
||||
dark: true,
|
||||
daemon: Daemon::start(headless && !live),
|
||||
@@ -389,6 +392,73 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
/// Show `screen`, leaving the one on screen behind for the back arrow. What the screen
|
||||
/// being left was playing stops; one that stays behind keeps its place, paused.
|
||||
pub fn go(&mut self, screen: Screen) {
|
||||
if screen == self.screen {
|
||||
return;
|
||||
}
|
||||
// The clip view and the review each hold one screen's state, and the one this shows
|
||||
// replaces it: an entry for the same screen deeper in the trail names what is gone.
|
||||
if matches!(screen, Screen::Clip | Screen::Review) {
|
||||
self.behind.retain(|behind| *behind != screen);
|
||||
}
|
||||
self.pause_away();
|
||||
self.behind.push(self.screen);
|
||||
self.screen = screen;
|
||||
self.settle();
|
||||
}
|
||||
|
||||
/// Return to the screen left behind. The match history is the root and has none, so
|
||||
/// there it does nothing.
|
||||
pub fn back(&mut self) {
|
||||
let Some(screen) = self.behind.pop() else {
|
||||
return;
|
||||
};
|
||||
self.pause_away();
|
||||
self.screen = screen;
|
||||
self.settle();
|
||||
}
|
||||
|
||||
/// Jump to a screen the title bar or a number key names, with the match history behind
|
||||
/// it. Whatever the trail held is dropped: this is a place of its own, not one on top.
|
||||
pub fn jump(&mut self, screen: Screen) {
|
||||
if self.screen != screen {
|
||||
self.pause_away();
|
||||
}
|
||||
self.behind.clear();
|
||||
if screen != Screen::History {
|
||||
self.behind.push(Screen::History);
|
||||
}
|
||||
self.screen = screen;
|
||||
self.settle();
|
||||
}
|
||||
|
||||
/// Stop what the screen being left is playing: it is out of sight, and its sound would
|
||||
/// carry under the next screen.
|
||||
fn pause_away(&mut self) {
|
||||
match self.screen {
|
||||
Screen::Clip => {
|
||||
if let Some(player) = self.clip.as_ref().and_then(|view| view.player.as_ref()) {
|
||||
player.pause();
|
||||
}
|
||||
}
|
||||
Screen::Review => self.review.pause(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Drop the state of screens the trail no longer holds. A clip view and a review are each
|
||||
/// a player and a timeline, kept only while back can return to them.
|
||||
fn settle(&mut self) {
|
||||
if self.screen != Screen::Clip && !self.behind.contains(&Screen::Clip) {
|
||||
self.clip = None;
|
||||
}
|
||||
if self.screen != Screen::Review && !self.behind.contains(&Screen::Review) {
|
||||
screens::review::leave(self);
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop the clip and the review where they are. The window is going away and the app stays
|
||||
/// in the tray, so sound with no picture should not carry on: reopening shows the same
|
||||
/// screen, paused at the same second.
|
||||
@@ -997,8 +1067,12 @@ impl App {
|
||||
// Keep the clock running so the status stays live even when nothing draws.
|
||||
tx.wake_after(Duration::from_millis(1000));
|
||||
|
||||
// The clip view plays its file; leaving the screen behind stops it with the view.
|
||||
if self.screen != Screen::Clip && self.clip.take().is_some() {
|
||||
// The clip view plays its file; leaving it for good stops it with the view. It stays
|
||||
// under the review, so back returns to the clip paused where it was.
|
||||
if self.screen != Screen::Clip
|
||||
&& !self.behind.contains(&Screen::Clip)
|
||||
&& self.clip.take().is_some()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
if self.screen == Screen::Review {
|
||||
@@ -1031,30 +1105,21 @@ pub fn on_key(app: &mut App, event: &KeyEvent, _tx: &mut Tx) -> bool {
|
||||
let command = event.mods.ctrl || event.mods.cmd;
|
||||
match (&event.key, command) {
|
||||
(Key::Text(t), false) if t == "1" => {
|
||||
if app.screen == Screen::Review {
|
||||
screens::review::leave(app);
|
||||
}
|
||||
app.menu_open = None;
|
||||
app.clips_menu_open = None;
|
||||
app.screen = Screen::History;
|
||||
app.jump(Screen::History);
|
||||
true
|
||||
}
|
||||
(Key::Text(t), false) if t == "2" => {
|
||||
if app.screen == Screen::Review {
|
||||
screens::review::leave(app);
|
||||
}
|
||||
app.menu_open = None;
|
||||
app.clips_menu_open = None;
|
||||
app.screen = Screen::Settings;
|
||||
app.jump(Screen::Settings);
|
||||
true
|
||||
}
|
||||
(Key::Text(t), false) if t == "3" => {
|
||||
if app.screen == Screen::Review {
|
||||
screens::review::leave(app);
|
||||
}
|
||||
app.menu_open = None;
|
||||
app.clips_menu_open = None;
|
||||
app.screen = Screen::Clips;
|
||||
app.jump(Screen::Clips);
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.form.add_open => {
|
||||
@@ -1073,24 +1138,10 @@ pub fn on_key(app: &mut App, event: &KeyEvent, _tx: &mut Tx) -> bool {
|
||||
app.clips_menu_open = None;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.screen == Screen::Clip => {
|
||||
(Key::Escape, _) if !app.behind.is_empty() => {
|
||||
app.menu_open = None;
|
||||
app.screen = Screen::Clips;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.screen == Screen::Clips => {
|
||||
app.menu_open = None;
|
||||
app.screen = Screen::History;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.screen == Screen::Review => {
|
||||
screens::review::leave(app);
|
||||
app.screen = Screen::History;
|
||||
true
|
||||
}
|
||||
(Key::Escape, _) if app.screen == Screen::Settings => {
|
||||
app.menu_open = None;
|
||||
app.screen = Screen::History;
|
||||
app.clips_menu_open = None;
|
||||
app.back();
|
||||
true
|
||||
}
|
||||
(Key::Text(t), true) if t.eq_ignore_ascii_case("r") => {
|
||||
@@ -1162,35 +1213,25 @@ fn statusbar(p: Paint, app: &App) -> El {
|
||||
bar
|
||||
}
|
||||
|
||||
/// What the back arrow says it returns to.
|
||||
fn back_label(screen: Screen) -> &'static str {
|
||||
match screen {
|
||||
Screen::History => "← Match history",
|
||||
Screen::Clips => "← Clips",
|
||||
Screen::Clip => "← Clip",
|
||||
Screen::Review => "← Game",
|
||||
Screen::Settings => "← Settings",
|
||||
}
|
||||
}
|
||||
|
||||
fn titlebar(p: Paint, app: &App) -> El {
|
||||
// Leaving a screen is on the left, where a window's back arrow lives; the app's own
|
||||
// actions stay on the right.
|
||||
let mut leading = row().key("leading").gap(8.0).center_y();
|
||||
if matches!(
|
||||
app.screen,
|
||||
Screen::Settings | Screen::Clips | Screen::Clip | Screen::Review
|
||||
) {
|
||||
let from_clip = app.screen == Screen::Clip;
|
||||
leading = leading.child(ui::button(
|
||||
p,
|
||||
"back",
|
||||
if from_clip {
|
||||
"← Clips"
|
||||
} else {
|
||||
"← Match history"
|
||||
},
|
||||
false,
|
||||
|app: &mut App| {
|
||||
if app.screen == Screen::Review {
|
||||
screens::review::leave(app);
|
||||
}
|
||||
app.screen = if app.screen == Screen::Clip {
|
||||
Screen::Clips
|
||||
} else {
|
||||
Screen::History
|
||||
};
|
||||
},
|
||||
));
|
||||
if let Some(behind) = app.behind.last().copied() {
|
||||
leading = leading.child(ui::button(p, "back", back_label(behind), false, |app| {
|
||||
app.back();
|
||||
}));
|
||||
}
|
||||
let leading = leading.child(
|
||||
text("League Recorder")
|
||||
@@ -1211,8 +1252,7 @@ fn titlebar(p: Paint, app: &App) -> El {
|
||||
|app: &mut App| {
|
||||
app.menu_open = None;
|
||||
app.clips_menu_open = None;
|
||||
screens::review::leave(app);
|
||||
app.screen = Screen::Clips;
|
||||
app.jump(Screen::Clips);
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -1238,8 +1278,7 @@ fn titlebar(p: Paint, app: &App) -> El {
|
||||
false,
|
||||
|app: &mut App| {
|
||||
app.menu_open = None;
|
||||
screens::review::leave(app);
|
||||
app.screen = Screen::Settings;
|
||||
app.jump(Screen::Settings);
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -1362,7 +1401,7 @@ pub fn headless() -> bool {
|
||||
|
||||
/// Put the first sample game on the review screen, for `--scene review`.
|
||||
pub fn demo_review(app: &mut App) {
|
||||
app.screen = Screen::Review;
|
||||
app.go(Screen::Review);
|
||||
if app.games.is_empty() {
|
||||
// Opened before the history finished loading: `poll` opens it once it has.
|
||||
app.pending_review = true;
|
||||
|
||||
+12
-10
@@ -82,17 +82,17 @@ fn main() {
|
||||
rune::App::new(AppSpec {
|
||||
scenes: &[
|
||||
("history", |_app: &mut app::App| {}),
|
||||
("settings", |app| app.screen = app::Screen::Settings),
|
||||
("settings", |app| app.jump(app::Screen::Settings)),
|
||||
("recording", |app| {
|
||||
app.screen = app::Screen::Settings;
|
||||
app.jump(app::Screen::Settings);
|
||||
app.settings_tab = app::SettingsTab::Recording;
|
||||
}),
|
||||
("audio", |app| {
|
||||
app.screen = app::Screen::Settings;
|
||||
app.jump(app::Screen::Settings);
|
||||
app.settings_tab = app::SettingsTab::Audio;
|
||||
}),
|
||||
("add-app", |app| {
|
||||
app.screen = app::Screen::Settings;
|
||||
app.jump(app::Screen::Settings);
|
||||
app.settings_tab = app::SettingsTab::Audio;
|
||||
app.form.open_add();
|
||||
app.form.source_name = rune::TextEdit::new("Discord");
|
||||
@@ -102,7 +102,7 @@ fn main() {
|
||||
app.confirm_delete = app.games.first().map(|game| game.recording_id.clone());
|
||||
}),
|
||||
("daemon", |app| {
|
||||
app.screen = app::Screen::Settings;
|
||||
app.jump(app::Screen::Settings);
|
||||
app.settings_tab = app::SettingsTab::Advanced;
|
||||
}),
|
||||
("review", |app| app::demo_review(app)),
|
||||
@@ -111,12 +111,12 @@ fn main() {
|
||||
app.review.show_details = true;
|
||||
}),
|
||||
("clips-empty", |app| {
|
||||
app.screen = app::Screen::Clips;
|
||||
app.jump(app::Screen::Clips);
|
||||
app.clips.clear();
|
||||
app.clips_loaded = true;
|
||||
}),
|
||||
("clips", |app| {
|
||||
app.screen = app::Screen::Clips;
|
||||
app.jump(app::Screen::Clips);
|
||||
app.clips_menu_open = None;
|
||||
app.spawn_thumbs();
|
||||
}),
|
||||
@@ -125,13 +125,15 @@ fn main() {
|
||||
if app.clips.is_empty() {
|
||||
app.refresh_clips();
|
||||
}
|
||||
// The grid is where a clip is opened from: the back arrow leads to it.
|
||||
app.jump(app::Screen::Clips);
|
||||
app.spawn_thumbs();
|
||||
if let Some(first) = app.clips.first().cloned() {
|
||||
screens::clip::open(app, &first.name);
|
||||
}
|
||||
}),
|
||||
("clips-many", |app| {
|
||||
app.screen = app::Screen::Clips;
|
||||
app.jump(app::Screen::Clips);
|
||||
app.spawn_thumbs();
|
||||
app.clips = (0..12)
|
||||
.flat_map(|page| {
|
||||
@@ -145,12 +147,12 @@ fn main() {
|
||||
app.clips_loaded = true;
|
||||
}),
|
||||
("clips-delete", |app| {
|
||||
app.screen = app::Screen::Clips;
|
||||
app.jump(app::Screen::Clips);
|
||||
app.spawn_thumbs();
|
||||
app.confirm_clip_delete = app.clips.first().map(|clip| clip.name.clone());
|
||||
}),
|
||||
("many", |app| {
|
||||
app.screen = app::Screen::History;
|
||||
app.jump(app::Screen::History);
|
||||
app.games = (0..30)
|
||||
.flat_map(|_| crate::history::sample())
|
||||
.map(|game| game.summary())
|
||||
|
||||
@@ -74,7 +74,7 @@ pub fn open(app: &mut App, name: &str) {
|
||||
at: 0.0,
|
||||
long: 0.0,
|
||||
});
|
||||
app.screen = Screen::Clip;
|
||||
app.go(Screen::Clip);
|
||||
}
|
||||
|
||||
/// The recording a clip was cut from.
|
||||
|
||||
@@ -398,7 +398,7 @@ impl Default for Review {
|
||||
/// [`show`] when it arrives.
|
||||
pub fn open(app: &mut App, recording_id: &str) {
|
||||
leave(app);
|
||||
app.screen = Screen::Review;
|
||||
app.go(Screen::Review);
|
||||
app.review.loading = true;
|
||||
|
||||
let id = recording_id.to_string();
|
||||
@@ -583,8 +583,7 @@ pub fn tick(app: &mut App, tx: &mut Tx) -> bool {
|
||||
.file_stem()
|
||||
.and_then(|stem| stem.to_str())
|
||||
{
|
||||
// The review's soundtrack would keep playing under the clip view.
|
||||
leave(app);
|
||||
// The clip view takes over the sound, and the review waits behind it.
|
||||
app.refresh_clips();
|
||||
crate::screens::clip::open(app, name);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user