mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix LinearLayout children width
Now properly gives the full width to every children.
This commit is contained in:
parent
0643c50bd5
commit
eb6b5d5728
18
src/vec.rs
18
src/vec.rs
@ -89,9 +89,21 @@ impl XY<usize> {
|
||||
|
||||
/// Returns a new `Vec2` with the axis `o` set to `value`.
|
||||
pub fn with_axis(&self, o: Orientation, value: usize) -> Self {
|
||||
let mut other = *self;
|
||||
*o.get_ref(&mut other) = value;
|
||||
other
|
||||
let mut new = *self;
|
||||
*o.get_ref(&mut new) = value;
|
||||
new
|
||||
}
|
||||
|
||||
/// Returns a new `Vec2` with the axis `o` set to the value from `other`.
|
||||
pub fn with_axis_from(&self, o: Orientation, other: &Vec2) -> Self {
|
||||
let mut new = *self;
|
||||
new.set_axis_from(o, other);
|
||||
new
|
||||
}
|
||||
|
||||
/// Sets the axis `o` on `self` to the value from `other`.
|
||||
pub fn set_axis_from(&mut self, o: Orientation, other: &Vec2) {
|
||||
*o.get_ref(self) = o.get(other);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,8 +192,11 @@ impl View for LinearLayout {
|
||||
self.get_min_size(size);
|
||||
}
|
||||
|
||||
let o = self.orientation;
|
||||
|
||||
for child in &mut self.children {
|
||||
child.view.layout(child.size);
|
||||
child.size.set_axis_from(o.swap(), &size);
|
||||
child.view.layout(size.with_axis_from(o, &child.size));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,6 +207,15 @@ impl SizeCache {
|
||||
|
||||
/// Creates a new bi-dimensional cache.
|
||||
///
|
||||
/// It will stay valid for the same request, and compatible ones.
|
||||
///
|
||||
/// A compatible request is one where, for each axis, either:
|
||||
///
|
||||
/// * the request is equal to the cached size, or
|
||||
/// * the request is larger than the cached size and the cache is unconstrained
|
||||
///
|
||||
/// Notes:
|
||||
///
|
||||
/// * `size` must fit inside `req`.
|
||||
/// * for each dimension, `constrained = (size == req)`
|
||||
fn build(size: Vec2, req: Vec2) -> XY<Self> {
|
||||
|
@ -3,9 +3,7 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use {Cursive, Printer};
|
||||
use vec::Vec2;
|
||||
use align::HAlign;
|
||||
use direction::Orientation;
|
||||
use theme::{ColorStyle, Effect};
|
||||
use view::View;
|
||||
|
||||
@ -120,8 +118,4 @@ impl View for ProgressBar {
|
||||
printer.print((offset, 0), &label);
|
||||
});
|
||||
}
|
||||
|
||||
fn get_min_size(&mut self, size: Vec2) -> Vec2 {
|
||||
size.with_axis(Orientation::Vertical, 1)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user