fp_tui/
widget.rs

1use std::rc::Rc;
2use std::cell::RefCell;
3
4use super::{PositioningAlgorithm, DisplayBuffer};
5use crate::common::BoundingBox;
6
7/// #### Description
8/// Base interface for every element in the tui
9/// 
10/// Note that most concrete widgets are stored as [Rc]<[RefCell]<dyn [Widget]> 
11/// so it can be helpful to have their constructors return such a value
12/// 
13pub trait Widget {
14    /// #### Description
15    /// Draws the widget to the display buffer
16    /// 
17    /// #### Arguments
18    /// * `positioning_algorithm`: &[Box]<dyn [PositioningAlgorithm]> - The 
19    /// positioning algorithm for the widget
20    /// * `display_buffer`: &mut [DisplayBuffer] - The display buffer
21    /// 
22    fn draw(
23        &mut self,
24        positioning_algorithm: &Box<dyn PositioningAlgorithm>,
25        display_buffer: &mut DisplayBuffer
26    );
27
28    /// #### Description
29    /// Retrieves the bounding box of the widget
30    /// 
31    /// #### Returns
32    /// [BoundingBox] - The bounding box of the widget
33    /// 
34    fn get_bounding_box(&self) -> BoundingBox;
35}
36
37/// #### Description
38/// An interface for widgets that contain other widgets
39/// 
40pub trait ContainerWidget: Widget {
41    /// #### Description
42    /// Add a widget to the container
43    ///
44    /// #### Arguments
45    /// * `positioning_algorithm`: &[Box]<dyn [PositioningAlgorithm]> - The 
46    /// positioning algorithm for the widget
47    /// * `widget`: [Rc]<[RefCell]<dyn [Widget]>> - The widget to add
48    /// 
49    fn add_child(
50        &mut self,
51        positioning_algorithm: Box<dyn PositioningAlgorithm>,
52        widget: Rc<RefCell<dyn Widget>>
53    );
54}