pull/1/head
elfein727 2021-12-20 13:39:42 -08:00
commit c275e99d1a
3 changed files with 60 additions and 2 deletions

18
.gitignore vendored
View File

@ -1,2 +1,16 @@
/target
Cargo.lock
# ---> Rust
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# tuid
terminal ui thingy based on druid

41
src/widget/flex.rs Normal file
View File

@ -0,0 +1,41 @@
use crate::{Data, Size, Widget};
use super::WidgetPod;
enum Direction {
Vertical,
Horizont,
}
pub struct Flex<T> {
children: Vec<WidgetPod<T, Box<dyn Widget<T>>>>,
}
impl<T: Data> Flex<T> {
pub fn new() -> Self {
Self { children: vec![] }
}
pub fn with_child(mut self, child: impl Widget<T> + 'static) -> Self {
self.children.push(WidgetPod::new(Box::new(child)));
self
}
}
impl<T: Data> Widget<T> for Flex<T> {
fn layout(&mut self, bounds: &Size) -> Size {
let mut output = Size { a: 0, b: 0 };
for child in &mut self.children {
if output.a + child.layout(bounds).a < bounds.a {
output.a += child.layout(bounds).a;
output.b = child.layout(bounds).b.max(output.b);
} else {
output.a = child.layout(bounds).a.max(output.a);
output.b += child.layout(bounds).b;
}
}
output
}
fn paint(&self, buf: &mut [&mut [char]]) {}
}