mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-16 08:20:39 +08:00
lib/im: Allow action alignment in shortcut widget
This commit is contained in:
@@ -317,7 +317,7 @@ impl Show<Message> for App {
|
||||
self.show_help_text(frame, ui);
|
||||
self.show_help_context(frame, ui);
|
||||
|
||||
ui.shortcuts(frame, &[("?", "close")], '∙');
|
||||
ui.shortcuts(frame, &[("?", "close")], '∙', Alignment::Left);
|
||||
});
|
||||
|
||||
if ui.has_input(|key| key == Key::Char('?')) {
|
||||
@@ -564,6 +564,7 @@ impl App {
|
||||
("?", "help"),
|
||||
],
|
||||
'∙',
|
||||
Alignment::Left,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use radicle::patch::PatchId;
|
||||
use radicle::storage::git::Repository;
|
||||
use radicle::Profile;
|
||||
|
||||
use ratatui::layout::{Constraint, Layout, Position};
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Position};
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Span;
|
||||
use ratatui::{Frame, Viewport};
|
||||
@@ -289,7 +289,7 @@ impl Show<Message> for App {
|
||||
self.show_help_text(frame, ui);
|
||||
self.show_help_context(frame, ui);
|
||||
|
||||
ui.shortcuts(frame, &[("?", "close")], '∙');
|
||||
ui.shortcuts(frame, &[("?", "close")], '∙', Alignment::Left);
|
||||
});
|
||||
|
||||
if ui.has_input(|key| key == Key::Char('?')) {
|
||||
@@ -570,6 +570,7 @@ impl App {
|
||||
("?", "help"),
|
||||
],
|
||||
'∙',
|
||||
Alignment::Left,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use anyhow::Result;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use ratatui::layout::{Constraint, Layout, Position};
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Position};
|
||||
use ratatui::style::{Style, Stylize};
|
||||
use ratatui::text::Text;
|
||||
use ratatui::{Frame, Viewport};
|
||||
@@ -486,6 +486,7 @@ impl App<'_> {
|
||||
("q", "quit"),
|
||||
],
|
||||
'∙',
|
||||
Alignment::Left,
|
||||
);
|
||||
|
||||
if ui.has_input(|key| key == Key::Char('?')) {
|
||||
@@ -502,7 +503,7 @@ impl App<'_> {
|
||||
}
|
||||
}
|
||||
ReviewMode::Show => {
|
||||
ui.shortcuts(frame, &[("?", "help"), ("q", "quit")], '∙');
|
||||
ui.shortcuts(frame, &[("?", "help"), ("q", "quit")], '∙', Alignment::Left);
|
||||
|
||||
if ui.has_input(|key| key == Key::Char('?')) {
|
||||
ui.send_message(Message::ShowHelp);
|
||||
@@ -567,7 +568,12 @@ impl Show<Message> for App<'_> {
|
||||
|
||||
self.show_context_bar(ui, frame);
|
||||
|
||||
ui.shortcuts(frame, &[("?", "close"), ("q", "quit")], '∙');
|
||||
ui.shortcuts(
|
||||
frame,
|
||||
&[("?", "close"), ("q", "quit")],
|
||||
'∙',
|
||||
Alignment::Left,
|
||||
);
|
||||
});
|
||||
|
||||
if ui.has_input(|key| key == Key::Char('?')) {
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use ratatui::layout::{Constraint, Layout};
|
||||
use ratatui::layout::{Alignment, Constraint, Layout};
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Span;
|
||||
use ratatui::widgets::Cell;
|
||||
@@ -117,7 +117,7 @@ impl Show<Message> for App {
|
||||
})
|
||||
}
|
||||
|
||||
ui.shortcuts(frame, &[("q", "quit")], '|');
|
||||
ui.shortcuts(frame, &[("q", "quit")], '|', Alignment::Left);
|
||||
|
||||
if ui.has_input(|key| key == Key::Enter) {
|
||||
ui.send_message(Message::Return);
|
||||
|
||||
+3
-2
@@ -12,7 +12,7 @@ use ratatui::text::{Span, Text};
|
||||
use tokio::sync::broadcast;
|
||||
use tokio::sync::mpsc::UnboundedReceiver;
|
||||
|
||||
use ratatui::layout::{Constraint, Flex, Position, Rect};
|
||||
use ratatui::layout::{Alignment, Constraint, Flex, Position, Rect};
|
||||
use ratatui::{Frame, Viewport};
|
||||
|
||||
use crate::event::{Event, Key};
|
||||
@@ -571,8 +571,9 @@ where
|
||||
frame: &mut Frame,
|
||||
shortcuts: &[(&str, &str)],
|
||||
divider: char,
|
||||
alignment: Alignment,
|
||||
) -> Response {
|
||||
widget::Shortcuts::new(shortcuts, divider).ui(self, frame)
|
||||
widget::Shortcuts::new(shortcuts, divider, alignment).ui(self, frame)
|
||||
}
|
||||
|
||||
pub fn column_bar(
|
||||
|
||||
+22
-2
@@ -2,7 +2,7 @@ use std::cmp;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use ratatui::layout::{Direction, Layout, Position, Rect};
|
||||
use ratatui::layout::{Alignment, Direction, Layout, Position, Rect};
|
||||
use ratatui::style::{Style, Stylize};
|
||||
use ratatui::text::{Line, Span, Text};
|
||||
use ratatui::widgets::{Block, BorderType, Row, Scrollbar, ScrollbarState};
|
||||
@@ -1043,16 +1043,18 @@ impl Widget for TextEdit<'_> {
|
||||
pub struct Shortcuts {
|
||||
pub shortcuts: Vec<(String, String)>,
|
||||
pub divider: char,
|
||||
pub alignment: Alignment,
|
||||
}
|
||||
|
||||
impl Shortcuts {
|
||||
pub fn new(shortcuts: &[(&str, &str)], divider: char) -> Self {
|
||||
pub fn new(shortcuts: &[(&str, &str)], divider: char, alignment: Alignment) -> Self {
|
||||
Self {
|
||||
shortcuts: shortcuts
|
||||
.iter()
|
||||
.map(|(s, a)| (s.to_string(), a.to_string()))
|
||||
.collect(),
|
||||
divider,
|
||||
alignment,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1095,6 +1097,24 @@ impl Widget for Shortcuts {
|
||||
.iter()
|
||||
.map(|(width, _)| Constraint::Length(*width as u16))
|
||||
.collect();
|
||||
|
||||
let (row, widths) = match self.alignment {
|
||||
Alignment::Left => ([row.as_slice(), &[Text::from("")]].concat(), widths),
|
||||
Alignment::Center => (
|
||||
[&[Text::from("")], row.as_slice(), &[Text::from("")]].concat(),
|
||||
[
|
||||
&[Constraint::Fill(1)],
|
||||
widths.as_slice(),
|
||||
&[Constraint::Fill(1)],
|
||||
]
|
||||
.concat(),
|
||||
),
|
||||
Alignment::Right => (
|
||||
[&[Text::from("")], row.as_slice()].concat(),
|
||||
[&[Constraint::Fill(1)], widths.as_slice()].concat(),
|
||||
),
|
||||
};
|
||||
|
||||
let table = Table::new([Row::new(row)], widths).column_spacing(0);
|
||||
|
||||
frame.render_widget(table, area);
|
||||
|
||||
Reference in New Issue
Block a user