feat(constraints): Rename Constraint::Proportional to Constraint::Fill (#880)
`Constraint::Fill` is a more intuitive name for the behavior, and it is shorter. Resolves #859
This commit is contained in:
committed by
GitHub
parent
663bbde9c3
commit
1cbe1f52ab
@@ -38,7 +38,7 @@ const LENGTH_COLOR: Color = tailwind::SLATE.c700;
|
||||
const PERCENTAGE_COLOR: Color = tailwind::SLATE.c800;
|
||||
const RATIO_COLOR: Color = tailwind::SLATE.c900;
|
||||
// priority 4
|
||||
const PROPORTIONAL_COLOR: Color = tailwind::SLATE.c950;
|
||||
const FILL_COLOR: Color = tailwind::SLATE.c950;
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
struct App {
|
||||
@@ -60,7 +60,7 @@ enum SelectedTab {
|
||||
Length,
|
||||
Percentage,
|
||||
Ratio,
|
||||
Proportional,
|
||||
Fill,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -165,7 +165,7 @@ impl Widget for App {
|
||||
let [tabs, axis, demo] = area.split(&Layout::vertical([
|
||||
Constraint::Fixed(3),
|
||||
Constraint::Fixed(3),
|
||||
Proportional(0),
|
||||
Fill(0),
|
||||
]));
|
||||
|
||||
self.render_tabs(tabs, buf);
|
||||
@@ -272,7 +272,7 @@ impl SelectedTab {
|
||||
Length => 4,
|
||||
Percentage => 5,
|
||||
Ratio => 4,
|
||||
Proportional => 2,
|
||||
Fill => 2,
|
||||
Min => 5,
|
||||
Max => 5,
|
||||
}
|
||||
@@ -286,7 +286,7 @@ impl SelectedTab {
|
||||
Length => LENGTH_COLOR,
|
||||
Percentage => PERCENTAGE_COLOR,
|
||||
Ratio => RATIO_COLOR,
|
||||
Proportional => PROPORTIONAL_COLOR,
|
||||
Fill => FILL_COLOR,
|
||||
Min => MIN_COLOR,
|
||||
Max => MAX_COLOR,
|
||||
};
|
||||
@@ -301,7 +301,7 @@ impl Widget for SelectedTab {
|
||||
SelectedTab::Length => self.render_length_example(area, buf),
|
||||
SelectedTab::Percentage => self.render_percentage_example(area, buf),
|
||||
SelectedTab::Ratio => self.render_ratio_example(area, buf),
|
||||
SelectedTab::Proportional => self.render_proportional_example(area, buf),
|
||||
SelectedTab::Fill => self.render_fill_example(area, buf),
|
||||
SelectedTab::Min => self.render_min_example(area, buf),
|
||||
SelectedTab::Max => self.render_max_example(area, buf),
|
||||
}
|
||||
@@ -313,17 +313,11 @@ impl SelectedTab {
|
||||
let [example1, example2, example3, example4, _] =
|
||||
area.split(&Layout::vertical([Fixed(EXAMPLE_HEIGHT); 5]));
|
||||
|
||||
Example::new(&[Fixed(40), Proportional(0)]).render(example1, buf);
|
||||
Example::new(&[Fixed(20), Fixed(20), Proportional(0)]).render(example2, buf);
|
||||
Example::new(&[Fixed(40), Fill(0)]).render(example1, buf);
|
||||
Example::new(&[Fixed(20), Fixed(20), Fill(0)]).render(example2, buf);
|
||||
Example::new(&[Fixed(20), Min(20), Max(20)]).render(example3, buf);
|
||||
Example::new(&[
|
||||
Length(20),
|
||||
Percentage(20),
|
||||
Ratio(1, 5),
|
||||
Proportional(1),
|
||||
Fixed(15),
|
||||
])
|
||||
.render(example4, buf);
|
||||
Example::new(&[Length(20), Percentage(20), Ratio(1, 5), Fill(1), Fixed(15)])
|
||||
.render(example4, buf);
|
||||
}
|
||||
|
||||
fn render_length_example(&self, area: Rect, buf: &mut Buffer) {
|
||||
@@ -340,11 +334,11 @@ impl SelectedTab {
|
||||
let [example1, example2, example3, example4, example5, _] =
|
||||
area.split(&Layout::vertical([Fixed(EXAMPLE_HEIGHT); 6]));
|
||||
|
||||
Example::new(&[Percentage(75), Proportional(0)]).render(example1, buf);
|
||||
Example::new(&[Percentage(25), Proportional(0)]).render(example2, buf);
|
||||
Example::new(&[Percentage(75), Fill(0)]).render(example1, buf);
|
||||
Example::new(&[Percentage(25), Fill(0)]).render(example2, buf);
|
||||
Example::new(&[Percentage(50), Min(20)]).render(example3, buf);
|
||||
Example::new(&[Percentage(0), Max(0)]).render(example4, buf);
|
||||
Example::new(&[Percentage(0), Proportional(0)]).render(example5, buf);
|
||||
Example::new(&[Percentage(0), Fill(0)]).render(example5, buf);
|
||||
}
|
||||
|
||||
fn render_ratio_example(&self, area: Rect, buf: &mut Buffer) {
|
||||
@@ -357,11 +351,11 @@ impl SelectedTab {
|
||||
Example::new(&[Ratio(1, 2), Percentage(25), Length(10)]).render(example4, buf);
|
||||
}
|
||||
|
||||
fn render_proportional_example(&self, area: Rect, buf: &mut Buffer) {
|
||||
fn render_fill_example(&self, area: Rect, buf: &mut Buffer) {
|
||||
let [example1, example2, _] = area.split(&Layout::vertical([Fixed(EXAMPLE_HEIGHT); 3]));
|
||||
|
||||
Example::new(&[Proportional(1), Proportional(2), Proportional(3)]).render(example1, buf);
|
||||
Example::new(&[Proportional(1), Percentage(50), Proportional(1)]).render(example2, buf);
|
||||
Example::new(&[Fill(1), Fill(2), Fill(3)]).render(example1, buf);
|
||||
Example::new(&[Fill(1), Percentage(50), Fill(1)]).render(example2, buf);
|
||||
}
|
||||
|
||||
fn render_min_example(&self, area: Rect, buf: &mut Buffer) {
|
||||
@@ -421,7 +415,7 @@ impl Example {
|
||||
Constraint::Length(_) => LENGTH_COLOR,
|
||||
Constraint::Percentage(_) => PERCENTAGE_COLOR,
|
||||
Constraint::Ratio(_, _) => RATIO_COLOR,
|
||||
Constraint::Proportional(_) => PROPORTIONAL_COLOR,
|
||||
Constraint::Fill(_) => FILL_COLOR,
|
||||
Constraint::Min(_) => MIN_COLOR,
|
||||
Constraint::Max(_) => MAX_COLOR,
|
||||
};
|
||||
|
||||
@@ -36,12 +36,12 @@ const EXAMPLE_DATA: &[(&str, &[Constraint])] = &[
|
||||
&[Fixed(10), Min(10), Max(10), Percentage(10), Ratio(1,10)],
|
||||
),
|
||||
(
|
||||
"Proportional(u16) takes any excess space always",
|
||||
&[Length(20), Percentage(20), Ratio(1, 5), Proportional(1)],
|
||||
"Fill(u16) takes any excess space always",
|
||||
&[Length(20), Percentage(20), Ratio(1, 5), Fill(1)],
|
||||
),
|
||||
(
|
||||
"Here's all constraints in one line",
|
||||
&[Fixed(10), Min(10), Max(10), Percentage(10), Ratio(1,10), Proportional(1)],
|
||||
&[Fixed(10), Min(10), Max(10), Percentage(10), Ratio(1,10), Fill(1)],
|
||||
),
|
||||
(
|
||||
"",
|
||||
@@ -58,12 +58,12 @@ const EXAMPLE_DATA: &[(&str, &[Constraint])] = &[
|
||||
("", &[Length(100), Min(20)]),
|
||||
("`Fixed` is higher priority than `Min/Max`", &[Max(20), Fixed(10)]),
|
||||
("", &[Min(20), Fixed(90)]),
|
||||
("Proportional is the lowest priority and will fill any excess space", &[Proportional(1), Ratio(1, 4)]),
|
||||
("Proportional can be used to scale proportionally with other Proportional blocks", &[Proportional(1), Percentage(20), Proportional(2)]),
|
||||
("Fill is the lowest priority and will fill any excess space", &[Fill(1), Ratio(1, 4)]),
|
||||
("Fill can be used to scale proportionally with other Fill blocks", &[Fill(1), Percentage(20), Fill(2)]),
|
||||
("", &[Ratio(1, 3), Percentage(20), Ratio(2, 3)]),
|
||||
("StretchLast will stretch the last lowest priority constraint\nStretch will only stretch equal weighted constraints", &[Length(20), Length(15)]),
|
||||
("", &[Percentage(20), Length(15)]),
|
||||
("`Proportional(u16)` fills up excess space, but is lower priority to spacers.\ni.e. Proportional will only have widths in Flex::Stretch and Flex::StretchLast", &[Proportional(1), Proportional(1)]),
|
||||
("`Fill(u16)` fills up excess space, but is lower priority to spacers.\ni.e. Fill will only have widths in Flex::Stretch and Flex::StretchLast", &[Fill(1), Fill(1)]),
|
||||
("", &[Length(20), Fixed(20)]),
|
||||
(
|
||||
"When not using `Flex::Stretch` or `Flex::StretchLast`,\n`Min(u16)` and `Max(u16)` collapse to their lowest values",
|
||||
@@ -74,21 +74,21 @@ const EXAMPLE_DATA: &[(&str, &[Constraint])] = &[
|
||||
&[Max(20)],
|
||||
),
|
||||
("", &[Min(20), Max(20), Length(20), Fixed(20)]),
|
||||
("", &[Proportional(0), Proportional(0)]),
|
||||
("", &[Fill(0), Fill(0)]),
|
||||
(
|
||||
"`Proportional(1)` can be to scale with respect to other `Proportional(2)`",
|
||||
&[Proportional(1), Proportional(2)],
|
||||
"`Fill(1)` can be to scale with respect to other `Fill(2)`",
|
||||
&[Fill(1), Fill(2)],
|
||||
),
|
||||
(
|
||||
"",
|
||||
&[Proportional(1), Min(10), Max(10), Proportional(2)],
|
||||
&[Fill(1), Min(10), Max(10), Fill(2)],
|
||||
),
|
||||
(
|
||||
"`Proportional(0)` collapses if there are other non-zero `Proportional(_)`\nconstraints. e.g. `[Proportional(0), Proportional(0), Proportional(1)]`:",
|
||||
"`Fill(0)` collapses if there are other non-zero `Fill(_)`\nconstraints. e.g. `[Fill(0), Fill(0), Fill(1)]`:",
|
||||
&[
|
||||
Proportional(0),
|
||||
Proportional(0),
|
||||
Proportional(1),
|
||||
Fill(0),
|
||||
Fill(0),
|
||||
Fill(1),
|
||||
],
|
||||
),
|
||||
];
|
||||
@@ -244,7 +244,7 @@ fn example_height() -> u16 {
|
||||
|
||||
impl Widget for App {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let layout = Layout::vertical([Fixed(3), Fixed(1), Proportional(0)]);
|
||||
let layout = Layout::vertical([Fixed(3), Fixed(1), Fill(0)]);
|
||||
let [tabs, axis, demo] = area.split(&layout);
|
||||
self.tabs().render(tabs, buf);
|
||||
let scroll_needed = self.render_demo(demo, buf);
|
||||
@@ -419,7 +419,7 @@ impl Example {
|
||||
impl Widget for Example {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let title_height = get_description_height(&self.description);
|
||||
let layout = Layout::vertical([Fixed(title_height), Proportional(0)]);
|
||||
let layout = Layout::vertical([Fixed(title_height), Fill(0)]);
|
||||
let [title, illustrations] = area.split(&layout);
|
||||
|
||||
let (blocks, spacers) = Layout::horizontal(&self.constraints)
|
||||
@@ -518,7 +518,7 @@ fn color_for_constraint(constraint: Constraint) -> Color {
|
||||
Constraint::Length(_) => SLATE.c700,
|
||||
Constraint::Percentage(_) => SLATE.c800,
|
||||
Constraint::Ratio(_, _) => SLATE.c900,
|
||||
Constraint::Proportional(_) => SLATE.c950,
|
||||
Constraint::Fill(_) => SLATE.c950,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ fn constraint_label(constraint: Constraint) -> String {
|
||||
Min(n) => format!("{n}"),
|
||||
Max(n) => format!("{n}"),
|
||||
Percentage(n) => format!("{n}"),
|
||||
Proportional(n) => format!("{n}"),
|
||||
Fill(n) => format!("{n}"),
|
||||
Fixed(n) => format!("{n}"),
|
||||
Ratio(a, b) => format!("{a}:{b}"),
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ use strum::EnumIs;
|
||||
/// A constraint that defines the size of a layout element.
|
||||
///
|
||||
/// Constraints can be used to specify a fixed size, a percentage of the available space, a ratio of
|
||||
/// the available space, a minimum or maximum size or a proportional value for a layout element.
|
||||
/// the available space, a minimum or maximum size or a fill proportional value for a layout
|
||||
/// element.
|
||||
///
|
||||
/// Relative constraints (percentage, ratio) are calculated relative to the entire space being
|
||||
/// divided, rather than the space available after applying more fixed constraints (min, max,
|
||||
@@ -20,7 +21,7 @@ use strum::EnumIs;
|
||||
/// 4. [`Constraint::Length`]
|
||||
/// 5. [`Constraint::Percentage`]
|
||||
/// 6. [`Constraint::Ratio`]
|
||||
/// 7. [`Constraint::Proportional`]
|
||||
/// 7. [`Constraint::Fill`]
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -44,8 +45,8 @@ use strum::EnumIs;
|
||||
/// // Create a sidebar layout specifying maximum sizes for the columns
|
||||
/// let constraints = Constraint::from_maxes([30, 170]);
|
||||
///
|
||||
/// // Create a layout with proportional sizes for each element
|
||||
/// let constraints = Constraint::from_proportional_lengths([1, 2, 1]);
|
||||
/// // Create a layout with fill proportional sizes for each element
|
||||
/// let constraints = Constraint::from_fills([1, 2, 1]);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, EnumIs)]
|
||||
pub enum Constraint {
|
||||
@@ -56,7 +57,7 @@ pub enum Constraint {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// `[Fixed(40), Proportional(1)]`
|
||||
/// `[Fixed(40), Fill(1)]`
|
||||
///
|
||||
/// ```plain
|
||||
/// ┌──────────────────────────────────────┐┌────────┐
|
||||
@@ -64,7 +65,7 @@ pub enum Constraint {
|
||||
/// └──────────────────────────────────────┘└────────┘
|
||||
/// ```
|
||||
///
|
||||
/// `[Fixed(20), Fixed(20), Proportional(1)]`
|
||||
/// `[Fixed(20), Fixed(20), Fill(1)]`
|
||||
///
|
||||
/// ```plain
|
||||
/// ┌──────────────────┐┌──────────────────┐┌────────┐
|
||||
@@ -145,7 +146,7 @@ pub enum Constraint {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// `[Percentage(75), Proportional(1)]`
|
||||
/// `[Percentage(75), Fill(1)]`
|
||||
///
|
||||
/// ```plain
|
||||
/// ┌────────────────────────────────────┐┌──────────┐
|
||||
@@ -153,7 +154,7 @@ pub enum Constraint {
|
||||
/// └────────────────────────────────────┘└──────────┘
|
||||
/// ```
|
||||
///
|
||||
/// `[Percentage(50), Proportional(1)]`
|
||||
/// `[Percentage(50), Fill(1)]`
|
||||
///
|
||||
/// ```plain
|
||||
/// ┌───────────────────────┐┌───────────────────────┐
|
||||
@@ -184,16 +185,16 @@ pub enum Constraint {
|
||||
/// └───────────┘└──────────┘└───────────┘└──────────┘
|
||||
/// ```
|
||||
Ratio(u32, u32),
|
||||
/// Applies the scaling factor proportional to all other [`Constraint::Proportional`] elements
|
||||
/// Applies the scaling factor proportional to all other [`Constraint::Fill`] elements
|
||||
/// to fill excess space
|
||||
///
|
||||
/// The element will only expand into excess available space, proportionally matching other
|
||||
/// [`Constraint::Proportional`] elements while satisfying all other constraints.
|
||||
/// The element will only expand or fill into excess available space, proportionally matching
|
||||
/// other [`Constraint::Fill`] elements while satisfying all other constraints.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
///
|
||||
/// `[Proportional(1), Proportional(2), Proportional(3)]`
|
||||
/// `[Fill(1), Fill(2), Fill(3)]`
|
||||
///
|
||||
/// ```plain
|
||||
/// ┌──────┐┌───────────────┐┌───────────────────────┐
|
||||
@@ -201,14 +202,14 @@ pub enum Constraint {
|
||||
/// └──────┘└───────────────┘└───────────────────────┘
|
||||
/// ```
|
||||
///
|
||||
/// `[Proportional(1), Percentage(50), Proportional(1)]`
|
||||
/// `[Fill(1), Percentage(50), Fill(1)]`
|
||||
///
|
||||
/// ```plain
|
||||
/// ┌───────────┐┌───────────────────────┐┌──────────┐
|
||||
/// │ 13 px ││ 25 px ││ 12 px │
|
||||
/// └───────────┘└───────────────────────┘└──────────┘
|
||||
/// ```
|
||||
Proportional(u16),
|
||||
Fill(u16),
|
||||
}
|
||||
|
||||
impl Constraint {
|
||||
@@ -232,7 +233,7 @@ impl Constraint {
|
||||
}
|
||||
Constraint::Length(l) => length.min(l),
|
||||
Constraint::Fixed(l) => length.min(l),
|
||||
Constraint::Proportional(l) => length.min(l),
|
||||
Constraint::Fill(l) => length.min(l),
|
||||
Constraint::Max(m) => length.min(m),
|
||||
Constraint::Min(m) => length.max(m),
|
||||
}
|
||||
@@ -359,13 +360,13 @@ impl Constraint {
|
||||
/// let constraints = Constraint::from_mins([1, 2, 3]);
|
||||
/// let layout = Layout::default().constraints(constraints).split(area);
|
||||
/// ```
|
||||
pub fn from_proportional_lengths<T>(proportional_lengths: T) -> Vec<Constraint>
|
||||
pub fn from_fills<T>(proportional_factors: T) -> Vec<Constraint>
|
||||
where
|
||||
T: IntoIterator<Item = u16>,
|
||||
{
|
||||
proportional_lengths
|
||||
proportional_factors
|
||||
.into_iter()
|
||||
.map(Constraint::Proportional)
|
||||
.map(Constraint::Fill)
|
||||
.collect_vec()
|
||||
}
|
||||
}
|
||||
@@ -415,7 +416,7 @@ impl Display for Constraint {
|
||||
Constraint::Ratio(n, d) => write!(f, "Ratio({}, {})", n, d),
|
||||
Constraint::Length(l) => write!(f, "Length({})", l),
|
||||
Constraint::Fixed(l) => write!(f, "Fixed({})", l),
|
||||
Constraint::Proportional(l) => write!(f, "Proportional({})", l),
|
||||
Constraint::Fill(l) => write!(f, "Fill({})", l),
|
||||
Constraint::Max(m) => write!(f, "Max({})", m),
|
||||
Constraint::Min(m) => write!(f, "Min({})", m),
|
||||
}
|
||||
@@ -502,17 +503,14 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_proportional_lengths() {
|
||||
fn from_fills() {
|
||||
let expected = [
|
||||
Constraint::Proportional(1),
|
||||
Constraint::Proportional(2),
|
||||
Constraint::Proportional(3),
|
||||
Constraint::Fill(1),
|
||||
Constraint::Fill(2),
|
||||
Constraint::Fill(3),
|
||||
];
|
||||
assert_eq!(Constraint::from_proportional_lengths([1, 2, 3]), expected);
|
||||
assert_eq!(
|
||||
Constraint::from_proportional_lengths(vec![1, 2, 3]),
|
||||
expected
|
||||
);
|
||||
assert_eq!(Constraint::from_fills([1, 2, 3]), expected);
|
||||
assert_eq!(Constraint::from_fills(vec![1, 2, 3]), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -25,9 +25,12 @@ pub enum Flex {
|
||||
/// constraints. As a refresher, the priorities of constraints are as follows:
|
||||
///
|
||||
/// 1. [`Constraint::Fixed`]
|
||||
/// 2. [`Constraint::Min`] / [`Constraint::Max`]
|
||||
/// 3. [`Constraint::Length`] / [`Constraint::Percentage`] / [`Constraint::Ratio`]
|
||||
/// 4. [`Constraint::Proportional`]
|
||||
/// 2. [`Constraint::Min`]
|
||||
/// 3. [`Constraint::Max`]
|
||||
/// 4. [`Constraint::Length`]
|
||||
/// 5. [`Constraint::Percentage`]
|
||||
/// 6. [`Constraint::Ratio`]
|
||||
/// 7. [`Constraint::Fill`]
|
||||
///
|
||||
/// When every constraint is `Length`, the last element gets the excess.
|
||||
///
|
||||
@@ -81,13 +84,13 @@ pub enum Flex {
|
||||
/// ^^^^^^^^^^^^^^^^ EXCESS ^^^^^^^^^^^^^^^^
|
||||
/// ```
|
||||
///
|
||||
/// Proportional constraints have the lowest priority amongst all the constraints and hence
|
||||
/// Fill constraints have the lowest priority amongst all the constraints and hence
|
||||
/// will always take up any excess space available.
|
||||
///
|
||||
/// ```plain
|
||||
/// <----------------------------------- 80 px ------------------------------------>
|
||||
/// ┌──────20 px───────┐┌──────20 px───────┐┌──────20 px───────┐┌──────20 px───────┐
|
||||
/// │ Proportional(0) ││ Min(20) ││ Length(20) ││ Fixed(20) │
|
||||
/// │ Fill(0) ││ Min(20) ││ Length(20) ││ Fixed(20) │
|
||||
/// └──────────────────┘└──────────────────┘└──────────────────┘└──────────────────┘
|
||||
/// ^^^^^^ EXCESS ^^^^^^
|
||||
/// ```
|
||||
|
||||
@@ -9,8 +9,8 @@ use itertools::Itertools;
|
||||
use lru::LruCache;
|
||||
|
||||
use self::strengths::{
|
||||
FIXED_SIZE_EQ, LENGTH_SIZE_EQ, MAX_SIZE_EQ, MAX_SIZE_LE, MIN_SIZE_EQ, MIN_SIZE_GE,
|
||||
PERCENTAGE_SIZE_EQ, PROPORTIONAL_GROW, RATIO_SIZE_EQ, *,
|
||||
FILL_GROW, FIXED_SIZE_EQ, LENGTH_SIZE_EQ, MAX_SIZE_EQ, MAX_SIZE_LE, MIN_SIZE_EQ, MIN_SIZE_GE,
|
||||
PERCENTAGE_SIZE_EQ, RATIO_SIZE_EQ, *,
|
||||
};
|
||||
use super::{Flex, SegmentSize};
|
||||
use crate::prelude::*;
|
||||
@@ -620,7 +620,7 @@ impl Layout {
|
||||
configure_variable_constraints(&mut solver, &variables, area_size)?;
|
||||
configure_flex_constraints(&mut solver, area_size, &spacers, &segments, flex, spacing)?;
|
||||
configure_constraints(&mut solver, area_size, &segments, constraints)?;
|
||||
configure_proportional_constraints(&mut solver, &segments, constraints)?;
|
||||
configure_fill_constraints(&mut solver, &segments, constraints)?;
|
||||
|
||||
// `solver.fetch_changes()` can only be called once per solve
|
||||
let changes: HashMap<Variable, f64> = solver.fetch_changes().iter().copied().collect();
|
||||
@@ -694,9 +694,9 @@ fn configure_constraints(
|
||||
let size = area.size() * f64::from(num) / f64::from(den.max(1));
|
||||
solver.add_constraint(element.has_size(size, RATIO_SIZE_EQ))?;
|
||||
}
|
||||
Constraint::Proportional(_) => {
|
||||
Constraint::Fill(_) => {
|
||||
// given no other constraints, this segment will grow as much as possible.
|
||||
solver.add_constraint(element.has_size(area, PROPORTIONAL_GROW))?;
|
||||
solver.add_constraint(element.has_size(area, FILL_GROW))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -792,21 +792,21 @@ fn configure_flex_constraints(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Make every `Proportional` constraint proportionally equal to each other
|
||||
/// Make every `Fill` constraint proportionally equal to each other
|
||||
/// This will make it fill up empty spaces equally
|
||||
///
|
||||
/// [Proportional(1), Proportional(1)]
|
||||
/// [Fill(1), Fill(1)]
|
||||
/// ┌──────┐┌──────┐
|
||||
/// │abcdef││abcdef│
|
||||
/// └──────┘└──────┘
|
||||
///
|
||||
/// [Proportional(1), Proportional(2)]
|
||||
/// [Fill(1), Fill(2)]
|
||||
/// ┌──────┐┌────────────┐
|
||||
/// │abcdef││abcdefabcdef│
|
||||
/// └──────┘└────────────┘
|
||||
///
|
||||
/// size == base_element * scaling_factor
|
||||
fn configure_proportional_constraints(
|
||||
fn configure_fill_constraints(
|
||||
solver: &mut Solver,
|
||||
segments: &[Element],
|
||||
constraints: &[Constraint],
|
||||
@@ -814,17 +814,15 @@ fn configure_proportional_constraints(
|
||||
for ((&l_constraint, &l_element), (&r_constraint, &r_element)) in constraints
|
||||
.iter()
|
||||
.zip(segments.iter())
|
||||
.filter(|(c, _)| c.is_proportional())
|
||||
.filter(|(c, _)| c.is_fill())
|
||||
.tuple_combinations()
|
||||
{
|
||||
// `Proportional` will only expand into _excess_ available space. You can think of
|
||||
// `Proportional` element sizes as starting from `0` and incrementally
|
||||
// increasing while proportionally matching other `Proportional` spaces AND
|
||||
// `Fill` will only expand into _excess_ available space. You can think of
|
||||
// `Fill` element sizes as starting from `0` and incrementally
|
||||
// increasing while proportionally matching other `Fill` spaces AND
|
||||
// also meeting all other constraints.
|
||||
if let (
|
||||
Constraint::Proportional(l_scaling_factor),
|
||||
Constraint::Proportional(r_scaling_factor),
|
||||
) = (l_constraint, r_constraint)
|
||||
if let (Constraint::Fill(l_scaling_factor), Constraint::Fill(r_scaling_factor)) =
|
||||
(l_constraint, r_constraint)
|
||||
{
|
||||
// because of the way cassowary works, we need to use `*` instead of `/`
|
||||
// l_size / l_scaling_factor == l_size / l_scaling_factor
|
||||
@@ -846,7 +844,7 @@ fn configure_proportional_constraints(
|
||||
);
|
||||
solver.add_constraint(
|
||||
(r_scaling_factor * l_element.size())
|
||||
| EQ(PROPORTIONAL_SCALING_EQ)
|
||||
| EQ(FILL_SCALING_EQ)
|
||||
| (l_scaling_factor * r_element.size()),
|
||||
)?;
|
||||
}
|
||||
@@ -969,12 +967,12 @@ mod strengths {
|
||||
/// └ ┘└───┘└ ┘└───┘└ ┘
|
||||
pub const SPACER_SIZE_EQ: f64 = REQUIRED - 1.0;
|
||||
|
||||
/// The strength to apply to Proportional constraints so that their sizes are proportional.
|
||||
/// The strength to apply to Fill constraints so that their sizes are proportional.
|
||||
///
|
||||
/// ┌───────────────┐┌───────────────┐
|
||||
/// │Proportional(x)││Proportional(x)│
|
||||
/// │ Fill(x) ││ Fill(x) │
|
||||
/// └───────────────┘└───────────────┘
|
||||
pub const PROPORTIONAL_SCALING_EQ: f64 = REQUIRED - 1.0;
|
||||
pub const FILL_SCALING_EQ: f64 = REQUIRED - 1.0;
|
||||
|
||||
/// The strength to apply to Fixed constraints.
|
||||
///
|
||||
@@ -1032,12 +1030,12 @@ mod strengths {
|
||||
/// └────────┘
|
||||
pub const MAX_SIZE_EQ: f64 = MEDIUM / 10.0;
|
||||
|
||||
/// The strength to apply to Proportional growing constraints.
|
||||
/// The strength to apply to Fill growing constraints.
|
||||
///
|
||||
/// ┌─────────────────────┐
|
||||
/// │<= Proportional(x) =>│
|
||||
/// │<= Fill(x) =>│
|
||||
/// └─────────────────────┘
|
||||
pub const PROPORTIONAL_GROW: f64 = WEAK * 10.0;
|
||||
pub const FILL_GROW: f64 = WEAK * 10.0;
|
||||
|
||||
/// The strength to apply to growing constraints.
|
||||
///
|
||||
@@ -1056,7 +1054,7 @@ mod strengths {
|
||||
#[allow(dead_code)]
|
||||
pub fn is_valid() -> bool {
|
||||
SPACER_SIZE_EQ > FIXED_SIZE_EQ
|
||||
&& PROPORTIONAL_SCALING_EQ > FIXED_SIZE_EQ
|
||||
&& FILL_SCALING_EQ > FIXED_SIZE_EQ
|
||||
&& FIXED_SIZE_EQ > MIN_SIZE_GE
|
||||
&& MIN_SIZE_GE > MIN_SIZE_EQ
|
||||
&& MAX_SIZE_LE > MAX_SIZE_EQ
|
||||
@@ -1066,8 +1064,8 @@ mod strengths {
|
||||
&& LENGTH_SIZE_EQ > PERCENTAGE_SIZE_EQ
|
||||
&& PERCENTAGE_SIZE_EQ > RATIO_SIZE_EQ
|
||||
&& RATIO_SIZE_EQ > MAX_SIZE_EQ
|
||||
&& MIN_SIZE_GE > PROPORTIONAL_GROW
|
||||
&& PROPORTIONAL_GROW > GROW
|
||||
&& MIN_SIZE_GE > FILL_GROW
|
||||
&& FILL_GROW > GROW
|
||||
&& GROW > SPACE_GROW
|
||||
}
|
||||
}
|
||||
@@ -1084,14 +1082,14 @@ mod tests {
|
||||
fn strength() {
|
||||
assert!(strengths::is_valid());
|
||||
assert_eq!(strengths::SPACER_SIZE_EQ, REQUIRED - 1.0);
|
||||
assert_eq!(strengths::PROPORTIONAL_SCALING_EQ, REQUIRED - 1.0);
|
||||
assert_eq!(strengths::FILL_SCALING_EQ, REQUIRED - 1.0);
|
||||
assert_eq!(strengths::FIXED_SIZE_EQ, REQUIRED / 10.0);
|
||||
assert_eq!(strengths::MIN_SIZE_GE, STRONG * 10.0);
|
||||
assert_eq!(strengths::LENGTH_SIZE_EQ, STRONG / 10.0);
|
||||
assert_eq!(strengths::PERCENTAGE_SIZE_EQ, MEDIUM * 10.0);
|
||||
assert_eq!(strengths::RATIO_SIZE_EQ, MEDIUM);
|
||||
assert_eq!(strengths::MIN_SIZE_EQ, MEDIUM / 10.0);
|
||||
assert_eq!(strengths::PROPORTIONAL_GROW, WEAK * 10.0);
|
||||
assert_eq!(strengths::FILL_GROW, WEAK * 10.0);
|
||||
assert_eq!(strengths::GROW, WEAK);
|
||||
assert_eq!(strengths::SPACE_GROW, WEAK / 10.0);
|
||||
}
|
||||
@@ -1858,10 +1856,10 @@ mod tests {
|
||||
#[case::fixed_higher_priority(vec![50, 25, 25], vec![Ratio(1, 4), Percentage(25), Fixed(25)])]
|
||||
#[case::fixed_higher_priority(vec![79, 1, 20], vec![Length(100), Fixed(1), Min(20)])]
|
||||
#[case::fixed_higher_priority(vec![20, 1, 79], vec![Min(20), Fixed(1), Length(100)])]
|
||||
#[case::fixed_higher_priority(vec![45, 10, 45], vec![Proportional(1), Fixed(10), Proportional(1)])]
|
||||
#[case::fixed_higher_priority(vec![30, 10, 60], vec![Proportional(1), Fixed(10), Proportional(2)])]
|
||||
#[case::fixed_higher_priority(vec![18, 10, 72], vec![Proportional(1), Fixed(10), Proportional(4)])]
|
||||
#[case::fixed_higher_priority(vec![15, 10, 75], vec![Proportional(1), Fixed(10), Proportional(5)])]
|
||||
#[case::fixed_higher_priority(vec![45, 10, 45], vec![Fill(1), Fixed(10), Fill(1)])]
|
||||
#[case::fixed_higher_priority(vec![30, 10, 60], vec![Fill(1), Fixed(10), Fill(2)])]
|
||||
#[case::fixed_higher_priority(vec![18, 10, 72], vec![Fill(1), Fixed(10), Fill(4)])]
|
||||
#[case::fixed_higher_priority(vec![15, 10, 75], vec![Fill(1), Fixed(10), Fill(5)])]
|
||||
#[case::three_lengths_reference(vec![25, 25, 50], vec![Length(25), Length(25), Length(25)])]
|
||||
// #[case::previously_unstable_test(vec![25, 50, 25], vec![Length(25), Length(25),
|
||||
// Fixed(25)])]
|
||||
@@ -1877,8 +1875,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::excess_in_last_variable(vec![13, 10, 27], vec![Proportional(1), Fixed(10), Proportional(2)])]
|
||||
#[case::excess_in_last_variable(vec![10, 27, 13], vec![Fixed(10), Proportional(2), Proportional(1)])] // might be unstable?
|
||||
#[case::excess_in_last_variable(vec![13, 10, 27], vec![Fill(1), Fixed(10), Fill(2)])]
|
||||
#[case::excess_in_last_variable(vec![10, 27, 13], vec![Fixed(10), Fill(2), Fill(1)])] // might be unstable?
|
||||
fn fixed_with_50_width(#[case] expected: Vec<u16>, #[case] constraints: Vec<Constraint>) {
|
||||
let rect = Rect::new(0, 0, 50, 1);
|
||||
let r = Layout::horizontal(constraints)
|
||||
@@ -1891,42 +1889,42 @@ mod tests {
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::multiple_same_proportionals_are_same(vec![20, 40, 20, 20], vec![Proportional(1), Proportional(2), Proportional(1), Proportional(1)])]
|
||||
#[case::incremental(vec![10, 20, 30, 40], vec![Proportional(1), Proportional(2), Proportional(3), Proportional(4)])]
|
||||
#[case::decremental(vec![40, 30, 20, 10], vec![Proportional(4), Proportional(3), Proportional(2), Proportional(1)])]
|
||||
#[case::randomly_ordered(vec![10, 30, 20, 40], vec![Proportional(1), Proportional(3), Proportional(2), Proportional(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Proportional(1), Proportional(3), Fixed(50), Proportional(2), Proportional(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Proportional(1), Proportional(3), Length(50), Proportional(2), Proportional(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Proportional(1), Proportional(3), Percentage(50), Proportional(2), Proportional(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Proportional(1), Proportional(3), Min(50), Proportional(2), Proportional(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Proportional(1), Proportional(3), Max(50), Proportional(2), Proportional(4)])]
|
||||
#[case::zero_width(vec![0, 100, 0], vec![Proportional(0), Proportional(1), Proportional(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Proportional(0), Fixed(1), Proportional(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Proportional(0), Length(1), Proportional(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Proportional(0), Percentage(1), Proportional(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Proportional(0), Min(1), Proportional(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Proportional(0), Max(1), Proportional(0)])]
|
||||
#[case::zero_width(vec![0, 67, 0, 33], vec![Proportional(0), Proportional(2), Proportional(0), Proportional(1)])]
|
||||
#[case::space_filler(vec![0, 80, 20], vec![Proportional(0), Proportional(2), Percentage(20)])]
|
||||
#[case::space_filler(vec![40, 40, 20], vec![Proportional(0), Proportional(0), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Proportional(0), Ratio(1, 5)])]
|
||||
#[case::space_filler(vec![0, 100], vec![Proportional(0), Proportional(u16::MAX)])]
|
||||
#[case::space_filler(vec![100, 0], vec![Proportional(u16::MAX), Proportional(0)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Proportional(0), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Proportional(1), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Proportional(u16::MAX), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 0, 20], vec![Proportional(u16::MAX), Proportional(0), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Proportional(0), Fixed(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Proportional(0), Length(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Proportional(0), Min(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Proportional(0), Max(20)])]
|
||||
#[case::proportional_collapses_first(vec![7, 6, 7, 30, 50], vec![Proportional(1), Proportional(1), Proportional(1), Min(30), Length(50)])]
|
||||
#[case::proportional_collapses_first(vec![0, 0, 0, 50, 50], vec![Proportional(1), Proportional(1), Proportional(1), Length(50), Length(50)])]
|
||||
#[case::proportional_collapses_first(vec![0, 0, 0, 75, 25], vec![Proportional(1), Proportional(1), Proportional(1), Length(75), Length(50)])]
|
||||
#[case::proportional_collapses_first(vec![0, 0, 0, 50, 50], vec![Proportional(1), Proportional(1), Proportional(1), Min(50), Max(50)])]
|
||||
#[case::proportional_collapses_first(vec![0, 0, 0, 100], vec![Proportional(1), Proportional(1), Proportional(1), Ratio(1, 1)])]
|
||||
#[case::proportional_collapses_first(vec![0, 0, 0, 100], vec![Proportional(1), Proportional(1), Proportional(1), Percentage(100)])]
|
||||
fn proportional(#[case] expected: Vec<u16>, #[case] constraints: Vec<Constraint>) {
|
||||
#[case::multiple_same_fill_are_same(vec![20, 40, 20, 20], vec![Fill(1), Fill(2), Fill(1), Fill(1)])]
|
||||
#[case::incremental(vec![10, 20, 30, 40], vec![Fill(1), Fill(2), Fill(3), Fill(4)])]
|
||||
#[case::decremental(vec![40, 30, 20, 10], vec![Fill(4), Fill(3), Fill(2), Fill(1)])]
|
||||
#[case::randomly_ordered(vec![10, 30, 20, 40], vec![Fill(1), Fill(3), Fill(2), Fill(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Fill(1), Fill(3), Fixed(50), Fill(2), Fill(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Fill(1), Fill(3), Length(50), Fill(2), Fill(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Fill(1), Fill(3), Percentage(50), Fill(2), Fill(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Fill(1), Fill(3), Min(50), Fill(2), Fill(4)])]
|
||||
#[case::randomly_ordered(vec![5, 15, 50, 10, 20], vec![Fill(1), Fill(3), Max(50), Fill(2), Fill(4)])]
|
||||
#[case::zero_width(vec![0, 100, 0], vec![Fill(0), Fill(1), Fill(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Fill(0), Fixed(1), Fill(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Fill(0), Length(1), Fill(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Fill(0), Percentage(1), Fill(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Fill(0), Min(1), Fill(0)])]
|
||||
#[case::zero_width(vec![50, 1, 49], vec![Fill(0), Max(1), Fill(0)])]
|
||||
#[case::zero_width(vec![0, 67, 0, 33], vec![Fill(0), Fill(2), Fill(0), Fill(1)])]
|
||||
#[case::space_filler(vec![0, 80, 20], vec![Fill(0), Fill(2), Percentage(20)])]
|
||||
#[case::space_filler(vec![40, 40, 20], vec![Fill(0), Fill(0), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Fill(0), Ratio(1, 5)])]
|
||||
#[case::space_filler(vec![0, 100], vec![Fill(0), Fill(u16::MAX)])]
|
||||
#[case::space_filler(vec![100, 0], vec![Fill(u16::MAX), Fill(0)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Fill(0), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Fill(1), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Fill(u16::MAX), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 0, 20], vec![Fill(u16::MAX), Fill(0), Percentage(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Fill(0), Fixed(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Fill(0), Length(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Fill(0), Min(20)])]
|
||||
#[case::space_filler(vec![80, 20], vec![Fill(0), Max(20)])]
|
||||
#[case::fill_collapses_first(vec![7, 6, 7, 30, 50], vec![Fill(1), Fill(1), Fill(1), Min(30), Length(50)])]
|
||||
#[case::fill_collapses_first(vec![0, 0, 0, 50, 50], vec![Fill(1), Fill(1), Fill(1), Length(50), Length(50)])]
|
||||
#[case::fill_collapses_first(vec![0, 0, 0, 75, 25], vec![Fill(1), Fill(1), Fill(1), Length(75), Length(50)])]
|
||||
#[case::fill_collapses_first(vec![0, 0, 0, 50, 50], vec![Fill(1), Fill(1), Fill(1), Min(50), Max(50)])]
|
||||
#[case::fill_collapses_first(vec![0, 0, 0, 100], vec![Fill(1), Fill(1), Fill(1), Ratio(1, 1)])]
|
||||
#[case::fill_collapses_first(vec![0, 0, 0, 100], vec![Fill(1), Fill(1), Fill(1), Percentage(100)])]
|
||||
fn fill(#[case] expected: Vec<u16>, #[case] constraints: Vec<Constraint>) {
|
||||
let rect = Rect::new(0, 0, 100, 1);
|
||||
let r = Layout::horizontal(constraints)
|
||||
.split(rect)
|
||||
@@ -2103,8 +2101,8 @@ mod tests {
|
||||
#[case::n(vec![(0, 75), (75, 25)], vec![Ratio(1, 4), Length(25)])]
|
||||
#[case::o(vec![(0, 25), (25, 75)], vec![Percentage(25), Ratio(1, 4)])]
|
||||
#[case::p(vec![(0, 75), (75, 25)], vec![Ratio(1, 4), Percentage(25)])]
|
||||
#[case::q(vec![(0, 25), (25, 75)], vec![Ratio(1, 4), Proportional(25)])]
|
||||
#[case::r(vec![(0, 75), (75, 25)], vec![Proportional(25), Ratio(1, 4)])]
|
||||
#[case::q(vec![(0, 25), (25, 75)], vec![Ratio(1, 4), Fill(25)])]
|
||||
#[case::r(vec![(0, 75), (75, 25)], vec![Fill(25), Ratio(1, 4)])]
|
||||
fn constraint_specification_tests_for_priority(
|
||||
#[case] expected: Vec<(u16, u16)>,
|
||||
#[case] constraints: Vec<Constraint>,
|
||||
@@ -2147,17 +2145,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::prop(vec![(0 , 10), (10, 80), (90 , 10)] , vec![Fixed(10), Proportional(1), Fixed(10)], Flex::Stretch)]
|
||||
#[case::prop(vec![(0 , 10), (10, 80), (90 , 10)] , vec![Fixed(10), Fill(1), Fixed(10)], Flex::Stretch)]
|
||||
#[case::flex(vec![(0 , 10), (90 , 10)] , vec![Fixed(10), Fixed(10)], Flex::SpaceBetween)]
|
||||
#[case::prop(vec![(0 , 27), (27, 10), (37, 26), (63, 10), (73, 27)] , vec![Proportional(1), Fixed(10), Proportional(1), Fixed(10), Proportional(1)], Flex::Stretch)]
|
||||
#[case::prop(vec![(0 , 27), (27, 10), (37, 26), (63, 10), (73, 27)] , vec![Fill(1), Fixed(10), Fill(1), Fixed(10), Fill(1)], Flex::Stretch)]
|
||||
#[case::flex(vec![(27 , 10), (63, 10)] , vec![Fixed(10), Fixed(10)], Flex::SpaceAround)]
|
||||
#[case::prop(vec![(0 , 10), (10, 10), (20 , 80)] , vec![Fixed(10), Fixed(10), Proportional(1)], Flex::Stretch)]
|
||||
#[case::prop(vec![(0 , 10), (10, 10), (20 , 80)] , vec![Fixed(10), Fixed(10), Fill(1)], Flex::Stretch)]
|
||||
#[case::flex(vec![(0 , 10), (10, 10)] , vec![Fixed(10), Fixed(10)], Flex::Start)]
|
||||
#[case::prop(vec![(0 , 80), (80 , 10), (90, 10)] , vec![Proportional(1), Fixed(10), Fixed(10)], Flex::Stretch)]
|
||||
#[case::prop(vec![(0 , 80), (80 , 10), (90, 10)] , vec![Fill(1), Fixed(10), Fixed(10)], Flex::Stretch)]
|
||||
#[case::flex(vec![(80 , 10), (90, 10)] , vec![Fixed(10), Fixed(10)], Flex::End)]
|
||||
#[case::prop(vec![(0 , 40), (40, 10), (50, 10), (60, 40)] , vec![Proportional(1), Fixed(10), Fixed(10), Proportional(1)], Flex::Stretch)]
|
||||
#[case::prop(vec![(0 , 40), (40, 10), (50, 10), (60, 40)] , vec![Fill(1), Fixed(10), Fixed(10), Fill(1)], Flex::Stretch)]
|
||||
#[case::flex(vec![(40 , 10), (50, 10)] , vec![Fixed(10), Fixed(10)], Flex::Center)]
|
||||
fn proportional_vs_flex(
|
||||
fn fill_vs_flex(
|
||||
#[case] expected: Vec<(u16, u16)>,
|
||||
#[case] constraints: Vec<Constraint>,
|
||||
#[case] flex: Flex,
|
||||
@@ -2172,37 +2170,37 @@ mod tests {
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::Stretch , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::StretchLast , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::SpaceAround , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::SpaceBetween , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::Start , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::Center , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::End , 0)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Proportional(1), Proportional(1)], Flex::Stretch , 10)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Proportional(1), Proportional(1)], Flex::StretchLast , 10)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Proportional(1), Proportional(1)], Flex::Start , 10)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Proportional(1), Proportional(1)], Flex::Center , 10)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Proportional(1), Proportional(1)], Flex::End , 10)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::Stretch , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::StretchLast , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::SpaceAround , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::SpaceBetween , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::Start , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::Center , 0)]
|
||||
#[case::flex0(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::End , 0)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Fill(1), Fill(1)], Flex::Stretch , 10)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Fill(1), Fill(1)], Flex::StretchLast , 10)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Fill(1), Fill(1)], Flex::Start , 10)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Fill(1), Fill(1)], Flex::Center , 10)]
|
||||
#[case::flex10(vec![(0 , 45), (55 , 45)] , vec![Fill(1), Fill(1)], Flex::End , 10)]
|
||||
// SpaceAround and SpaceBetween spacers behave differently from other flexes
|
||||
#[case::flex10(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::SpaceAround , 10)]
|
||||
#[case::flex10(vec![(0 , 50), (50 , 50)] , vec![Proportional(1), Proportional(1)], Flex::SpaceBetween , 10)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::Stretch , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::StretchLast , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::SpaceAround , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::SpaceBetween , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::Start , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::Center , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::End , 0)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::Stretch , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::StretchLast , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::Start , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::Center , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::End , 10)]
|
||||
#[case::flex10(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::SpaceAround , 10)]
|
||||
#[case::flex10(vec![(0 , 50), (50 , 50)] , vec![Fill(1), Fill(1)], Flex::SpaceBetween , 10)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::Stretch , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::StretchLast , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::SpaceAround , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::SpaceBetween , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::Start , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::Center , 0)]
|
||||
#[case::flex_fixed0(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::End , 0)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::Stretch , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::StretchLast , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::Start , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::Center , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 35), (45, 10), (65 , 35)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::End , 10)]
|
||||
// SpaceAround and SpaceBetween spacers behave differently from other flexes
|
||||
#[case::flex_fixed10(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::SpaceAround , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Proportional(1), Fixed(10), Proportional(1)], Flex::SpaceBetween , 10)]
|
||||
fn proportional_spacing(
|
||||
#[case::flex_fixed10(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::SpaceAround , 10)]
|
||||
#[case::flex_fixed10(vec![(0 , 45), (45, 10), (55 , 45)] , vec![Fill(1), Fixed(10), Fill(1)], Flex::SpaceBetween , 10)]
|
||||
fn fill_spacing(
|
||||
#[case] expected: Vec<(u16, u16)>,
|
||||
#[case] constraints: Vec<Constraint>,
|
||||
#[case] flex: Flex,
|
||||
|
||||
@@ -133,7 +133,7 @@ impl<DS: DateStyler> Monthly<'_, DS> {
|
||||
let layout = Layout::vertical([
|
||||
Constraint::Length(self.show_month.is_some().into()),
|
||||
Constraint::Length(self.show_weekday.is_some().into()),
|
||||
Constraint::Proportional(1),
|
||||
Constraint::Fill(1),
|
||||
]);
|
||||
let [month_header, days_header, days_area] = area.split(&layout);
|
||||
|
||||
|
||||
@@ -775,7 +775,7 @@ impl Table<'_> {
|
||||
let [_selection_area, columns_area] =
|
||||
Rect::new(0, 0, max_width, 1).split(&Layout::horizontal([
|
||||
Constraint::Fixed(selection_width),
|
||||
Constraint::Proportional(0),
|
||||
Constraint::Fill(0),
|
||||
]));
|
||||
let rects = Layout::horizontal(widths)
|
||||
.flex(self.flex)
|
||||
|
||||
Reference in New Issue
Block a user