mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-27 07:34:27 +02:00
temp
This commit is contained in:
parent
c094efa74c
commit
c002a3fa3a
@ -4,6 +4,9 @@ pub use base::*;
|
|||||||
pub mod widget;
|
pub mod widget;
|
||||||
pub use widget::*;
|
pub use widget::*;
|
||||||
|
|
||||||
|
pub mod properties;
|
||||||
|
pub use properties::*;
|
||||||
|
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use tui::{layout::Rect, Frame};
|
use tui::{layout::Rect, Frame};
|
||||||
|
|
||||||
|
@ -92,7 +92,9 @@ impl<'a, Message> TmpComponent<Message> for Flex<'a, Message> {
|
|||||||
.iter_mut()
|
.iter_mut()
|
||||||
.zip(context.children())
|
.zip(context.children())
|
||||||
.for_each(|(child, child_node)| {
|
.for_each(|(child, child_node)| {
|
||||||
child.draw(child_node, frame);
|
if child_node.should_draw() {
|
||||||
|
child.draw(child_node, frame);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,10 +125,16 @@ impl<'a, Message> TmpComponent<Message> for Flex<'a, Message> {
|
|||||||
.zip(children.iter_mut())
|
.zip(children.iter_mut())
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.for_each(|(index, (child, child_node))| {
|
.for_each(|(index, (child, child_node))| {
|
||||||
if child.flex == 0 && remaining_bounds.has_space() {
|
if child.flex == 0 {
|
||||||
let size = child.child_layout(remaining_bounds, child_node);
|
let size = if remaining_bounds.has_space() {
|
||||||
current_size += size;
|
let size = child.child_layout(remaining_bounds, child_node);
|
||||||
remaining_bounds.shrink_size(size);
|
current_size += size;
|
||||||
|
remaining_bounds.shrink_size(size);
|
||||||
|
|
||||||
|
size
|
||||||
|
} else {
|
||||||
|
Size::default()
|
||||||
|
};
|
||||||
|
|
||||||
sizes.push(size);
|
sizes.push(size);
|
||||||
} else {
|
} else {
|
||||||
|
3
src/tuice/component/properties.rs
Normal file
3
src/tuice/component/properties.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/// A trait that the properties of a [`Component`](super::Component)
|
||||||
|
/// should implement.
|
||||||
|
pub trait Properties: PartialEq {}
|
@ -24,6 +24,10 @@ impl<'a> DrawContext<'_> {
|
|||||||
rect
|
rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn should_draw(&self) -> bool {
|
||||||
|
self.current_node.rect.area() != 0
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn children(&self) -> impl Iterator<Item = DrawContext<'_>> {
|
pub(crate) fn children(&self) -> impl Iterator<Item = DrawContext<'_>> {
|
||||||
let new_offset = (
|
let new_offset = (
|
||||||
self.current_offset.0 + self.current_node.rect.x,
|
self.current_offset.0 + self.current_node.rect.x,
|
||||||
|
26
src/tuice/key.rs
Normal file
26
src/tuice/key.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//! Code here is based on crochet's implementation - see
|
||||||
|
//! [here](https://github.com/raphlinus/crochet/blob/master/src/key.rs) for more details!
|
||||||
|
|
||||||
|
use std::hash::Hash;
|
||||||
|
use std::panic::Location;
|
||||||
|
|
||||||
|
/// A newtype around [`Location`].
|
||||||
|
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct Caller(&'static Location<'static>);
|
||||||
|
|
||||||
|
/// A unique key built around using the [`Location`] given by
|
||||||
|
/// `#[track_caller]` and a sequence index.
|
||||||
|
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct Key {
|
||||||
|
pub(crate) caller: Caller,
|
||||||
|
pub(crate) index: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Key {
|
||||||
|
pub fn new(caller: impl Into<Caller>, index: usize) -> Self {
|
||||||
|
Self {
|
||||||
|
caller: caller.into(),
|
||||||
|
index,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,13 @@
|
|||||||
|
//! tuice is a wrapper around tui-rs that expands upon state management and
|
||||||
|
//! event handling.
|
||||||
|
//!
|
||||||
|
//! tuice is inspired by a **ton** of other libraries and frameworks, like:
|
||||||
|
//! - Iced
|
||||||
|
//! - [crochet](https://github.com/raphlinus/crochet)
|
||||||
|
//! - Flutter
|
||||||
|
//! - React
|
||||||
|
//! - Yew
|
||||||
|
|
||||||
mod tui_rs;
|
mod tui_rs;
|
||||||
|
|
||||||
pub mod component;
|
pub mod component;
|
||||||
@ -20,3 +30,12 @@ pub use element::*;
|
|||||||
|
|
||||||
pub mod context;
|
pub mod context;
|
||||||
pub use context::*;
|
pub use context::*;
|
||||||
|
|
||||||
|
pub mod screen;
|
||||||
|
pub use screen::*;
|
||||||
|
|
||||||
|
pub mod key;
|
||||||
|
pub use key::*;
|
||||||
|
|
||||||
|
pub mod state;
|
||||||
|
pub use state::*;
|
||||||
|
1
src/tuice/screen.rs
Normal file
1
src/tuice/screen.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
//! Screens are a system to preserve states while moving between two "screens".
|
25
src/tuice/state.rs
Normal file
25
src/tuice/state.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
//! State code is heavily inspired by crochet's work - see
|
||||||
|
//! [here](https://github.com/raphlinus/crochet/blob/master/src/state.rs) for the original.
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
|
/// A trait that any sort of [`Component`](crate::tuice::Component) state should implement.
|
||||||
|
pub trait State {
|
||||||
|
fn as_any(&self) -> &dyn Any;
|
||||||
|
|
||||||
|
fn are_equal(&self, other: &dyn State) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: PartialEq + 'static> State for S {
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn are_equal(&self, other: &dyn State) -> bool {
|
||||||
|
other
|
||||||
|
.as_any()
|
||||||
|
.downcast_ref()
|
||||||
|
.map(|other| self == other)
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user