mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-27 15:44:17 +02:00
Fix offset bug
This commit is contained in:
parent
86edfed892
commit
c094efa74c
13
src/app.rs
13
src/app.rs
@ -238,10 +238,21 @@ impl Application for AppState {
|
|||||||
use crate::tuice::FlexElement;
|
use crate::tuice::FlexElement;
|
||||||
use crate::tuice::TextTable;
|
use crate::tuice::TextTable;
|
||||||
|
|
||||||
|
Flex::column()
|
||||||
|
.with_flex_child(
|
||||||
Flex::row_with_children(vec![
|
Flex::row_with_children(vec![
|
||||||
FlexElement::new(TextTable::new(vec!["A", "B", "C"])),
|
FlexElement::new(TextTable::new(vec!["A", "B", "C"])),
|
||||||
FlexElement::new(TextTable::new(vec!["D", "E", "F"])),
|
FlexElement::new(TextTable::new(vec!["D", "E", "F"])),
|
||||||
])
|
]),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
.with_flex_child(
|
||||||
|
Flex::row_with_children(vec![
|
||||||
|
FlexElement::new(TextTable::new(vec!["G", "H", "I", "J"])),
|
||||||
|
FlexElement::new(TextTable::new(vec!["K", "L", "M", "N"])),
|
||||||
|
]),
|
||||||
|
2,
|
||||||
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use itertools::izip;
|
|
||||||
use tui::{backend::Backend, layout::Rect, Frame};
|
use tui::{backend::Backend, layout::Rect, Frame};
|
||||||
|
|
||||||
pub mod flex_element;
|
pub mod flex_element;
|
||||||
@ -111,9 +110,8 @@ impl<'a, Message> TmpComponent<Message> for Flex<'a, Message> {
|
|||||||
let mut remaining_bounds = bounds;
|
let mut remaining_bounds = bounds;
|
||||||
let mut children = vec![LayoutNode::default(); self.children.len()];
|
let mut children = vec![LayoutNode::default(); self.children.len()];
|
||||||
let mut flexible_children_indexes = vec![];
|
let mut flexible_children_indexes = vec![];
|
||||||
let mut offsets = vec![];
|
let mut current_x_offset = 0;
|
||||||
let mut current_x = 0;
|
let mut current_y_offset = 0;
|
||||||
let mut current_y = 0;
|
|
||||||
let mut sizes = Vec::with_capacity(self.children.len());
|
let mut sizes = Vec::with_capacity(self.children.len());
|
||||||
let mut current_size = Size::default();
|
let mut current_size = Size::default();
|
||||||
let mut total_flex = 0;
|
let mut total_flex = 0;
|
||||||
@ -129,16 +127,6 @@ impl<'a, Message> TmpComponent<Message> for Flex<'a, Message> {
|
|||||||
let size = child.child_layout(remaining_bounds, child_node);
|
let size = child.child_layout(remaining_bounds, child_node);
|
||||||
current_size += size;
|
current_size += size;
|
||||||
remaining_bounds.shrink_size(size);
|
remaining_bounds.shrink_size(size);
|
||||||
offsets.push((current_x, current_y));
|
|
||||||
|
|
||||||
match self.alignment {
|
|
||||||
Axis::Horizontal => {
|
|
||||||
current_x += size.width;
|
|
||||||
}
|
|
||||||
Axis::Vertical => {
|
|
||||||
current_y += size.height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sizes.push(size);
|
sizes.push(size);
|
||||||
} else {
|
} else {
|
||||||
@ -161,9 +149,6 @@ impl<'a, Message> TmpComponent<Message> for Flex<'a, Message> {
|
|||||||
let new_size =
|
let new_size =
|
||||||
child.ratio_layout(remaining_bounds, total_flex, child_node, self.alignment);
|
child.ratio_layout(remaining_bounds, total_flex, child_node, self.alignment);
|
||||||
current_size += new_size;
|
current_size += new_size;
|
||||||
offsets.push((current_x, current_y));
|
|
||||||
current_x += new_size.width;
|
|
||||||
|
|
||||||
*size = new_size;
|
*size = new_size;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -181,12 +166,21 @@ impl<'a, Message> TmpComponent<Message> for Flex<'a, Message> {
|
|||||||
// Now that we're done determining sizes, convert all children into the appropriate
|
// Now that we're done determining sizes, convert all children into the appropriate
|
||||||
// layout nodes. Remember - parents determine children, and so, we determine
|
// layout nodes. Remember - parents determine children, and so, we determine
|
||||||
// children here!
|
// children here!
|
||||||
izip!(sizes, offsets, children.iter_mut()).for_each(
|
sizes
|
||||||
|(size, offset, child): (Size, (u16, u16), &mut LayoutNode)| {
|
.iter()
|
||||||
let rect = Rect::new(offset.0, offset.1, size.width, size.height);
|
.zip(children.iter_mut())
|
||||||
child.rect = rect;
|
.for_each(|(size, child)| {
|
||||||
},
|
child.rect = Rect::new(current_x_offset, current_y_offset, size.width, size.height);
|
||||||
);
|
|
||||||
|
match self.alignment {
|
||||||
|
Axis::Horizontal => {
|
||||||
|
current_x_offset += size.width;
|
||||||
|
}
|
||||||
|
Axis::Vertical => {
|
||||||
|
current_y_offset += size.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
node.children = children;
|
node.children = children;
|
||||||
|
|
||||||
current_size
|
current_size
|
||||||
|
Loading…
x
Reference in New Issue
Block a user