mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-21 10:30:48 +08:00
inbox: Add shortcut widget
This commit is contained in:
@@ -2,11 +2,11 @@ use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use termion::event::Key;
|
||||
|
||||
use ratatui::backend::Backend;
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::{backend::Backend, layout::Rect};
|
||||
|
||||
use radicle_tui as tui;
|
||||
use tui::flux::ui::{Render, Widget};
|
||||
use tui::flux::ui::widget::{Render, Shortcut, ShortcutWidget, ShortcutWidgetProps, Widget};
|
||||
|
||||
use crate::tui_inbox::select::flux::{Action, InboxState};
|
||||
|
||||
@@ -27,6 +27,8 @@ pub struct ListPage {
|
||||
pub action_tx: UnboundedSender<Action>,
|
||||
// Mapped Props from State
|
||||
props: Props,
|
||||
/// Shortcut widget
|
||||
shortcuts: ShortcutWidget<Action>,
|
||||
}
|
||||
|
||||
impl Widget<InboxState, Action> for ListPage {
|
||||
@@ -34,9 +36,10 @@ impl Widget<InboxState, Action> for ListPage {
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
ListPage {
|
||||
Self {
|
||||
action_tx: action_tx.clone(),
|
||||
props: Props::from(state),
|
||||
shortcuts: ShortcutWidget::new(state, action_tx.clone()),
|
||||
}
|
||||
.move_with_state(state)
|
||||
}
|
||||
@@ -66,12 +69,20 @@ impl Widget<InboxState, Action> for ListPage {
|
||||
}
|
||||
|
||||
impl Render<()> for ListPage {
|
||||
fn render<B: Backend>(&self, frame: &mut ratatui::Frame, _props: ()) {
|
||||
fn render<B: Backend>(&self, frame: &mut ratatui::Frame, _area: Rect, _props: ()) {
|
||||
let area = frame.size();
|
||||
let layout = tui::flux::ui::layout::default_page(area, 1u16, 1u16);
|
||||
|
||||
let shortcuts = Paragraph::new(String::from("q quit"));
|
||||
self.shortcuts.render::<B>(
|
||||
frame,
|
||||
layout.shortcuts,
|
||||
ShortcutWidgetProps {
|
||||
shortcuts: vec![Shortcut::new("q", "quit"), Shortcut::new("s", "show"), Shortcut::new("?", "help")],
|
||||
divider: '∙',
|
||||
},
|
||||
);
|
||||
|
||||
frame.render_widget(shortcuts, layout.shortcuts);
|
||||
// let shortcuts = Paragraph::new(String::from("q quit"));
|
||||
// frame.render_widget(self.shortcuts, layout.shortcuts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user