Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Windows. #2472

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/ferris/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Image {
}
}

fn view(&self) -> Element<Message> {
fn view(&self, _window: Option<window::Id>) -> Element<Message> {
let i_am_ferris = column![
"Hello!",
Element::from(
Expand Down
131 changes: 57 additions & 74 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@
fn view<'a>(
&self,
state: &'a Self::State,
_window: window::Id,
window: window::Id,
) -> Element<'a, Self::Message, Self::Theme, Self::Renderer> {
self.view.view(state).into()
self.view.view(state, Some(window)).into()
}
}

Expand All @@ -134,7 +134,7 @@
_renderer: PhantomData,
},
settings: Settings::default(),
window: window::Settings::default(),
windows: vec![window::Settings::default()],
}
.title(title)
}
Expand All @@ -150,7 +150,7 @@
pub struct Application<P: Program> {
raw: P,
settings: Settings,
window: window::Settings,
windows: Vec<window::Settings>,
}

impl<P: Program> Application<P> {
Expand All @@ -172,11 +172,11 @@
/// Runs the [`Application`] with a closure that creates the initial state.
pub fn run_with<I>(self, initialize: I) -> Result
where
Self: 'static,

Check failure on line 175 in src/application.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/src/application.rs
I: Fn() -> P::State + Clone + 'static,
{
self.raw
.run_with(self.settings, Some(self.window), initialize)
.run_with(self.settings, self.windows, initialize)
}

/// Sets the [`Settings`] that will be used to run the [`Application`].
Expand Down Expand Up @@ -212,99 +212,80 @@
self
}

/// Sets the [`window::Settings`] of the [`Application`].
///
/// Overwrites any previous [`window::Settings`].
pub fn window(self, window: window::Settings) -> Self {
Self { window, ..self }
/// Adds a [`window::Settings`] to the [`Application`].
pub fn without_windows(mut self) -> Self {
self.windows.clear();
self
}

/// Adds a [`window::Settings`] to the [`Application`].
pub fn add_window(mut self, window: window::Settings) -> Self {
self.windows.push(window);
self
}

/// Sets the [`window::Settings::position`] to [`window::Position::Centered`] in the [`Application`].
pub fn centered(self) -> Self {
Self {
window: window::Settings {
position: window::Position::Centered,
..self.window
},
..self
pub fn centered(mut self) -> Self {
for window in &mut self.windows {
window.position = window::Position::Centered;
}
self
}

Check failure on line 233 in src/application.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/src/application.rs

/// Sets the [`window::Settings::exit_on_close_request`] of the [`Application`].
pub fn exit_on_close_request(self, exit_on_close_request: bool) -> Self {
Self {
window: window::Settings {
exit_on_close_request,
..self.window
},
..self
pub fn exit_on_close_request(mut self, exit_on_close_request: bool) -> Self {
for window in &mut self.windows {
window.exit_on_close_request = exit_on_close_request;
}
self
}

/// Sets the [`window::Settings::size`] of the [`Application`].
pub fn window_size(self, size: impl Into<Size>) -> Self {
Self {
window: window::Settings {
size: size.into(),
..self.window
},
..self
pub fn window_size(mut self, size: impl Into<Size> + Clone) -> Self {
for window in &mut self.windows {
window.size = size.clone().into();
}
self
}

/// Sets the [`window::Settings::transparent`] of the [`Application`].
pub fn transparent(self, transparent: bool) -> Self {
Self {
window: window::Settings {
transparent,
..self.window
},
..self
pub fn transparent(mut self, transparent: bool) -> Self {
for window in &mut self.windows {
window.transparent = transparent;
}
self
}

/// Sets the [`window::Settings::resizable`] of the [`Application`].
pub fn resizable(self, resizable: bool) -> Self {
Self {
window: window::Settings {
resizable,
..self.window
},
..self
pub fn resizable(mut self, resizable: bool) -> Self {
for window in &mut self.windows {
window.resizable = resizable;
}
self
}

/// Sets the [`window::Settings::decorations`] of the [`Application`].
pub fn decorations(self, decorations: bool) -> Self {
Self {
window: window::Settings {
decorations,
..self.window
},
..self
pub fn decorations(mut self, decorations: bool) -> Self {
for window in &mut self.windows {
window.decorations = decorations;
}
self
}

/// Sets the [`window::Settings::position`] of the [`Application`].
pub fn position(self, position: window::Position) -> Self {
Self {
window: window::Settings {
position,
..self.window
},
..self
pub fn position(mut self, position: window::Position) -> Self {
for window in &mut self.windows {
window.position = position;
}
self
}

/// Sets the [`window::Settings::level`] of the [`Application`].
pub fn level(self, level: window::Level) -> Self {
Self {
window: window::Settings {
level,
..self.window
},
..self
pub fn level(mut self, level: window::Level) -> Self {
for window in &mut self.windows {
window.level = level;
}
self
}

/// Sets the [`Title`] of the [`Application`].
Expand All @@ -319,7 +300,7 @@
title.title(state)
}),
settings: self.settings,
window: self.window,
windows: self.windows,
}
}

Expand All @@ -333,7 +314,7 @@
Application {
raw: program::with_load(self.raw, f),
settings: self.settings,
window: self.window,
windows: self.windows,
}
}

Expand All @@ -347,7 +328,7 @@
Application {
raw: program::with_subscription(self.raw, f),
settings: self.settings,
window: self.window,
windows: self.windows,
}
}

Expand All @@ -361,7 +342,7 @@
Application {
raw: program::with_theme(self.raw, move |state, _window| f(state)),
settings: self.settings,
window: self.window,
windows: self.windows,
}
}

Expand All @@ -375,7 +356,7 @@
Application {
raw: program::with_style(self.raw, f),
settings: self.settings,
window: self.window,
windows: self.windows,
}
}

Expand All @@ -391,7 +372,7 @@
f(state)
}),
settings: self.settings,
window: self.window,
windows: self.windows,
}
}
}
Expand Down Expand Up @@ -458,20 +439,22 @@
fn view(
&self,
state: &'a State,
window: Option<window::Id>,
) -> impl Into<Element<'a, Message, Theme, Renderer>>;
}

impl<'a, T, State, Message, Theme, Renderer, Widget>
View<'a, State, Message, Theme, Renderer> for T
where
T: Fn(&'a State) -> Widget,
T: Fn(&'a State, Option<window::Id>) -> Widget,
State: 'static,
Widget: Into<Element<'a, Message, Theme, Renderer>>,
{
fn view(
&self,
state: &'a State,
window: Option<window::Id>,
) -> impl Into<Element<'a, Message, Theme, Renderer>> {
self(state)
self(state, window)
}
}
2 changes: 1 addition & 1 deletion src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<P: Program> Daemon<P> {
Self: 'static,
I: Fn() -> P::State + Clone + 'static,
{
self.raw.run_with(self.settings, None, initialize)
self.raw.run_with(self.settings, Vec::new(), initialize)
}

/// Sets the [`Settings`] that will be used to run the [`Daemon`].
Expand Down
7 changes: 4 additions & 3 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
fn run(
self,
settings: Settings,
window_settings: Option<window::Settings>,
window_settings: Vec<window::Settings>,
) -> Result
where
Self: 'static,
Expand All @@ -87,7 +87,7 @@
fn run_with<I>(
self,
settings: Settings,
window_settings: Option<window::Settings>,
window_settings: Vec<window::Settings>,
initialize: I,
) -> Result
where
Expand Down Expand Up @@ -170,9 +170,10 @@
} else {
None
},
..crate::graphics::Settings::default()

Check failure on line 173 in src/program.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/src/program.rs
};


Ok(shell::program::run::<
Instance<Self, I>,
<Self::Renderer as compositor::Default>::Compositor,
Expand All @@ -186,7 +187,7 @@
}
.into(),
renderer_settings,
window_settings,
window_settings.get(0).cloned(),

Check failure on line 190 in src/program.rs

View workflow job for this annotation

GitHub Actions / all

accessing first element with `window_settings.get(0)`
(self, initialize),
)?)
}
Expand Down
Loading