diff options
author | 2020-08-16 19:20:02 -0500 | |
---|---|---|
committer | 2020-08-22 21:23:50 +0200 | |
commit | fed30ef7753bbe33af026f1f46a09d8381682284 (patch) | |
tree | 1f0d3b3a1f50fbdb982d2c2ce436bd5f49288c54 /style | |
parent | 32561bd85c6db0d7e6d9d12c87b87f4b50f1d43f (diff) | |
download | iced-fed30ef7753bbe33af026f1f46a09d8381682284.tar.gz iced-fed30ef7753bbe33af026f1f46a09d8381682284.tar.bz2 iced-fed30ef7753bbe33af026f1f46a09d8381682284.zip |
added FillMode::fill()
Diffstat (limited to 'style')
-rw-r--r-- | style/src/rule.rs | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/style/src/rule.rs b/style/src/rule.rs index aa095d3b..6ba54e33 100644 --- a/style/src/rule.rs +++ b/style/src/rule.rs @@ -19,6 +19,53 @@ pub enum FillMode { AsymmetricPadding(u16, u16), } +impl FillMode { + /// Return the starting offset and length of the rule. + /// + /// * `space` - The space to fill. + /// + /// # Returns + /// + /// * (starting_offset, length) + pub fn fill(&self, space: f32) -> (f32, f32) { + match *self { + FillMode::Full => (0.0, space), + FillMode::Percent(percent) => { + if percent >= 100.0 { + (0.0, space) + } else { + let percent_width = (space * percent / 100.0).round(); + + (((space - percent_width) / 2.0).round(), percent_width) + } + } + FillMode::Padded(padding) => { + if padding == 0 { + (0.0, space) + } else { + let padding = padding as f32; + let mut line_width = space - (padding * 2.0); + if line_width < 0.0 { + line_width = 0.0; + } + + (padding, line_width) + } + } + FillMode::AsymmetricPadding(first_pad, second_pad) => { + let first_pad = first_pad as f32; + let second_pad = second_pad as f32; + let mut line_width = space - first_pad - second_pad; + if line_width < 0.0 { + line_width = 0.0; + } + + (first_pad, line_width) + } + } + } +} + /// The appearance of a rule. #[derive(Debug, Clone, Copy)] pub struct Style { @@ -26,7 +73,7 @@ pub struct Style { pub color: Color, /// The width (thickness) of the rule line. pub width: u16, - /// The radius of the rectangle corners. + /// The radius of the line corners. pub radius: u16, /// The [`FillMode`] of the rule. /// |