#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Focus {
FactsPane,
WorldPane,
QueryPrompt,
RightPane,
#[allow(dead_code)]
ConfirmationOverlay,
}
impl Focus {
pub(crate) fn next(self) -> Focus {
match self {
Focus::FactsPane => Focus::WorldPane,
Focus::WorldPane => Focus::QueryPrompt,
Focus::QueryPrompt => Focus::RightPane,
Focus::RightPane => Focus::FactsPane,
Focus::ConfirmationOverlay => Focus::ConfirmationOverlay,
}
}
pub(crate) fn prev(self) -> Focus {
match self {
Focus::FactsPane => Focus::RightPane,
Focus::WorldPane => Focus::FactsPane,
Focus::QueryPrompt => Focus::WorldPane,
Focus::RightPane => Focus::QueryPrompt,
Focus::ConfirmationOverlay => Focus::ConfirmationOverlay,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum RightPane {
Chat,
Research,
Map,
Ledger,
}
impl RightPane {
pub(crate) fn next(self) -> RightPane {
match self {
RightPane::Chat => RightPane::Research,
RightPane::Research => RightPane::Map,
RightPane::Map => RightPane::Ledger,
RightPane::Ledger => RightPane::Chat,
}
}
pub(crate) fn title(self) -> &'static str {
match self {
RightPane::Chat => "Chat",
RightPane::Research => "Research",
RightPane::Map => "Map",
RightPane::Ledger => "Ledger",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tab_cycles_four_primaries_and_returns() {
let mut f = Focus::FactsPane;
f = f.next();
assert_eq!(f, Focus::WorldPane);
f = f.next();
assert_eq!(f, Focus::QueryPrompt);
f = f.next();
assert_eq!(f, Focus::RightPane);
f = f.next();
assert_eq!(f, Focus::FactsPane); }
#[test]
fn shift_tab_is_the_inverse() {
for f in [Focus::FactsPane, Focus::WorldPane, Focus::QueryPrompt, Focus::RightPane] {
assert_eq!(f.next().prev(), f);
assert_eq!(f.prev().next(), f);
}
}
#[test]
fn overlay_is_sticky() {
assert_eq!(Focus::ConfirmationOverlay.next(), Focus::ConfirmationOverlay);
assert_eq!(Focus::ConfirmationOverlay.prev(), Focus::ConfirmationOverlay);
}
#[test]
fn right_pane_cycles() {
let mut r = RightPane::Chat;
r = r.next();
assert_eq!(r, RightPane::Research);
r = r.next();
assert_eq!(r, RightPane::Map);
r = r.next();
assert_eq!(r, RightPane::Ledger);
r = r.next();
assert_eq!(r, RightPane::Chat);
}
}