Add bell widget
This commit is contained in:
parent
89b4595ed9
commit
e3af509358
3 changed files with 58 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ Procedure when bumping the version number:
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- `Frame::set_bell` to print a bell character when the frame is displayed
|
- `Frame::set_bell` to print a bell character when the frame is displayed
|
||||||
|
- `widgets::bell`
|
||||||
|
|
||||||
## v0.3.3 - 2025-02-28
|
## v0.3.3 - 2025-02-28
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod background;
|
pub mod background;
|
||||||
|
pub mod bell;
|
||||||
pub mod border;
|
pub mod border;
|
||||||
pub mod boxed;
|
pub mod boxed;
|
||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
|
|
@ -16,6 +17,7 @@ pub mod text;
|
||||||
pub mod title;
|
pub mod title;
|
||||||
|
|
||||||
pub use background::*;
|
pub use background::*;
|
||||||
|
pub use bell::*;
|
||||||
pub use border::*;
|
pub use border::*;
|
||||||
pub use boxed::*;
|
pub use boxed::*;
|
||||||
pub use cursor::*;
|
pub use cursor::*;
|
||||||
|
|
|
||||||
55
src/widgets/bell.rs
Normal file
55
src/widgets/bell.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
use crate::{Frame, Size, Widget, WidthDb};
|
||||||
|
|
||||||
|
///////////
|
||||||
|
// State //
|
||||||
|
///////////
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct BellState {
|
||||||
|
// Whether the bell should be rung the next time the widget is displayed.
|
||||||
|
pub ring: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BellState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn widget(&mut self) -> Bell<'_> {
|
||||||
|
Bell { state: self }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// Widget //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Bell<'a> {
|
||||||
|
state: &'a mut BellState,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bell<'_> {
|
||||||
|
pub fn state(&mut self) -> &mut BellState {
|
||||||
|
self.state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<E> Widget<E> for Bell<'_> {
|
||||||
|
fn size(
|
||||||
|
&self,
|
||||||
|
_widthdb: &mut WidthDb,
|
||||||
|
_max_width: Option<u16>,
|
||||||
|
_max_height: Option<u16>,
|
||||||
|
) -> Result<Size, E> {
|
||||||
|
Ok(Size::ZERO)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(self, frame: &mut Frame) -> Result<(), E> {
|
||||||
|
if self.state.ring {
|
||||||
|
frame.set_bell(true);
|
||||||
|
self.state.ring = false
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue