-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create components for easier UI creation
- Loading branch information
1 parent
9140798
commit 6ab6e12
Showing
17 changed files
with
360 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
"cmdline", | ||
"commandline", | ||
"concat", | ||
"coord", | ||
"crossterm", | ||
"curr", | ||
"cvar", | ||
|
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
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
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,51 @@ | ||
use crate::app::layout_manager::{BottomWidget, BottomWidgetType}; | ||
|
||
use super::{HandleClick, HandleKeyInputs, HandleScroll}; | ||
|
||
#[derive(Default, Debug)] | ||
pub struct Coordinate { | ||
pub x: u16, | ||
pub y: u16, | ||
} | ||
|
||
#[derive(Default, Debug)] | ||
pub struct WidgetCorners { | ||
pub top_left_corner: Coordinate, | ||
pub bottom_right_corner: Coordinate, | ||
} | ||
|
||
pub trait BaseWidget: HandleClick + HandleScroll + HandleKeyInputs { | ||
/// Get the widget bounds - returns the top left corner (TLC) and the bottom | ||
/// right corner (BRC). | ||
fn get_widget_bounds(&self) -> Option<WidgetCorners>; | ||
|
||
/// Get if a border is being drawn around this widget. | ||
fn is_drawing_borders(&self) -> bool { | ||
self.is_drawing_horizontal_borders() && self.is_drawing_vertical_borders() | ||
} | ||
|
||
/// Get if horizontal borders are being drawn around this widget. | ||
fn is_drawing_horizontal_borders(&self) -> bool; | ||
|
||
/// Get if vertical borders are being drawn around this widget. | ||
fn is_drawing_vertical_borders(&self) -> bool; | ||
|
||
/// Obtain the widget ID. | ||
fn get_widget_id(&self) -> u64 { | ||
self.get_bottom_widget_details().widget_id | ||
} | ||
|
||
/// Obtain the widget type. | ||
fn get_widget_type(&self) -> &BottomWidgetType { | ||
&self.get_bottom_widget_details().widget_type | ||
} | ||
|
||
/// Obtain the widget layout details. | ||
fn get_bottom_widget_details(&self) -> &BottomWidget; | ||
} | ||
|
||
pub trait BaseTableWidget: BaseWidget { | ||
fn get_table_gap(&self) -> u16; | ||
} | ||
|
||
pub trait BaseGraphWidget: BaseWidget {} |
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,9 @@ | ||
use tui::{backend::Backend, layout::Rect, Frame}; | ||
|
||
use crate::app::App; | ||
|
||
pub trait Drawable { | ||
fn draw<B: Backend>( | ||
&mut self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, is_force_redraw: bool, | ||
); | ||
} |
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,25 @@ | ||
use crossterm::event::KeyEvent; | ||
|
||
use super::Coordinate; | ||
|
||
pub trait HandleKeyInputs { | ||
/// How to handle a key input | ||
fn on_char(&mut self, key_input: KeyEvent); | ||
} | ||
|
||
pub trait HandleScroll { | ||
fn on_scroll_up(&mut self); | ||
|
||
fn on_scroll_down(&mut self); | ||
} | ||
|
||
pub enum MouseButton { | ||
Left, | ||
Middle, | ||
Right, | ||
} | ||
|
||
pub trait HandleClick { | ||
/// How to handle a click. | ||
fn on_click(&mut self, button: MouseButton, click_coord: Coordinate); | ||
} |
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,7 @@ | ||
pub mod base_widget; | ||
pub mod drawable; | ||
pub mod events; | ||
|
||
pub use base_widget::*; | ||
pub use drawable::*; | ||
pub use events::*; |
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,5 @@ | ||
pub mod base_traits; | ||
pub mod scrollable_table; | ||
|
||
pub use base_traits::*; | ||
pub use scrollable_table::*; |
Oops, something went wrong.