diff options
author | 2021-09-20 15:09:55 +0700 | |
---|---|---|
committer | 2021-09-20 15:14:08 +0700 | |
commit | a0ad3996225601aaa1ebe051cba115374b55c80e (patch) | |
tree | 8420a91cd319a63b1ed257a6334453a1a673bdfb /native/src/layout | |
parent | 5fae6e59ffbc5913761df638dc7f0c35b7f43bc9 (diff) | |
download | iced-a0ad3996225601aaa1ebe051cba115374b55c80e.tar.gz iced-a0ad3996225601aaa1ebe051cba115374b55c80e.tar.bz2 iced-a0ad3996225601aaa1ebe051cba115374b55c80e.zip |
Refactor alignment types into an `alignment` module
Diffstat (limited to 'native/src/layout')
-rw-r--r-- | native/src/layout/flex.rs | 27 | ||||
-rw-r--r-- | native/src/layout/node.rs | 22 |
2 files changed, 23 insertions, 26 deletions
diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs index dfb5288b..5fbcbca0 100644 --- a/native/src/layout/flex.rs +++ b/native/src/layout/flex.rs @@ -16,11 +16,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - -use crate::{ - layout::{Limits, Node}, - CrossAlign, Element, Padding, Point, Size, -}; +use crate::layout::{Limits, Node}; +use crate::{Alignment, Element, Padding, Point, Size}; /// The main axis of a flex layout. #[derive(Debug)] @@ -65,7 +62,7 @@ pub fn resolve<Message, Renderer>( limits: &Limits, padding: Padding, spacing: f32, - align_items: CrossAlign, + align_items: Alignment, items: &[Element<'_, Message, Renderer>], ) -> Node where @@ -82,7 +79,7 @@ where let mut nodes: Vec<Node> = Vec::with_capacity(items.len()); nodes.resize(items.len(), Node::default()); - if align_items == CrossAlign::Fill { + if align_items == Alignment::Fill { let mut fill_cross = axis.cross(limits.min()); items.iter().for_each(|child| { @@ -116,13 +113,13 @@ where .fill_factor(); if fill_factor == 0 { - let (min_width, min_height) = if align_items == CrossAlign::Fill { + let (min_width, min_height) = if align_items == Alignment::Fill { axis.pack(0.0, cross) } else { axis.pack(0.0, 0.0) }; - let (max_width, max_height) = if align_items == CrossAlign::Fill { + let (max_width, max_height) = if align_items == Alignment::Fill { axis.pack(available, cross) } else { axis.pack(available, max_cross) @@ -138,7 +135,7 @@ where available -= axis.main(size); - if align_items != CrossAlign::Fill { + if align_items != Alignment::Fill { cross = cross.max(axis.cross(size)); } @@ -165,13 +162,13 @@ where max_main }; - let (min_width, min_height) = if align_items == CrossAlign::Fill { + let (min_width, min_height) = if align_items == Alignment::Fill { axis.pack(min_main, cross) } else { axis.pack(min_main, axis.cross(limits.min())) }; - let (max_width, max_height) = if align_items == CrossAlign::Fill { + let (max_width, max_height) = if align_items == Alignment::Fill { axis.pack(max_main, cross) } else { axis.pack(max_main, max_cross) @@ -184,7 +181,7 @@ where let layout = child.layout(renderer, &child_limits); - if align_items != CrossAlign::Fill { + if align_items != Alignment::Fill { cross = cross.max(axis.cross(layout.size())); } @@ -207,7 +204,7 @@ where match axis { Axis::Horizontal => { node.align( - CrossAlign::Start, + Alignment::Start, align_items, Size::new(0.0, cross), ); @@ -215,7 +212,7 @@ where Axis::Vertical => { node.align( align_items, - CrossAlign::Start, + Alignment::Start, Size::new(cross, 0.0), ); } diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs index 2239a654..e9e6058e 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -1,4 +1,4 @@ -use crate::{CrossAlign, Point, Rectangle, Size}; +use crate::{Alignment, Point, Rectangle, Size}; /// The bounds of an element and its children. #[derive(Debug, Clone, Default)] @@ -44,32 +44,32 @@ impl Node { /// Aligns the [`Node`] in the given space. pub fn align( &mut self, - horizontal_alignment: CrossAlign, - vertical_alignment: CrossAlign, + horizontal_alignment: Alignment, + vertical_alignment: Alignment, space: Size, ) { match horizontal_alignment { - CrossAlign::Start => {} - CrossAlign::Center => { + Alignment::Start => {} + Alignment::Center => { self.bounds.x += (space.width - self.bounds.width) / 2.0; } - CrossAlign::End => { + Alignment::End => { self.bounds.x += space.width - self.bounds.width; } - CrossAlign::Fill => { + Alignment::Fill => { self.bounds.width = space.width; } } match vertical_alignment { - CrossAlign::Start => {} - CrossAlign::Center => { + Alignment::Start => {} + Alignment::Center => { self.bounds.y += (space.height - self.bounds.height) / 2.0; } - CrossAlign::End => { + Alignment::End => { self.bounds.y += space.height - self.bounds.height; } - CrossAlign::Fill => { + Alignment::Fill => { self.bounds.height = space.height; } } |