summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/arc/src/main.rs4
-rw-r--r--examples/bezier_tool/src/main.rs7
-rw-r--r--examples/clock/src/main.rs4
-rw-r--r--examples/editor/src/main.rs6
-rw-r--r--examples/game_of_life/src/main.rs7
-rw-r--r--examples/geometry/src/main.rs8
-rw-r--r--examples/integration/src/controls.rs11
-rw-r--r--examples/layout/src/main.rs11
-rw-r--r--examples/multi_window/src/main.rs4
-rw-r--r--examples/pane_grid/src/main.rs13
-rw-r--r--examples/progress_bar/src/main.rs42
-rw-r--r--examples/screenshot/src/main.rs10
-rw-r--r--examples/stopwatch/src/main.rs6
-rw-r--r--examples/svg/src/main.rs12
-rw-r--r--examples/the_matrix/src/main.rs4
-rw-r--r--examples/toast/src/main.rs7
-rw-r--r--examples/todos/src/main.rs4
-rw-r--r--examples/tour/src/main.rs22
18 files changed, 99 insertions, 83 deletions
diff --git a/examples/arc/src/main.rs b/examples/arc/src/main.rs
index 18873259..88544caa 100644
--- a/examples/arc/src/main.rs
+++ b/examples/arc/src/main.rs
@@ -4,6 +4,7 @@ use iced::mouse;
use iced::widget::canvas::{
self, stroke, Cache, Canvas, Geometry, Path, Stroke,
};
+use iced::window;
use iced::{Element, Fill, Point, Rectangle, Renderer, Subscription, Theme};
pub fn main() -> iced::Result {
@@ -34,8 +35,7 @@ impl Arc {
}
fn subscription(&self) -> Subscription<Message> {
- iced::time::every(std::time::Duration::from_millis(10))
- .map(|_| Message::Tick)
+ window::frames().map(|_| Message::Tick)
}
}
diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs
index e8f0efc9..4d438bd9 100644
--- a/examples/bezier_tool/src/main.rs
+++ b/examples/bezier_tool/src/main.rs
@@ -1,6 +1,6 @@
//! This example showcases an interactive `Canvas` for drawing Bézier curves.
-use iced::widget::{button, container, horizontal_space, hover};
-use iced::{Element, Fill, Theme};
+use iced::widget::{button, container, horizontal_space, hover, right};
+use iced::{Element, Theme};
pub fn main() -> iced::Result {
iced::application("Bezier Tool - Iced", Example::update, Example::view)
@@ -41,13 +41,12 @@ impl Example {
if self.curves.is_empty() {
container(horizontal_space())
} else {
- container(
+ right(
button("Clear")
.style(button::danger)
.on_press(Message::Clear),
)
.padding(10)
- .align_right(Fill)
},
))
.padding(20)
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index 7d11a3b5..0810594f 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -1,5 +1,5 @@
use iced::mouse;
-use iced::time;
+use iced::time::{self, milliseconds};
use iced::widget::canvas::{stroke, Cache, Geometry, LineCap, Path, Stroke};
use iced::widget::{canvas, container};
use iced::{alignment, Radians};
@@ -49,7 +49,7 @@ impl Clock {
}
fn subscription(&self) -> Subscription<Message> {
- time::every(time::Duration::from_millis(500))
+ time::every(milliseconds(500))
.map(|_| Message::Tick(chrono::offset::Local::now()))
}
diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs
index d55f9bdf..7032324a 100644
--- a/examples/editor/src/main.rs
+++ b/examples/editor/src/main.rs
@@ -1,8 +1,8 @@
use iced::highlighter;
use iced::keyboard;
use iced::widget::{
- self, button, column, container, horizontal_space, pick_list, row, text,
- text_editor, toggler, tooltip,
+ self, button, center_x, column, container, horizontal_space, pick_list,
+ row, text, text_editor, toggler, tooltip,
};
use iced::{Center, Element, Fill, Font, Task, Theme};
@@ -288,7 +288,7 @@ fn action<'a, Message: Clone + 'a>(
label: &'a str,
on_press: Option<Message>,
) -> Element<'a, Message> {
- let action = button(container(content).center_x(30));
+ let action = button(center_x(content).width(30));
if let Some(on_press) = on_press {
tooltip(
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index 7a7224d5..1008e477 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -5,12 +5,11 @@ mod preset;
use grid::Grid;
use preset::Preset;
-use iced::time;
+use iced::time::{self, milliseconds};
use iced::widget::{
button, checkbox, column, container, pick_list, row, slider, text,
};
use iced::{Center, Element, Fill, Subscription, Task, Theme};
-use std::time::Duration;
pub fn main() -> iced::Result {
tracing_subscriber::fmt::init();
@@ -112,7 +111,7 @@ impl GameOfLife {
fn subscription(&self) -> Subscription<Message> {
if self.is_playing {
- time::every(Duration::from_millis(1000 / self.speed as u64))
+ time::every(milliseconds(1000 / self.speed as u64))
.map(|_| Message::Tick)
} else {
Subscription::none()
@@ -191,6 +190,7 @@ mod grid {
use crate::Preset;
use iced::alignment;
use iced::mouse;
+ use iced::time::{Duration, Instant};
use iced::touch;
use iced::widget::canvas;
use iced::widget::canvas::{
@@ -202,7 +202,6 @@ mod grid {
use rustc_hash::{FxHashMap, FxHashSet};
use std::future::Future;
use std::ops::RangeInclusive;
- use std::time::{Duration, Instant};
pub struct Grid {
state: State,
diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs
index d53ae6a5..44214c63 100644
--- a/examples/geometry/src/main.rs
+++ b/examples/geometry/src/main.rs
@@ -152,8 +152,8 @@ mod rainbow {
}
}
-use iced::widget::{column, container, scrollable};
-use iced::{Element, Length};
+use iced::widget::{center_x, center_y, column, scrollable};
+use iced::Element;
use rainbow::rainbow;
pub fn main() -> iced::Result {
@@ -176,7 +176,7 @@ fn view(_state: &()) -> Element<'_, ()> {
.spacing(20)
.max_width(500);
- let scrollable = scrollable(container(content).center_x(Length::Fill));
+ let scrollable = scrollable(center_x(content));
- container(scrollable).center_y(Length::Fill).into()
+ center_y(scrollable).into()
}
diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs
index 0b11a323..b92e4987 100644
--- a/examples/integration/src/controls.rs
+++ b/examples/integration/src/controls.rs
@@ -1,6 +1,6 @@
use iced_wgpu::Renderer;
-use iced_widget::{column, container, row, slider, text, text_input};
-use iced_winit::core::{Color, Element, Length::*, Theme};
+use iced_widget::{bottom, column, row, slider, text, text_input};
+use iced_winit::core::{Color, Element, Theme};
use iced_winit::runtime::{Program, Task};
pub struct Controls {
@@ -74,18 +74,17 @@ impl Program for Controls {
.width(500)
.spacing(20);
- container(
+ bottom(
column![
text("Background color").color(Color::WHITE),
text!("{background_color:?}").size(14).color(Color::WHITE),
- text_input("Placeholder", &self.input)
- .on_input(Message::InputChanged),
sliders,
+ text_input("Type something...", &self.input)
+ .on_input(Message::InputChanged),
]
.spacing(10),
)
.padding(10)
- .align_bottom(Fill)
.into()
}
}
diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs
index e83a1f7d..b298dce4 100644
--- a/examples/layout/src/main.rs
+++ b/examples/layout/src/main.rs
@@ -2,9 +2,9 @@ use iced::border;
use iced::keyboard;
use iced::mouse;
use iced::widget::{
- button, canvas, center, checkbox, column, container, horizontal_rule,
- horizontal_space, pick_list, pin, row, scrollable, stack, text,
- vertical_rule,
+ button, canvas, center, center_y, checkbox, column, container,
+ horizontal_rule, horizontal_space, pick_list, pin, row, scrollable, stack,
+ text, vertical_rule,
};
use iced::{
color, Center, Element, Fill, Font, Length, Point, Rectangle, Renderer,
@@ -253,15 +253,14 @@ fn application<'a>() -> Element<'a, Message> {
.border(border::color(palette.background.strong.color).width(1))
});
- let sidebar = container(
+ let sidebar = center_y(
column!["Sidebar!", square(50), square(50)]
.spacing(40)
.padding(10)
.width(200)
.align_x(Center),
)
- .style(container::rounded_box)
- .center_y(Fill);
+ .style(container::rounded_box);
let content = container(
scrollable(
diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs
index b43a627a..f9021c8d 100644
--- a/examples/multi_window/src/main.rs
+++ b/examples/multi_window/src/main.rs
@@ -1,5 +1,5 @@
use iced::widget::{
- button, center, column, container, horizontal_space, scrollable, text,
+ button, center, center_x, column, horizontal_space, scrollable, text,
text_input,
};
use iced::window;
@@ -193,6 +193,6 @@ impl Window {
.align_x(Center),
);
- container(content).center_x(200).into()
+ center_x(content).width(200).into()
}
}
diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs
index 67f4d27f..17ba5804 100644
--- a/examples/pane_grid/src/main.rs
+++ b/examples/pane_grid/src/main.rs
@@ -1,7 +1,7 @@
use iced::keyboard;
use iced::widget::pane_grid::{self, PaneGrid};
use iced::widget::{
- button, column, container, responsive, row, scrollable, text,
+ button, center_y, column, container, responsive, row, scrollable, text,
};
use iced::{Center, Color, Element, Fill, Size, Subscription};
@@ -196,11 +196,7 @@ impl Example {
.on_drag(Message::Dragged)
.on_resize(10, Message::Resized);
- container(pane_grid)
- .width(Fill)
- .height(Fill)
- .padding(10)
- .into()
+ container(pane_grid).padding(10).into()
}
}
@@ -295,10 +291,7 @@ fn view_content<'a>(
.spacing(10)
.align_x(Center);
- container(scrollable(content))
- .center_y(Fill)
- .padding(5)
- .into()
+ center_y(scrollable(content)).padding(5).into()
}
fn view_controls<'a>(
diff --git a/examples/progress_bar/src/main.rs b/examples/progress_bar/src/main.rs
index 67da62f2..e431a404 100644
--- a/examples/progress_bar/src/main.rs
+++ b/examples/progress_bar/src/main.rs
@@ -1,4 +1,7 @@
-use iced::widget::{column, progress_bar, slider};
+use iced::widget::{
+ center, center_x, checkbox, column, progress_bar, row, slider,
+ vertical_slider,
+};
use iced::Element;
pub fn main() -> iced::Result {
@@ -8,25 +11,58 @@ pub fn main() -> iced::Result {
#[derive(Default)]
struct Progress {
value: f32,
+ is_vertical: bool,
}
#[derive(Debug, Clone, Copy)]
enum Message {
SliderChanged(f32),
+ ToggleVertical(bool),
}
impl Progress {
fn update(&mut self, message: Message) {
match message {
Message::SliderChanged(x) => self.value = x,
+ Message::ToggleVertical(is_vertical) => {
+ self.is_vertical = is_vertical
+ }
}
}
fn view(&self) -> Element<Message> {
+ let bar = progress_bar(0.0..=100.0, self.value);
+
column![
- progress_bar(0.0..=100.0, self.value),
- slider(0.0..=100.0, self.value, Message::SliderChanged).step(0.01)
+ if self.is_vertical {
+ center(
+ row![
+ bar.vertical(),
+ vertical_slider(
+ 0.0..=100.0,
+ self.value,
+ Message::SliderChanged
+ )
+ .step(0.01)
+ ]
+ .spacing(20),
+ )
+ } else {
+ center(
+ column![
+ bar,
+ slider(0.0..=100.0, self.value, Message::SliderChanged)
+ .step(0.01)
+ ]
+ .spacing(20),
+ )
+ },
+ center_x(
+ checkbox("Vertical", self.is_vertical)
+ .on_toggle(Message::ToggleVertical)
+ ),
]
+ .spacing(20)
.padding(20)
.into()
}
diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs
index 5c105f6c..7766542d 100644
--- a/examples/screenshot/src/main.rs
+++ b/examples/screenshot/src/main.rs
@@ -1,5 +1,7 @@
use iced::keyboard;
-use iced::widget::{button, column, container, image, row, text, text_input};
+use iced::widget::{
+ button, center_y, column, container, image, row, text, text_input,
+};
use iced::window;
use iced::window::screenshot::{self, Screenshot};
use iced::{
@@ -131,8 +133,8 @@ impl Example {
text("Press the button to take a screenshot!").into()
};
- let image = container(image)
- .center_y(FillPortion(2))
+ let image = center_y(image)
+ .height(FillPortion(2))
.padding(10)
.style(container::rounded_box);
@@ -211,7 +213,7 @@ impl Example {
.spacing(40)
};
- let side_content = container(controls).center_y(Fill);
+ let side_content = center_y(controls);
let content = row![side_content, image]
.spacing(10)
diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs
index 0d824d36..a814da55 100644
--- a/examples/stopwatch/src/main.rs
+++ b/examples/stopwatch/src/main.rs
@@ -1,10 +1,8 @@
use iced::keyboard;
-use iced::time;
+use iced::time::{self, milliseconds, Duration, Instant};
use iced::widget::{button, center, column, row, text};
use iced::{Center, Element, Subscription, Theme};
-use std::time::{Duration, Instant};
-
pub fn main() -> iced::Result {
iced::application("Stopwatch - Iced", Stopwatch::update, Stopwatch::view)
.subscription(Stopwatch::subscription)
@@ -63,7 +61,7 @@ impl Stopwatch {
let tick = match self.state {
State::Idle => Subscription::none(),
State::Ticking { .. } => {
- time::every(Duration::from_millis(10)).map(Message::Tick)
+ time::every(milliseconds(10)).map(Message::Tick)
}
};
diff --git a/examples/svg/src/main.rs b/examples/svg/src/main.rs
index 02cb85cc..c4be8fb8 100644
--- a/examples/svg/src/main.rs
+++ b/examples/svg/src/main.rs
@@ -1,4 +1,4 @@
-use iced::widget::{center, checkbox, column, container, svg};
+use iced::widget::{center, center_x, checkbox, column, svg};
use iced::{color, Element, Fill};
pub fn main() -> iced::Result {
@@ -46,12 +46,8 @@ impl Tiger {
checkbox("Apply a color filter", self.apply_color_filter)
.on_toggle(Message::ToggleColorFilter);
- center(
- column![svg, container(apply_color_filter).center_x(Fill)]
- .spacing(20)
- .height(Fill),
- )
- .padding(20)
- .into()
+ center(column![svg, center_x(apply_color_filter)].spacing(20))
+ .padding(20)
+ .into()
}
}
diff --git a/examples/the_matrix/src/main.rs b/examples/the_matrix/src/main.rs
index c6b20ece..315e9ee5 100644
--- a/examples/the_matrix/src/main.rs
+++ b/examples/the_matrix/src/main.rs
@@ -1,5 +1,5 @@
use iced::mouse;
-use iced::time::{self, Instant};
+use iced::time::{self, milliseconds, Instant};
use iced::widget::canvas;
use iced::{
Color, Element, Fill, Font, Point, Rectangle, Renderer, Subscription, Theme,
@@ -40,7 +40,7 @@ impl TheMatrix {
}
fn subscription(&self) -> Subscription<Message> {
- time::every(std::time::Duration::from_millis(50)).map(Message::Tick)
+ time::every(milliseconds(50)).map(Message::Tick)
}
}
diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs
index a1b5886f..2ae9bfe2 100644
--- a/examples/toast/src/main.rs
+++ b/examples/toast/src/main.rs
@@ -162,7 +162,6 @@ impl Default for App {
mod toast {
use std::fmt;
- use std::time::{Duration, Instant};
use iced::advanced::layout::{self, Layout};
use iced::advanced::overlay;
@@ -171,6 +170,7 @@ mod toast {
use iced::advanced::{Clipboard, Shell, Widget};
use iced::mouse;
use iced::theme;
+ use iced::time::{self, Duration, Instant};
use iced::widget::{
button, column, container, horizontal_rule, horizontal_space, row, text,
};
@@ -502,9 +502,8 @@ mod toast {
self.instants.iter_mut().enumerate().for_each(
|(index, maybe_instant)| {
if let Some(instant) = maybe_instant.as_mut() {
- let remaining =
- Duration::from_secs(self.timeout_secs)
- .saturating_sub(instant.elapsed());
+ let remaining = time::seconds(self.timeout_secs)
+ .saturating_sub(instant.elapsed());
if remaining == Duration::ZERO {
maybe_instant.take();
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index e86e23b5..7759552c 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -1,6 +1,6 @@
use iced::keyboard;
use iced::widget::{
- self, button, center, checkbox, column, container, keyed_column, row,
+ self, button, center, center_x, checkbox, column, keyed_column, row,
scrollable, text, text_input, Text,
};
use iced::window;
@@ -237,7 +237,7 @@ impl Todos {
.spacing(20)
.max_width(800);
- scrollable(container(content).center_x(Fill).padding(40)).into()
+ scrollable(center_x(content).padding(40)).into()
}
}
}
diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs
index d8c0b29a..32720c47 100644
--- a/examples/tour/src/main.rs
+++ b/examples/tour/src/main.rs
@@ -1,6 +1,6 @@
use iced::widget::{
- button, checkbox, column, container, horizontal_space, image, radio, row,
- scrollable, slider, text, text_input, toggler, vertical_space,
+ button, center_x, center_y, checkbox, column, horizontal_space, image,
+ radio, row, scrollable, slider, text, text_input, toggler, vertical_space,
};
use iced::widget::{Button, Column, Container, Slider};
use iced::{Center, Color, Element, Fill, Font, Pixels};
@@ -166,16 +166,13 @@ impl Tour {
.padding(20)
.into();
- let scrollable = scrollable(
- container(if self.debug {
- content.explain(Color::BLACK)
- } else {
- content
- })
- .center_x(Fill),
- );
+ let scrollable = scrollable(center_x(if self.debug {
+ content.explain(Color::BLACK)
+ } else {
+ content
+ }));
- container(scrollable).center_y(Fill).into()
+ center_y(scrollable).into()
}
fn can_continue(&self) -> bool {
@@ -543,7 +540,7 @@ fn ferris<'a>(
width: u16,
filter_method: image::FilterMethod,
) -> Container<'a, Message> {
- container(
+ center_x(
// This should go away once we unify resource loading on native
// platforms
if cfg!(target_arch = "wasm32") {
@@ -554,7 +551,6 @@ fn ferris<'a>(
.filter_method(filter_method)
.width(width),
)
- .center_x(Fill)
}
fn padded_button<Message: Clone>(label: &str) -> Button<'_, Message> {