-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
557fb0c
commit 9b88aa5
Showing
3 changed files
with
66 additions
and
19 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
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,59 @@ | ||
use ratatui::{ | ||
buffer::Buffer, | ||
layout::{Alignment, Rect}, | ||
style::{Color, Modifier, Stylize}, | ||
text::Line, | ||
widgets::{Block, BorderType, Padding, Paragraph, Widget, WidgetRef}, | ||
}; | ||
|
||
use crate::{color::ColorTheme, ui::common::calc_centered_dialog_rect, widget::Dialog}; | ||
|
||
#[derive(Debug, Default)] | ||
struct LoadingDialogColor { | ||
bg: Color, | ||
block: Color, | ||
text: Color, | ||
} | ||
|
||
impl LoadingDialogColor { | ||
fn new(theme: &ColorTheme) -> Self { | ||
LoadingDialogColor { | ||
bg: theme.bg, | ||
block: theme.fg, | ||
text: theme.fg, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
pub struct LoadingDialog { | ||
color: LoadingDialogColor, | ||
} | ||
|
||
impl LoadingDialog { | ||
pub fn theme(mut self, theme: &ColorTheme) -> Self { | ||
self.color = LoadingDialogColor::new(theme); | ||
self | ||
} | ||
} | ||
|
||
impl Widget for LoadingDialog { | ||
fn render(self, area: Rect, buf: &mut Buffer) { | ||
let area = calc_centered_dialog_rect(area, 30, 5); | ||
|
||
let text = Line::from(Self::MSG.fg(self.color.text).add_modifier(Modifier::BOLD)); | ||
let paragraph = Paragraph::new(text).alignment(Alignment::Center).block( | ||
Block::bordered() | ||
.border_type(BorderType::Rounded) | ||
.padding(Padding::vertical(1)) | ||
.fg(self.color.block), | ||
); | ||
|
||
let dialog = Dialog::new(Box::new(paragraph), self.color.bg); | ||
dialog.render_ref(area, buf); | ||
} | ||
} | ||
|
||
impl LoadingDialog { | ||
const MSG: &'static str = "Loading..."; | ||
} |