Add bound to Node constructor.
This commit is contained in:
parent
457d6f616a
commit
b72bd0b2b5
@ -174,6 +174,7 @@ where
|
||||
|
||||
Node::with_children(
|
||||
Size::new(size.width + padding * 2.0, size.height + padding * 2.0),
|
||||
Size::ZERO,
|
||||
nodes,
|
||||
)
|
||||
}
|
||||
|
||||
@ -12,19 +12,19 @@ impl Node {
|
||||
///
|
||||
/// [`Node`]: struct.Node.html
|
||||
/// [`Size`]: ../struct.Size.html
|
||||
pub fn new(size: Size) -> Self {
|
||||
Self::with_children(size, Vec::new())
|
||||
pub fn new(size: Size, bound: Size) -> Self {
|
||||
Self::with_children(size, bound, Vec::new())
|
||||
}
|
||||
|
||||
/// Creates a new [`Node`] with the given [`Size`] and children.
|
||||
///
|
||||
/// [`Node`]: struct.Node.html
|
||||
/// [`Size`]: ../struct.Size.html
|
||||
pub fn with_children(size: Size, children: Vec<Node>) -> Self {
|
||||
pub fn with_children(size: Size, bound: Size, children: Vec<Node>) -> Self {
|
||||
Node {
|
||||
bounds: Rectangle {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
x: bound.width,
|
||||
y: bound.height,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
},
|
||||
|
||||
@ -307,7 +307,7 @@ impl Cache {
|
||||
pub fn new() -> Cache {
|
||||
Cache {
|
||||
hash: 0,
|
||||
layout: layout::Node::new(Size::new(0.0, 0.0)),
|
||||
layout: layout::Node::new(Size::ZERO, Size::ZERO),
|
||||
bounds: Size::ZERO,
|
||||
cursor_position: Point::new(-1.0, -1.0),
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
use crate::{
|
||||
input::{mouse, ButtonState},
|
||||
layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||
Rectangle, Widget,
|
||||
Rectangle, Size, Widget,
|
||||
};
|
||||
use std::hash::Hash;
|
||||
|
||||
@ -174,7 +174,7 @@ where
|
||||
|
||||
let size = limits.resolve(content.size()).pad(padding);
|
||||
|
||||
layout::Node::with_children(size, vec![content])
|
||||
layout::Node::with_children(size, Size::ZERO, vec![content])
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::{
|
||||
layout, Align, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||
layout, Align, Clipboard, Size, Element, Event, Hasher, Layout, Length, Point,
|
||||
Rectangle, Widget,
|
||||
};
|
||||
|
||||
@ -77,7 +77,6 @@ where
|
||||
self.max_height = max_height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the content alignment for the horizontal axis of the [`Container`].
|
||||
///
|
||||
/// [`Container`]: struct.Container.html
|
||||
@ -149,7 +148,7 @@ where
|
||||
|
||||
content.align(self.horizontal_alignment, self.vertical_alignment, size);
|
||||
|
||||
layout::Node::with_children(size, vec![content])
|
||||
layout::Node::with_children(size, Size::ZERO, vec![content])
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
|
||||
@ -88,7 +88,7 @@ where
|
||||
size.height = height as f32 * size.width / width as f32;
|
||||
}
|
||||
|
||||
layout::Node::new(size)
|
||||
layout::Node::new(size, Size::ZERO)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
||||
@ -95,7 +95,7 @@ where
|
||||
|
||||
let size = limits.resolve(Size::ZERO);
|
||||
|
||||
layout::Node::new(size)
|
||||
layout::Node::new(size, Size::ZERO)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
||||
@ -143,7 +143,7 @@ where
|
||||
let content = self.content.layout(renderer, &child_limits);
|
||||
let size = limits.resolve(content.size());
|
||||
|
||||
layout::Node::with_children(size, vec![content])
|
||||
layout::Node::with_children(size, Size::ZERO, vec![content])
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
|
||||
@ -135,7 +135,7 @@ where
|
||||
|
||||
let size = limits.resolve(Size::ZERO);
|
||||
|
||||
layout::Node::new(size)
|
||||
layout::Node::new(size, Size::ZERO)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
|
||||
@ -62,7 +62,7 @@ where
|
||||
) -> layout::Node {
|
||||
let limits = limits.width(self.width).height(self.height);
|
||||
|
||||
layout::Node::new(limits.resolve(Size::ZERO))
|
||||
layout::Node::new(limits.resolve(Size::ZERO), Size::ZERO)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
||||
@ -85,7 +85,7 @@ where
|
||||
size.height = height as f32 * size.width / width as f32;
|
||||
}
|
||||
|
||||
layout::Node::new(size)
|
||||
layout::Node::new(size, Size::ZERO)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
||||
@ -140,7 +140,7 @@ where
|
||||
|
||||
let size = limits.resolve(Size::new(width, height));
|
||||
|
||||
layout::Node::new(size)
|
||||
layout::Node::new(size, Size::ZERO)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
||||
@ -183,11 +183,16 @@ where
|
||||
.max_width(self.max_width)
|
||||
.height(Length::Units(text_size));
|
||||
|
||||
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
|
||||
let mut text =
|
||||
layout::Node::new(limits.resolve(Size::ZERO), Size::ZERO);
|
||||
text.bounds.x = padding;
|
||||
text.bounds.y = padding;
|
||||
|
||||
layout::Node::with_children(text.size().pad(padding), vec![text])
|
||||
layout::Node::with_children(
|
||||
text.size().pad(padding),
|
||||
Size::ZERO,
|
||||
vec![text],
|
||||
)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user