Use Program API in visible_bounds example
This commit is contained in:
parent
c4be7efce5
commit
78e78d20b6
1 changed files with 8 additions and 29 deletions
|
|
@ -1,19 +1,22 @@
|
||||||
use iced::event::{self, Event};
|
use iced::event::{self, Event};
|
||||||
use iced::executor;
|
|
||||||
use iced::mouse;
|
use iced::mouse;
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
column, container, horizontal_space, row, scrollable, text, vertical_space,
|
column, container, horizontal_space, row, scrollable, text, vertical_space,
|
||||||
};
|
};
|
||||||
use iced::window;
|
use iced::window;
|
||||||
use iced::{
|
use iced::{
|
||||||
Alignment, Application, Color, Command, Element, Font, Length, Point,
|
Alignment, Color, Command, Element, Font, Length, Point, Rectangle,
|
||||||
Rectangle, Settings, Subscription, Theme,
|
Subscription, Theme,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
Example::run(Settings::default())
|
iced::program("Visible Bounds - Iced", Example::update, Example::view)
|
||||||
|
.subscription(Example::subscription)
|
||||||
|
.theme(|_| Theme::Dark)
|
||||||
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
struct Example {
|
struct Example {
|
||||||
mouse_position: Option<Point>,
|
mouse_position: Option<Point>,
|
||||||
outer_bounds: Option<Rectangle>,
|
outer_bounds: Option<Rectangle>,
|
||||||
|
|
@ -29,27 +32,7 @@ enum Message {
|
||||||
InnerBoundsFetched(Option<Rectangle>),
|
InnerBoundsFetched(Option<Rectangle>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Example {
|
impl Example {
|
||||||
type Message = Message;
|
|
||||||
type Theme = Theme;
|
|
||||||
type Flags = ();
|
|
||||||
type Executor = executor::Default;
|
|
||||||
|
|
||||||
fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
|
|
||||||
(
|
|
||||||
Self {
|
|
||||||
mouse_position: None,
|
|
||||||
outer_bounds: None,
|
|
||||||
inner_bounds: None,
|
|
||||||
},
|
|
||||||
Command::none(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn title(&self) -> String {
|
|
||||||
String::from("Visible bounds - Iced")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, message: Message) -> Command<Message> {
|
fn update(&mut self, message: Message) -> Command<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::MouseMoved(position) => {
|
Message::MouseMoved(position) => {
|
||||||
|
|
@ -172,10 +155,6 @@ impl Application for Example {
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn theme(&self) -> Theme {
|
|
||||||
Theme::Dark
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue