diff options
author | 2020-11-23 17:19:21 +0000 | |
---|---|---|
committer | 2021-06-01 19:05:39 +0700 | |
commit | fe0a27c56d9d75fb521e69352259f1d737402a20 (patch) | |
tree | f7f77430b63983717036a81e734276123d139ca6 /native/src/layout | |
parent | a9eb591628017caaf7aa9af505d1206f7a143a9a (diff) | |
download | iced-fe0a27c56d9d75fb521e69352259f1d737402a20.tar.gz iced-fe0a27c56d9d75fb521e69352259f1d737402a20.tar.bz2 iced-fe0a27c56d9d75fb521e69352259f1d737402a20.zip |
Add support for asymmetrical padding
Diffstat (limited to 'native/src/layout')
-rw-r--r-- | native/src/layout/flex.rs | 12 | ||||
-rw-r--r-- | native/src/layout/limits.rs | 9 |
2 files changed, 13 insertions, 8 deletions
diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs index 4f6523fb..3d3ff82c 100644 --- a/native/src/layout/flex.rs +++ b/native/src/layout/flex.rs @@ -16,9 +16,10 @@ // 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}, - Align, Element, Point, Size, + Align, Element, Padding, Point, Size, }; /// The main axis of a flex layout. @@ -62,7 +63,7 @@ pub fn resolve<Message, Renderer>( axis: Axis, renderer: &Renderer, limits: &Limits, - padding: f32, + padding: Padding, spacing: f32, align_items: Align, items: &[Element<'_, Message, Renderer>], @@ -141,14 +142,15 @@ where } } - let mut main = padding; + let pad = axis.pack(padding.left as f32, padding.top as f32); + let mut main = pad.0; for (i, node) in nodes.iter_mut().enumerate() { if i > 0 { main += spacing; } - let (x, y) = axis.pack(main, padding); + let (x, y) = axis.pack(main, pad.1); node.move_to(Point::new(x, y)); @@ -166,7 +168,7 @@ where main += axis.main(size); } - let (width, height) = axis.pack(main - padding, cross); + let (width, height) = axis.pack(main - pad.0, cross); let size = limits.resolve(Size::new(width, height)); Node::with_children(size.pad(padding), nodes) diff --git a/native/src/layout/limits.rs b/native/src/layout/limits.rs index a7bb5c9c..0057e3ba 100644 --- a/native/src/layout/limits.rs +++ b/native/src/layout/limits.rs @@ -1,4 +1,4 @@ -use crate::{Length, Size}; +use crate::{Length, Padding, Size}; /// A set of size constraints for layouting. #[derive(Debug, Clone, Copy)] @@ -117,8 +117,11 @@ impl Limits { } /// Shrinks the current [`Limits`] to account for the given padding. - pub fn pad(&self, padding: f32) -> Limits { - self.shrink(Size::new(padding * 2.0, padding * 2.0)) + pub fn pad(&self, padding: Padding) -> Limits { + self.shrink(Size::new( + (padding.left + padding.right) as f32, + (padding.top + padding.bottom) as f32, + )) } /// Shrinks the current [`Limits`] by the given [`Size`]. |