-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This involved refactoring the action menu a lot so it's no longer provided by the text window.
- Loading branch information
1 parent
15db89e
commit 145a693
Showing
12 changed files
with
388 additions
and
223 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,76 @@ | ||
use crate::tui::view::{ | ||
common::{list::List, modal::Modal}, | ||
component::Component, | ||
draw::{Draw, Generate}, | ||
event::{Event, EventHandler, UpdateContext}, | ||
state::select::{Fixed, FixedSelect, SelectState}, | ||
}; | ||
use ratatui::{ | ||
layout::{Constraint, Rect}, | ||
text::Span, | ||
widgets::ListState, | ||
Frame, | ||
}; | ||
|
||
/// Modal to list and trigger arbitrary actions. The list of available actions | ||
/// is defined by the generic parameter | ||
#[derive(Debug)] | ||
pub struct ActionsModal<T: FixedSelect> { | ||
actions: Component<SelectState<Fixed, T, ListState>>, | ||
} | ||
|
||
impl<T: FixedSelect> Default for ActionsModal<T> { | ||
fn default() -> Self { | ||
let wrapper = move |context: &mut UpdateContext, action: &mut T| { | ||
// Close the modal *first*, so the parent can handle the callback | ||
// event. Jank but it works | ||
context.queue_event(Event::CloseModal); | ||
context.queue_event(Event::other(*action)); | ||
}; | ||
|
||
Self { | ||
actions: SelectState::fixed().on_submit(wrapper).into(), | ||
} | ||
} | ||
} | ||
|
||
impl<T> Modal for ActionsModal<T> | ||
where | ||
T: FixedSelect, | ||
ActionsModal<T>: Draw, | ||
{ | ||
fn title(&self) -> &str { | ||
"Actions" | ||
} | ||
|
||
fn dimensions(&self) -> (Constraint, Constraint) { | ||
( | ||
Constraint::Length(30), | ||
Constraint::Length(T::iter().count() as u16), | ||
) | ||
} | ||
} | ||
|
||
impl<T: FixedSelect> EventHandler for ActionsModal<T> { | ||
fn children(&mut self) -> Vec<Component<&mut dyn EventHandler>> { | ||
vec![self.actions.as_child()] | ||
} | ||
} | ||
|
||
impl<T> Draw for ActionsModal<T> | ||
where | ||
T: 'static + FixedSelect, | ||
for<'a> &'a T: Generate<Output<'a> = Span<'a>>, | ||
{ | ||
fn draw(&self, frame: &mut Frame, _: (), area: Rect) { | ||
let list = List { | ||
block: None, | ||
list: &self.actions, | ||
}; | ||
frame.render_stateful_widget( | ||
list.generate(), | ||
area, | ||
&mut self.actions.state_mut(), | ||
); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.