summaryrefslogtreecommitdiffstats
path: root/examples/geometry
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-07-27 06:49:20 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-07-27 06:49:20 +0200
commitff2519b1d43d481987351a83b6dd7237524c21f0 (patch)
tree5731eeb7eb1247d4a8951de0d5bc5d8102640559 /examples/geometry
parentc44267b85f7aaa2997e3caf1323b837d95818c22 (diff)
downloadiced-ff2519b1d43d481987351a83b6dd7237524c21f0.tar.gz
iced-ff2519b1d43d481987351a83b6dd7237524c21f0.tar.bz2
iced-ff2519b1d43d481987351a83b6dd7237524c21f0.zip
Replace stateful widgets with new `iced_pure` API
Diffstat (limited to 'examples/geometry')
-rw-r--r--examples/geometry/src/main.rs57
1 files changed, 26 insertions, 31 deletions
diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs
index 03eac69e..d8b99ab3 100644
--- a/examples/geometry/src/main.rs
+++ b/examples/geometry/src/main.rs
@@ -13,8 +13,9 @@ mod rainbow {
use iced_graphics::renderer::{self, Renderer};
use iced_graphics::{Backend, Primitive};
+ use iced_native::widget::{self, Widget};
use iced_native::{
- layout, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
+ layout, Element, Layout, Length, Point, Rectangle, Size, Vector,
};
#[derive(Default)]
@@ -26,6 +27,10 @@ mod rainbow {
}
}
+ pub fn rainbow() -> Rainbow {
+ Rainbow
+ }
+
impl<Message, B, T> Widget<Message, Renderer<B, T>> for Rainbow
where
B: Backend,
@@ -50,6 +55,7 @@ mod rainbow {
fn draw(
&self,
+ _tree: &widget::Tree,
renderer: &mut Renderer<B, T>,
_theme: &T,
_style: &renderer::Style,
@@ -159,27 +165,21 @@ mod rainbow {
}
}
-use iced::{
- scrollable, Alignment, Column, Container, Element, Length, Sandbox,
- Scrollable, Settings, Text,
-};
-use rainbow::Rainbow;
+use iced::widget::{column, container, scrollable};
+use iced::{Alignment, Element, Length, Sandbox, Settings};
+use rainbow::rainbow;
pub fn main() -> iced::Result {
Example::run(Settings::default())
}
-struct Example {
- scroll: scrollable::State,
-}
+struct Example;
impl Sandbox for Example {
type Message = ();
fn new() -> Self {
- Example {
- scroll: scrollable::State::new(),
- }
+ Example
}
fn title(&self) -> String {
@@ -188,32 +188,27 @@ impl Sandbox for Example {
fn update(&mut self, _: ()) {}
- fn view(&mut self) -> Element<()> {
- let content = Column::new()
- .padding(20)
- .spacing(20)
- .max_width(500)
- .align_items(Alignment::Start)
- .push(Rainbow::new())
- .push(Text::new(
- "In this example we draw a custom widget Rainbow, using \
+ fn view(&self) -> Element<()> {
+ let content = column![
+ rainbow(),
+ "In this example we draw a custom widget Rainbow, using \
the Mesh2D primitive. This primitive supplies a list of \
triangles, expressed as vertices and indices.",
- ))
- .push(Text::new(
- "Move your cursor over it, and see the center vertex \
+ "Move your cursor over it, and see the center vertex \
follow you!",
- ))
- .push(Text::new(
- "Every Vertex2D defines its own color. You could use the \
+ "Every Vertex2D defines its own color. You could use the \
Mesh2D primitive to render virtually any two-dimensional \
geometry for your widget.",
- ));
+ ]
+ .padding(20)
+ .spacing(20)
+ .max_width(500)
+ .align_items(Alignment::Start);
- let scrollable = Scrollable::new(&mut self.scroll)
- .push(Container::new(content).width(Length::Fill).center_x());
+ let scrollable =
+ scrollable(container(content).width(Length::Fill).center_x());
- Container::new(scrollable)
+ container(scrollable)
.width(Length::Fill)
.height(Length::Fill)
.center_y()