Add bound to Node constructor.
This commit is contained in:
parent
457d6f616a
commit
b72bd0b2b5
@ -174,6 +174,7 @@ 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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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) -> Self {
|
pub fn new(size: Size, bound: Size) -> Self {
|
||||||
Self::with_children(size, Vec::new())
|
Self::with_children(size, bound, 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, children: Vec<Node>) -> Self {
|
pub fn with_children(size: Size, bound: Size, children: Vec<Node>) -> Self {
|
||||||
Node {
|
Node {
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: 0.0,
|
x: bound.width,
|
||||||
y: 0.0,
|
y: bound.height,
|
||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height,
|
height: size.height,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -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::new(0.0, 0.0)),
|
layout: layout::Node::new(Size::ZERO, Size::ZERO),
|
||||||
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, Widget,
|
Rectangle, Size, Widget,
|
||||||
};
|
};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ where
|
|||||||
|
|
||||||
let size = limits.resolve(content.size()).pad(padding);
|
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(
|
fn on_event(
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
layout, Align, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
layout, Align, Clipboard, Size, Element, Event, Hasher, Layout, Length, Point,
|
||||||
Rectangle, Widget,
|
Rectangle, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,7 +77,6 @@ where
|
|||||||
self.max_height = max_height;
|
self.max_height = max_height;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the content alignment for the horizontal axis of the [`Container`].
|
/// Sets the content alignment for the horizontal axis of the [`Container`].
|
||||||
///
|
///
|
||||||
/// [`Container`]: struct.Container.html
|
/// [`Container`]: struct.Container.html
|
||||||
@ -149,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, vec![content])
|
layout::Node::with_children(size, Size::ZERO, 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)
|
layout::Node::new(size, Size::ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
layout::Node::new(size, Size::ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
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, vec![content])
|
layout::Node::with_children(size, Size::ZERO, 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)
|
layout::Node::new(size, Size::ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
layout::Node::new(limits.resolve(Size::ZERO), 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)
|
layout::Node::new(size, Size::ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
layout::Node::new(size, Size::ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|||||||
@ -183,11 +183,16 @@ where
|
|||||||
.max_width(self.max_width)
|
.max_width(self.max_width)
|
||||||
.height(Length::Units(text_size));
|
.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.x = padding;
|
||||||
text.bounds.y = 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(
|
fn on_event(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user