Revert changing the constructor and implement new method.
This commit is contained in:
parent
60b40fdc99
commit
f4b8bce837
16 changed files with 39 additions and 44 deletions
|
|
@ -84,7 +84,7 @@ mod bezier {
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.resolve(Size::ZERO);
|
.resolve(Size::ZERO);
|
||||||
layout::Node::new(size, Size::ZERO)
|
layout::Node::new(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,10 @@ mod circle {
|
||||||
_renderer: &Renderer,
|
_renderer: &Renderer,
|
||||||
_limits: &layout::Limits,
|
_limits: &layout::Limits,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
layout::Node::new(
|
layout::Node::new(Size::new(
|
||||||
Size::new(
|
f32::from(self.radius) * 2.0,
|
||||||
f32::from(self.radius) * 2.0,
|
f32::from(self.radius) * 2.0,
|
||||||
f32::from(self.radius) * 2.0,
|
))
|
||||||
),
|
|
||||||
Size::ZERO,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_layout(&self, state: &mut Hasher) {
|
fn hash_layout(&self, state: &mut Hasher) {
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ mod rainbow {
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let size = limits.width(Length::Fill).resolve(Size::ZERO);
|
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) {}
|
fn hash_layout(&self, _state: &mut Hasher) {}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use crate::{
|
use crate::{
|
||||||
layout::{Limits, Node},
|
layout::{Limits, Node},
|
||||||
Align, Element, Size,
|
Align, Element, Point, Size,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The main axis of a flex layout.
|
/// The main axis of a flex layout.
|
||||||
|
|
@ -152,8 +152,7 @@ where
|
||||||
|
|
||||||
let (x, y) = axis.pack(main, padding);
|
let (x, y) = axis.pack(main, padding);
|
||||||
|
|
||||||
node.bounds.x = x;
|
node.move_to(Point::new(x, y));
|
||||||
node.bounds.y = y;
|
|
||||||
|
|
||||||
match axis {
|
match axis {
|
||||||
Axis::Horizontal => {
|
Axis::Horizontal => {
|
||||||
|
|
@ -174,7 +173,6 @@ where
|
||||||
|
|
||||||
Node::with_children(
|
Node::with_children(
|
||||||
Size::new(size.width + padding * 2.0, size.height + padding * 2.0),
|
Size::new(size.width + padding * 2.0, size.height + padding * 2.0),
|
||||||
Size::ZERO,
|
|
||||||
nodes,
|
nodes,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::{Align, Rectangle, Size};
|
use crate::{Align, Point, Rectangle, Size};
|
||||||
|
|
||||||
/// The bounds of an element and its children.
|
/// The bounds of an element and its children.
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
pub(crate) bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
children: Vec<Node>,
|
children: Vec<Node>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -12,19 +12,19 @@ impl Node {
|
||||||
///
|
///
|
||||||
/// [`Node`]: struct.Node.html
|
/// [`Node`]: struct.Node.html
|
||||||
/// [`Size`]: ../struct.Size.html
|
/// [`Size`]: ../struct.Size.html
|
||||||
pub fn new(size: Size, bound: Size) -> Self {
|
pub fn new(size: Size) -> Self {
|
||||||
Self::with_children(size, bound, Vec::new())
|
Self::with_children(size, Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`Node`] with the given [`Size`] and children.
|
/// Creates a new [`Node`] with the given [`Size`] and children.
|
||||||
///
|
///
|
||||||
/// [`Node`]: struct.Node.html
|
/// [`Node`]: struct.Node.html
|
||||||
/// [`Size`]: ../struct.Size.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 {
|
Node {
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: bound.width,
|
x: 0.0,
|
||||||
y: bound.height,
|
y: 0.0,
|
||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height,
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -307,7 +307,7 @@ impl Cache {
|
||||||
pub fn new() -> Cache {
|
pub fn new() -> Cache {
|
||||||
Cache {
|
Cache {
|
||||||
hash: 0,
|
hash: 0,
|
||||||
layout: layout::Node::new(Size::ZERO, Size::ZERO),
|
layout: layout::Node::new(Size::new(0.0, 0.0)),
|
||||||
bounds: Size::ZERO,
|
bounds: Size::ZERO,
|
||||||
cursor_position: Point::new(-1.0, -1.0),
|
cursor_position: Point::new(-1.0, -1.0),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
input::{mouse, ButtonState},
|
input::{mouse, ButtonState},
|
||||||
layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||||
Rectangle, Size, Widget,
|
Rectangle, Widget,
|
||||||
};
|
};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
|
@ -168,13 +168,11 @@ where
|
||||||
.pad(padding);
|
.pad(padding);
|
||||||
|
|
||||||
let mut content = self.content.layout(renderer, &limits);
|
let mut content = self.content.layout(renderer, &limits);
|
||||||
|
content.move_to(Point::new(padding, padding));
|
||||||
content.bounds.x = padding;
|
|
||||||
content.bounds.y = padding;
|
|
||||||
|
|
||||||
let size = limits.resolve(content.size()).pad(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(
|
fn on_event(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
layout, Align, Clipboard, Size, Element, Event, Hasher, Layout, Length, Point,
|
layout, Align, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||||
Rectangle, Widget,
|
Rectangle, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -148,7 +148,7 @@ where
|
||||||
|
|
||||||
content.align(self.horizontal_alignment, self.vertical_alignment, size);
|
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(
|
fn on_event(
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ where
|
||||||
size.height = height as f32 * size.width / width as f32;
|
size.height = height as f32 * size.width / width as f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
layout::Node::new(size, Size::ZERO)
|
layout::Node::new(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ where
|
||||||
|
|
||||||
let size = limits.resolve(Size::ZERO);
|
let size = limits.resolve(Size::ZERO);
|
||||||
|
|
||||||
layout::Node::new(size, Size::ZERO)
|
layout::Node::new(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ where
|
||||||
let content = self.content.layout(renderer, &child_limits);
|
let content = self.content.layout(renderer, &child_limits);
|
||||||
let size = limits.resolve(content.size());
|
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(
|
fn on_event(
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ where
|
||||||
|
|
||||||
let size = limits.resolve(Size::ZERO);
|
let size = limits.resolve(Size::ZERO);
|
||||||
|
|
||||||
layout::Node::new(size, Size::ZERO)
|
layout::Node::new(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(
|
fn on_event(
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ where
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let limits = limits.width(self.width).height(self.height);
|
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(
|
fn draw(
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ where
|
||||||
size.height = height as f32 * size.width / width as f32;
|
size.height = height as f32 * size.width / width as f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
layout::Node::new(size, Size::ZERO)
|
layout::Node::new(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ where
|
||||||
|
|
||||||
let size = limits.resolve(Size::new(width, height));
|
let size = limits.resolve(Size::new(width, height));
|
||||||
|
|
||||||
layout::Node::new(size, Size::ZERO)
|
layout::Node::new(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|
|
||||||
|
|
@ -183,16 +183,10 @@ where
|
||||||
.max_width(self.max_width)
|
.max_width(self.max_width)
|
||||||
.height(Length::Units(text_size));
|
.height(Length::Units(text_size));
|
||||||
|
|
||||||
let mut text =
|
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
|
||||||
layout::Node::new(limits.resolve(Size::ZERO), Size::ZERO);
|
text.move_to(Point::new(padding, padding));
|
||||||
text.bounds.x = padding;
|
|
||||||
text.bounds.y = padding;
|
|
||||||
|
|
||||||
layout::Node::with_children(
|
layout::Node::with_children(text.size().pad(padding), vec![text])
|
||||||
text.size().pad(padding),
|
|
||||||
Size::ZERO,
|
|
||||||
vec![text],
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(
|
fn on_event(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue