renderer: Mark latched buttons differently than locked
There are some hacks here in the form of an extra field "appears_locked_from", which can be used to hint that the user should see the button as locked. Without it, there's some confusion on user side regarding buttons that change states unprompted.
This commit is contained in:
@ -32,6 +32,8 @@ pub enum Action {
|
||||
/// Whether key has a latched state
|
||||
/// that pops when another key is pressed.
|
||||
latches: bool,
|
||||
/// Should take on *locked* appearance whenever latch comes back to those views.
|
||||
looks_locked_from: Vec<View>,
|
||||
},
|
||||
/// Hold this modifier for as long as the button is pressed
|
||||
ApplyModifier(Modifier),
|
||||
@ -51,14 +53,24 @@ pub enum Action {
|
||||
impl Action {
|
||||
pub fn is_locked(&self, view_name: &str) -> bool {
|
||||
match self {
|
||||
Action::LockView { lock, unlock: _, latches: _ } => lock == view_name,
|
||||
Action::LockView { lock, unlock: _, latches: _, looks_locked_from: _ } => lock == view_name,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
pub fn has_locked_appearance_from(&self, locked_view_name: &str) -> bool {
|
||||
match self {
|
||||
Action::LockView { lock: _, unlock: _, latches: _, looks_locked_from } => {
|
||||
looks_locked_from.iter()
|
||||
.find(|view| locked_view_name == view.as_str())
|
||||
.is_some()
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
pub fn is_active(&self, view_name: &str) -> bool {
|
||||
match self {
|
||||
Action::SetView(view) => view == view_name,
|
||||
Action::LockView { lock, unlock: _, latches: _ } => lock == view_name,
|
||||
Action::LockView { lock, unlock: _, latches: _, looks_locked_from: _ } => lock == view_name,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user