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

feat: somewhere to place extra actions by platform #2146

Merged
merged 4 commits into from
Feb 3, 2024
Merged
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `style` attribute for `Font`. [#2041](https://github.com/iced-rs/iced/pull/2041)
- Texture filtering options for `Image`. [#1894](https://github.com/iced-rs/iced/pull/1894)
- `default` and `shift_step` methods for `slider` widgets. [#2100](https://github.com/iced-rs/iced/pull/2100)
- `Custom` variant to `command::Action`. [#2146](https://github.com/iced-rs/iced/pull/2146)

### Changed
- Enable WebGPU backend in `wgpu` by default instead of WebGL. [#2068](https://github.com/iced-rs/iced/pull/2068)
Expand Down Expand Up @@ -101,6 +102,7 @@ Many thanks to...
- @casperstorm
- @cfrenette
- @Davidster
- @Decodetalkers
- @derezzedex
- @dtzxporter
- @GyulyVGC
Expand Down
9 changes: 7 additions & 2 deletions runtime/src/command/action.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::clipboard;
use crate::core::widget;
use crate::font;
use crate::futures::MaybeSend;
use crate::system;
use crate::window;

use iced_futures::MaybeSend;

use std::any::Any;
use std::borrow::Cow;
use std::fmt;

Expand Down Expand Up @@ -43,6 +43,9 @@ pub enum Action<T> {
/// The message to produce when the font has been loaded.
tagger: Box<dyn Fn(Result<(), font::Error>) -> T>,
},

/// A custom action supported by a specific runtime.
Custom(Box<dyn Any>),
}

impl<T> Action<T> {
Expand Down Expand Up @@ -72,6 +75,7 @@ impl<T> Action<T> {
bytes,
tagger: Box::new(move |result| f(tagger(result))),
},
Self::Custom(custom) => Action::Custom(custom),
}
}
}
Expand All @@ -90,6 +94,7 @@ impl<T> fmt::Debug for Action<T> {
Self::System(action) => write!(f, "Action::System({action:?})"),
Self::Widget(_action) => write!(f, "Action::Widget"),
Self::LoadFont { .. } => write!(f, "Action::LoadFont"),
Self::Custom(_) => write!(f, "Action::Custom"),
}
}
}
3 changes: 3 additions & 0 deletions winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@ pub fn run_command<A, C, E>(
.send_event(tagger(Ok(())))
.expect("Send message to event loop");
}
command::Action::Custom(_) => {
log::warn!("Unsupported custom action in `iced_winit` shell");
}
}
}
}
3 changes: 3 additions & 0 deletions winit/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,9 @@ fn run_command<A, C, E>(
.send_event(tagger(Ok(())))
.expect("Send message to event loop");
}
command::Action::Custom(_) => {
log::warn!("Unsupported custom action in `iced_winit` shell");
}
}
}
}
Expand Down
Loading