Formatting
This commit is contained in:
parent
ec41918ec4
commit
3e5d34f25f
4 changed files with 81 additions and 25 deletions
|
|
@ -57,9 +57,9 @@ enum WindowMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Example {
|
impl Application for Example {
|
||||||
|
type Executor = executor::Default;
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
type Theme = Theme;
|
type Theme = Theme;
|
||||||
type Executor = executor::Default;
|
|
||||||
type Flags = ();
|
type Flags = ();
|
||||||
|
|
||||||
fn new(_flags: ()) -> (Self, Command<Message>) {
|
fn new(_flags: ()) -> (Self, Command<Message>) {
|
||||||
|
|
@ -251,10 +251,6 @@ impl Application for Example {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_requested(&self, window: window::Id) -> Self::Message {
|
|
||||||
Message::Window(window, WindowMessage::CloseWindow)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self, window_id: window::Id) -> Element<Message> {
|
fn view(&self, window_id: window::Id) -> Element<Message> {
|
||||||
if let Some(window) = self.windows.get(&window_id) {
|
if let Some(window) = self.windows.get(&window_id) {
|
||||||
let focus = window.focus;
|
let focus = window.focus;
|
||||||
|
|
@ -342,6 +338,10 @@ impl Application for Example {
|
||||||
.center_y()
|
.center_y()
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn close_requested(&self, window: window::Id) -> Self::Message {
|
||||||
|
Message::Window(window, WindowMessage::CloseWindow)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const PANE_ID_COLOR_UNFOCUSED: Color = Color::from_rgb(
|
const PANE_ID_COLOR_UNFOCUSED: Color = Color::from_rgb(
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,12 @@ impl<A: Application> State<A>
|
||||||
where
|
where
|
||||||
<A::Renderer as crate::Renderer>::Theme: application::StyleSheet,
|
<A::Renderer as crate::Renderer>::Theme: application::StyleSheet,
|
||||||
{
|
{
|
||||||
/// Creates a new [`State`] for the provided [`Application`] and window.
|
/// Creates a new [`State`] for the provided [`Application`]'s window.
|
||||||
pub fn new(application: &A, window_id: window::Id, window: &Window) -> Self {
|
pub fn new(
|
||||||
|
application: &A,
|
||||||
|
window_id: window::Id,
|
||||||
|
window: &Window,
|
||||||
|
) -> Self {
|
||||||
let title = application.title(window_id);
|
let title = application.title(window_id);
|
||||||
let scale_factor = application.scale_factor();
|
let scale_factor = application.scale_factor();
|
||||||
let theme = application.theme();
|
let theme = application.theme();
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,62 @@ use crate::{Command, Element, Executor, Settings, Subscription};
|
||||||
|
|
||||||
pub use iced_native::application::{Appearance, StyleSheet};
|
pub use iced_native::application::{Appearance, StyleSheet};
|
||||||
|
|
||||||
/// A pure version of [`Application`].
|
/// An interactive cross-platform multi-window application.
|
||||||
///
|
///
|
||||||
/// Unlike the impure version, the `view` method of this trait takes an
|
/// This trait is the main entrypoint of Iced. Once implemented, you can run
|
||||||
/// immutable reference to `self` and returns a pure [`Element`].
|
/// your GUI application by simply calling [`run`](#method.run).
|
||||||
///
|
///
|
||||||
/// [`Application`]: crate::Application
|
/// An [`Application`] can execute asynchronous actions by returning a
|
||||||
/// [`Element`]: pure::Element
|
/// [`Command`] in some of its methods. For example, to spawn a new window, you
|
||||||
|
/// can use the `iced_winit::window::spawn()` [`Command`].
|
||||||
|
///
|
||||||
|
/// When using an [`Application`] with the `debug` feature enabled, a debug view
|
||||||
|
/// can be toggled by pressing `F12`.
|
||||||
|
///
|
||||||
|
/// ## A simple "Hello, world!"
|
||||||
|
///
|
||||||
|
/// If you just want to get started, here is a simple [`Application`] that
|
||||||
|
/// says "Hello, world!":
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// use iced::executor;
|
||||||
|
/// use iced::multi_window::Application;
|
||||||
|
/// use iced::window;
|
||||||
|
/// use iced::{Command, Element, Settings, Theme};
|
||||||
|
///
|
||||||
|
/// pub fn main() -> iced::Result {
|
||||||
|
/// Hello::run(Settings::default())
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// struct Hello;
|
||||||
|
///
|
||||||
|
/// impl Application for Hello {
|
||||||
|
/// type Executor = executor::Default;
|
||||||
|
/// type Message = ();
|
||||||
|
/// type Theme = Theme;
|
||||||
|
/// type Flags = ();
|
||||||
|
///
|
||||||
|
/// fn new(_flags: ()) -> (Hello, Command<Self::Message>) {
|
||||||
|
/// (Hello, Command::none())
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn title(&self, window: window::Id) -> String {
|
||||||
|
/// String::from("A cool application")
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
|
||||||
|
/// Command::none()
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn view(&self, window: window::Id) -> Element<Self::Message> {
|
||||||
|
/// "Hello, world!".into()
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn close_requested(&self, window: window::Id) -> Self::Message {
|
||||||
|
/// ()
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
pub trait Application: Sized {
|
pub trait Application: Sized {
|
||||||
/// The [`Executor`] that will run commands and subscriptions.
|
/// The [`Executor`] that will run commands and subscriptions.
|
||||||
///
|
///
|
||||||
|
|
@ -157,16 +206,6 @@ where
|
||||||
type Renderer = crate::Renderer<A::Theme>;
|
type Renderer = crate::Renderer<A::Theme>;
|
||||||
type Message = A::Message;
|
type Message = A::Message;
|
||||||
|
|
||||||
fn new(flags: Self::Flags) -> (Self, Command<A::Message>) {
|
|
||||||
let (app, command) = A::new(flags);
|
|
||||||
|
|
||||||
(Instance(app), command)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn title(&self, window: window::Id) -> String {
|
|
||||||
self.0.title(window)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
||||||
self.0.update(message)
|
self.0.update(message)
|
||||||
}
|
}
|
||||||
|
|
@ -178,6 +217,16 @@ where
|
||||||
self.0.view(window)
|
self.0.view(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new(flags: Self::Flags) -> (Self, Command<A::Message>) {
|
||||||
|
let (app, command) = A::new(flags);
|
||||||
|
|
||||||
|
(Instance(app), command)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&self, window: window::Id) -> String {
|
||||||
|
self.0.title(window)
|
||||||
|
}
|
||||||
|
|
||||||
fn theme(&self) -> A::Theme {
|
fn theme(&self) -> A::Theme {
|
||||||
self.0.theme()
|
self.0.theme()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,12 @@ impl<A: Application> State<A>
|
||||||
where
|
where
|
||||||
<A::Renderer as crate::Renderer>::Theme: application::StyleSheet,
|
<A::Renderer as crate::Renderer>::Theme: application::StyleSheet,
|
||||||
{
|
{
|
||||||
/// Creates a new [`State`] for the provided [`Application`] and window.
|
/// Creates a new [`State`] for the provided [`Application`]'s window.
|
||||||
pub fn new(application: &A, window_id: window::Id, window: &Window) -> Self {
|
pub fn new(
|
||||||
|
application: &A,
|
||||||
|
window_id: window::Id,
|
||||||
|
window: &Window,
|
||||||
|
) -> Self {
|
||||||
let title = application.title(window_id);
|
let title = application.title(window_id);
|
||||||
let scale_factor = application.scale_factor();
|
let scale_factor = application.scale_factor();
|
||||||
let theme = application.theme();
|
let theme = application.theme();
|
||||||
|
|
@ -191,7 +195,6 @@ where
|
||||||
|
|
||||||
if self.title != new_title {
|
if self.title != new_title {
|
||||||
window.set_title(&new_title);
|
window.set_title(&new_title);
|
||||||
|
|
||||||
self.title = new_title;
|
self.title = new_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue