mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-27 07:34:27 +02:00
Start layout tree work
This commit is contained in:
parent
bf81a389b8
commit
65a1ee5202
@ -6,7 +6,7 @@ pub use widget::*;
|
||||
|
||||
use tui::{layout::Rect, Frame};
|
||||
|
||||
use super::{Bounds, Context, Event, LayoutNode, Size, Status};
|
||||
use super::{Bounds, DrawContext, Event, LayoutNode, Size, Status};
|
||||
|
||||
/// A component displays information and can be interacted with.
|
||||
#[allow(unused_variables)]
|
||||
@ -15,7 +15,7 @@ where
|
||||
Backend: tui::backend::Backend,
|
||||
{
|
||||
/// Draws the component.
|
||||
fn draw(&mut self, area: Rect, context: &Context, frame: &mut Frame<'_, Backend>);
|
||||
fn draw(&mut self, area: Rect, context: &DrawContext, frame: &mut Frame<'_, Backend>);
|
||||
|
||||
/// How a component should react to an [`Event`].
|
||||
///
|
||||
@ -27,7 +27,7 @@ where
|
||||
/// How a component should size itself and its children, given some [`Bounds`].
|
||||
///
|
||||
/// Defaults to returning a [`Size`] that fills up the bounds given.
|
||||
fn layout(&self, bounds: Bounds) -> Size {
|
||||
fn layout(&self, bounds: Bounds, node: &mut LayoutNode) -> Size {
|
||||
Size {
|
||||
width: bounds.max_width,
|
||||
height: bounds.max_height,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use tui::{backend::Backend, layout::Rect, Frame};
|
||||
|
||||
use crate::tuice::{Component, Context, Event, Status};
|
||||
use crate::tuice::{Component, DrawContext, Event, Status};
|
||||
|
||||
pub struct Block {}
|
||||
|
||||
@ -8,7 +8,7 @@ impl<Message, B> Component<Message, B> for Block
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
fn draw(&mut self, _area: Rect, _context: &Context, _frame: &mut Frame<'_, B>) {
|
||||
fn draw(&mut self, _area: Rect, _context: &DrawContext, _frame: &mut Frame<'_, B>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use tui::{backend::Backend, layout::Rect, Frame};
|
||||
|
||||
use crate::tuice::{Component, Context, Event, Status};
|
||||
use crate::tuice::{Component, DrawContext, Event, Status};
|
||||
|
||||
pub struct Carousel {}
|
||||
|
||||
@ -8,7 +8,7 @@ impl<Message, B> Component<Message, B> for Carousel
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
fn draw(&mut self, _area: Rect, _context: &Context, _frame: &mut Frame<'_, B>) {
|
||||
fn draw(&mut self, _area: Rect, _context: &DrawContext, _frame: &mut Frame<'_, B>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use tui::{backend::Backend, layout::Rect, Frame};
|
||||
|
||||
use crate::tuice::{Component, Context, Event, Status};
|
||||
use crate::tuice::{Component, DrawContext, Event, Status};
|
||||
|
||||
pub struct Column {}
|
||||
|
||||
@ -8,7 +8,7 @@ impl<Message, B> Component<Message, B> for Column
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
fn draw(&mut self, _area: Rect, _context: &Context, _frame: &mut Frame<'_, B>) {
|
||||
fn draw(&mut self, _area: Rect, _context: &DrawContext, _frame: &mut Frame<'_, B>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use tui::{backend::Backend, layout::Rect, Frame};
|
||||
|
||||
use crate::tuice::{Bounds, Component, Context, Event, LayoutNode, Length, Size, Status};
|
||||
use crate::tuice::{Bounds, Component, DrawContext, Event, Length, Size, Status, LayoutNode};
|
||||
|
||||
pub struct Container<'a, Message, B>
|
||||
where
|
||||
@ -28,7 +28,7 @@ impl<'a, Message, B> Component<Message, B> for Container<'a, Message, B>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
fn draw(&mut self, area: Rect, _context: &Context, _frame: &mut Frame<'_, B>) {
|
||||
fn draw(&mut self, area: Rect, _context: &DrawContext, _frame: &mut Frame<'_, B>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ where
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn layout(&self, bounds: Bounds) -> Size {
|
||||
fn layout(&self, bounds: Bounds, node: &mut LayoutNode) -> Size {
|
||||
let width = match self.width {
|
||||
Length::Flex => {
|
||||
todo!()
|
||||
|
@ -1,6 +1,6 @@
|
||||
use tui::{backend::Backend, layout::Rect, Frame};
|
||||
|
||||
use crate::tuice::{Bounds, Component, Context, Event, Size, Status};
|
||||
use crate::tuice::{Bounds, Component, DrawContext, Event, Size, Status};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Row<'a, Message, B>
|
||||
@ -29,7 +29,7 @@ impl<'a, Message, B> Component<Message, B> for Row<'a, Message, B>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
fn draw(&mut self, area: Rect, context: &Context, frame: &mut Frame<'_, B>) {
|
||||
fn draw(&mut self, area: Rect, context: &DrawContext, frame: &mut Frame<'_, B>) {
|
||||
self.children.iter_mut().for_each(|child| {
|
||||
// TODO: This is just temp! We need layout!
|
||||
child.draw(area, context, frame);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use tui::{backend::Backend, layout::Rect, Frame};
|
||||
|
||||
use crate::tuice::{Component, Context, Event, Status};
|
||||
use crate::tuice::{Component, DrawContext, Event, Status};
|
||||
|
||||
/// A [`Component`] to handle keyboard shortcuts and assign actions to them.
|
||||
///
|
||||
@ -11,7 +11,7 @@ impl<Message, B> Component<Message, B> for Shortcut
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
fn draw(&mut self, _area: Rect, _context: &Context, _frame: &mut Frame<'_, B>) {
|
||||
fn draw(&mut self, _area: Rect, _context: &DrawContext, _frame: &mut Frame<'_, B>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use crate::{
|
||||
constants::TABLE_GAP_HEIGHT_LIMIT,
|
||||
tuice::{Component, Context, Event, Status},
|
||||
tuice::{Component, DrawContext, Event, Status},
|
||||
};
|
||||
|
||||
pub use self::table_column::{TextColumn, TextColumnConstraint};
|
||||
@ -179,7 +179,7 @@ impl<'a, Message, B> Component<Message, B> for TextTable<'a, Message>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
fn draw(&mut self, area: Rect, context: &Context, frame: &mut Frame<'_, B>) {
|
||||
fn draw(&mut self, area: Rect, context: &DrawContext, frame: &mut Frame<'_, B>) {
|
||||
self.table_gap = if !self.show_gap
|
||||
|| (self.rows.len() + 2 > area.height.into() && area.height < TABLE_GAP_HEIGHT_LIMIT)
|
||||
{
|
||||
|
@ -1,6 +0,0 @@
|
||||
use crate::app::layout_manager::LayoutNode;
|
||||
|
||||
/// Internal management for drawing and the like.
|
||||
pub struct Context {
|
||||
layout_root: LayoutNode,
|
||||
}
|
1
src/tuice/draw_context.rs
Normal file
1
src/tuice/draw_context.rs
Normal file
@ -0,0 +1 @@
|
||||
pub struct DrawContext {}
|
22
src/tuice/layout/build_layout.rs
Normal file
22
src/tuice/layout/build_layout.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use tui::layout::Rect;
|
||||
|
||||
use crate::tuice::{Bounds, Component, LayoutNode};
|
||||
|
||||
pub fn build_layout_tree<Message, Backend>(
|
||||
area: Rect, root: &Box<dyn Component<Message, Backend>>,
|
||||
) -> LayoutNode
|
||||
where
|
||||
Backend: tui::backend::Backend,
|
||||
{
|
||||
let mut root_layout_node = LayoutNode::from_area(area);
|
||||
let bounds = Bounds {
|
||||
min_width: 0,
|
||||
min_height: 0,
|
||||
max_width: area.width,
|
||||
max_height: area.height,
|
||||
};
|
||||
|
||||
root.layout(bounds, &mut root_layout_node);
|
||||
|
||||
root_layout_node
|
||||
}
|
@ -1,12 +1,16 @@
|
||||
use tui::layout::Rect;
|
||||
|
||||
/// A node for the layout tree.
|
||||
pub enum LayoutNode {
|
||||
Leaf {
|
||||
area: Rect,
|
||||
},
|
||||
Branch {
|
||||
area: Rect,
|
||||
children: Vec<LayoutNode>,
|
||||
},
|
||||
#[derive(Default)]
|
||||
pub struct LayoutNode {
|
||||
pub area: Rect,
|
||||
pub children: Vec<LayoutNode>,
|
||||
}
|
||||
|
||||
impl LayoutNode {
|
||||
pub fn from_area(area: Rect) -> Self {
|
||||
Self {
|
||||
area,
|
||||
children: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,5 @@ pub use size::Size;
|
||||
pub mod layout_node;
|
||||
pub use layout_node::LayoutNode;
|
||||
|
||||
pub fn build_layout() -> LayoutNode {
|
||||
todo!()
|
||||
}
|
||||
pub mod build_layout;
|
||||
pub use build_layout::build_layout_tree;
|
||||
|
@ -15,5 +15,5 @@ pub use runtime::RuntimeEvent;
|
||||
pub mod layout;
|
||||
pub use layout::*;
|
||||
|
||||
pub mod context;
|
||||
pub use context::*;
|
||||
pub mod draw_context;
|
||||
pub use draw_context::*;
|
||||
|
Loading…
x
Reference in New Issue
Block a user