Revert changing the constructor and implement new method.

This commit is contained in:
daxpedda 2020-02-14 21:41:35 +01:00
parent 60b40fdc99
commit f4b8bce837
No known key found for this signature in database
GPG Key ID: 43D62A3EA388E46F
16 changed files with 39 additions and 44 deletions

View File

@ -84,7 +84,7 @@ mod bezier {
.height(Length::Fill)
.width(Length::Fill)
.resolve(Size::ZERO);
layout::Node::new(size, Size::ZERO)
layout::Node::new(size)
}
fn draw(

View File

@ -39,13 +39,10 @@ mod circle {
_renderer: &Renderer,
_limits: &layout::Limits,
) -> layout::Node {
layout::Node::new(
Size::new(
f32::from(self.radius) * 2.0,
f32::from(self.radius) * 2.0,
),
Size::ZERO,
)
layout::Node::new(Size::new(
f32::from(self.radius) * 2.0,
f32::from(self.radius) * 2.0,
))
}
fn hash_layout(&self, state: &mut Hasher) {

View File

@ -43,7 +43,7 @@ mod rainbow {
) -> layout::Node {
let size = limits.width(Length::Fill).resolve(Size::ZERO);
layout::Node::new(Size::new(size.width, size.width), Size::ZERO)
layout::Node::new(Size::new(size.width, size.width))
}
fn hash_layout(&self, _state: &mut Hasher) {}

View File

@ -18,7 +18,7 @@
// limitations under the License.
use crate::{
layout::{Limits, Node},
Align, Element, Size,
Align, Element, Point, Size,
};
/// The main axis of a flex layout.
@ -152,8 +152,7 @@ where
let (x, y) = axis.pack(main, padding);
node.bounds.x = x;
node.bounds.y = y;
node.move_to(Point::new(x, y));
match axis {
Axis::Horizontal => {
@ -174,7 +173,6 @@ where
Node::with_children(
Size::new(size.width + padding * 2.0, size.height + padding * 2.0),
Size::ZERO,
nodes,
)
}

View File

@ -1,9 +1,9 @@
use crate::{Align, Rectangle, Size};
use crate::{Align, Point, Rectangle, Size};
/// The bounds of an element and its children.
#[derive(Debug, Clone, Default)]
pub struct Node {
pub(crate) bounds: Rectangle,
bounds: Rectangle,
children: Vec<Node>,
}
@ -12,19 +12,19 @@ impl Node {
///
/// [`Node`]: struct.Node.html
/// [`Size`]: ../struct.Size.html
pub fn new(size: Size, bound: Size) -> Self {
Self::with_children(size, bound, Vec::new())
pub fn new(size: Size) -> Self {
Self::with_children(size, 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, bound: Size, children: Vec<Node>) -> Self {
pub fn with_children(size: Size, children: Vec<Node>) -> Self {
Node {
bounds: Rectangle {
x: bound.width,
y: bound.height,
x: 0.0,
y: 0.0,
width: size.width,
height: size.height,
},
@ -84,4 +84,12 @@ impl Node {
}
}
}
/// Move item to [`Point`].
///
/// [`Point`]: ../struct.Point.html
pub fn move_to(&mut self, position: Point) {
self.bounds.x = position.x;
self.bounds.y = position.y;
}
}

View File

@ -307,7 +307,7 @@ impl Cache {
pub fn new() -> Cache {
Cache {
hash: 0,
layout: layout::Node::new(Size::ZERO, Size::ZERO),
layout: layout::Node::new(Size::new(0.0, 0.0)),
bounds: Size::ZERO,
cursor_position: Point::new(-1.0, -1.0),
}

View File

@ -7,7 +7,7 @@
use crate::{
input::{mouse, ButtonState},
layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Rectangle, Size, Widget,
Rectangle, Widget,
};
use std::hash::Hash;
@ -168,13 +168,11 @@ where
.pad(padding);
let mut content = self.content.layout(renderer, &limits);
content.bounds.x = padding;
content.bounds.y = padding;
content.move_to(Point::new(padding, padding));
let size = limits.resolve(content.size()).pad(padding);
layout::Node::with_children(size, Size::ZERO, vec![content])
layout::Node::with_children(size, vec![content])
}
fn on_event(

View File

@ -2,7 +2,7 @@
use std::hash::Hash;
use crate::{
layout, Align, Clipboard, Size, Element, Event, Hasher, Layout, Length, Point,
layout, Align, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Rectangle, Widget,
};
@ -148,7 +148,7 @@ where
content.align(self.horizontal_alignment, self.vertical_alignment, size);
layout::Node::with_children(size, Size::ZERO, vec![content])
layout::Node::with_children(size, vec![content])
}
fn on_event(

View File

@ -88,7 +88,7 @@ where
size.height = height as f32 * size.width / width as f32;
}
layout::Node::new(size, Size::ZERO)
layout::Node::new(size)
}
fn draw(

View File

@ -95,7 +95,7 @@ where
let size = limits.resolve(Size::ZERO);
layout::Node::new(size, Size::ZERO)
layout::Node::new(size)
}
fn draw(

View File

@ -143,7 +143,7 @@ where
let content = self.content.layout(renderer, &child_limits);
let size = limits.resolve(content.size());
layout::Node::with_children(size, Size::ZERO, vec![content])
layout::Node::with_children(size, vec![content])
}
fn on_event(

View File

@ -135,7 +135,7 @@ where
let size = limits.resolve(Size::ZERO);
layout::Node::new(size, Size::ZERO)
layout::Node::new(size)
}
fn on_event(

View File

@ -62,7 +62,7 @@ where
) -> layout::Node {
let limits = limits.width(self.width).height(self.height);
layout::Node::new(limits.resolve(Size::ZERO), Size::ZERO)
layout::Node::new(limits.resolve(Size::ZERO))
}
fn draw(

View File

@ -85,7 +85,7 @@ where
size.height = height as f32 * size.width / width as f32;
}
layout::Node::new(size, Size::ZERO)
layout::Node::new(size)
}
fn draw(

View File

@ -140,7 +140,7 @@ where
let size = limits.resolve(Size::new(width, height));
layout::Node::new(size, Size::ZERO)
layout::Node::new(size)
}
fn draw(

View File

@ -183,16 +183,10 @@ where
.max_width(self.max_width)
.height(Length::Units(text_size));
let mut text =
layout::Node::new(limits.resolve(Size::ZERO), Size::ZERO);
text.bounds.x = padding;
text.bounds.y = padding;
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
text.move_to(Point::new(padding, padding));
layout::Node::with_children(
text.size().pad(padding),
Size::ZERO,
vec![text],
)
layout::Node::with_children(text.size().pad(padding), vec![text])
}
fn on_event(