diff options
author | 2020-08-16 19:20:02 -0500 | |
---|---|---|
committer | 2020-08-22 21:23:50 +0200 | |
commit | fed30ef7753bbe33af026f1f46a09d8381682284 (patch) | |
tree | 1f0d3b3a1f50fbdb982d2c2ce436bd5f49288c54 /graphics | |
parent | 32561bd85c6db0d7e6d9d12c87b87f4b50f1d43f (diff) | |
download | iced-fed30ef7753bbe33af026f1f46a09d8381682284.tar.gz iced-fed30ef7753bbe33af026f1f46a09d8381682284.tar.bz2 iced-fed30ef7753bbe33af026f1f46a09d8381682284.zip |
added FillMode::fill()
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/src/widget/rule.rs | 87 |
1 files changed, 4 insertions, 83 deletions
diff --git a/graphics/src/widget/rule.rs b/graphics/src/widget/rule.rs index e058dffe..a7a5d0e7 100644 --- a/graphics/src/widget/rule.rs +++ b/graphics/src/widget/rule.rs @@ -31,47 +31,8 @@ where - (style.width as f32 / 2.0)) .round(); - let (line_x, line_width) = match style.fill_mode { - FillMode::Full => (bounds.x, bounds.width), - FillMode::Percent(percent) => { - if percent >= 100.0 { - (bounds.x, bounds.width) - } else { - let percent_width = - (bounds.width * percent / 100.0).round(); - - ( - bounds.x - + ((bounds.width - percent_width) / 2.0) - .round(), - percent_width, - ) - } - } - FillMode::Padded(padding) => { - if padding == 0 { - (bounds.x, bounds.width) - } else { - let padding = padding as f32; - let mut line_width = bounds.width - (padding * 2.0); - if line_width < 0.0 { - line_width = 0.0; - } - - (bounds.x + 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 = bounds.width - first_pad - second_pad; - if line_width < 0.0 { - line_width = 0.0; - } - - (bounds.x + first_pad, line_width) - } - }; + let (offset, line_width) = style.fill_mode.fill(bounds.width); + let line_x = bounds.x + offset; Primitive::Quad { bounds: Rectangle { @@ -90,48 +51,8 @@ where - (style.width as f32 / 2.0)) .round(); - let (line_y, line_height) = match style.fill_mode { - FillMode::Full => (bounds.y, bounds.height), - FillMode::Percent(percent) => { - if percent >= 100.0 { - (bounds.y, bounds.height) - } else { - let percent_height = - (bounds.height * percent / 100.0).round(); - - ( - bounds.y - + ((bounds.height - percent_height) / 2.0) - .round(), - percent_height, - ) - } - } - FillMode::Padded(padding) => { - if padding == 0 { - (bounds.y, bounds.height) - } else { - let padding = padding as f32; - let mut line_height = bounds.height - (padding * 2.0); - if line_height < 0.0 { - line_height = 0.0; - } - - (bounds.y + padding, line_height) - } - } - FillMode::AsymmetricPadding(first_pad, second_pad) => { - let first_pad = first_pad as f32; - let second_pad = second_pad as f32; - let mut line_height = - bounds.height - first_pad - second_pad; - if line_height < 0.0 { - line_height = 0.0; - } - - (bounds.y + first_pad, line_height) - } - }; + let (offset, line_height) = style.fill_mode.fill(bounds.height); + let line_y = bounds.y + offset; Primitive::Quad { bounds: Rectangle { |