merged
commit
c275e99d1a
|
@ -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
|
||||
|
||||
|
|
|
@ -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]]) {}
|
||||
}
|
Loading…
Reference in New Issue