improv: allow overrides for corner radius or blur that apply on creation as well

This commit is contained in:
Ashley Wulber 2026-05-15 14:27:17 -04:00 committed by Ashley Wulber
parent f268bb86cf
commit ac4a1ab259
9 changed files with 415 additions and 285 deletions

View file

@ -5,7 +5,9 @@ use super::Action;
#[cfg(feature = "winit")]
use crate::Application;
use iced::window;
use iced::{Rectangle, window};
#[cfg(all(feature = "wayland", target_os = "linux", feature = "winit"))]
use iced_runtime::platform_specific::wayland::CornerRadius;
use std::any::Any;
use std::sync::Arc;
@ -34,18 +36,30 @@ pub fn destroy_layer_shell(id: iced_core::window::Id) -> Action {
Action::DestroyLayerShell(id)
}
#[derive(Debug, Default, Copy, Clone)]
pub struct LiveSettings {
#[cfg(all(feature = "wayland", target_os = "linux", feature = "winit"))]
/// Override the default corner radius value for the surface type.
pub corners: Option<CornerRadius>,
/// Override the default blur setting for the surface type.
pub blur: Option<bool>,
}
type BoxedView<App> = Option<
Box<
dyn Fn(&App) -> crate::Element<'_, crate::Action<<App as Application>::Message>>
+ Send
+ Sync
+ 'static,
>,
>;
#[cfg(all(feature = "wayland", target_os = "linux", feature = "winit"))]
#[must_use]
pub fn app_window<App: Application>(
live_settings: impl Fn(&App) -> LiveSettings + Send + Sync + 'static,
settings: impl Fn(&mut App) -> window::Settings + Send + Sync + 'static,
view: Option<
Box<
dyn for<'a> Fn(&'a App) -> crate::Element<'a, crate::Action<App::Message>>
+ Send
+ Sync
+ 'static,
>,
>,
view: BoxedView<App>,
) -> (window::Id, Action) {
let id = window::Id::unique();
@ -53,11 +67,16 @@ pub fn app_window<App: Application>(
Box::new(settings);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
let boxed_live: Box<dyn Fn(&App) -> LiveSettings + Send + Sync + 'static> =
Box::new(live_settings);
let boxed_live: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed_live);
(
id,
Action::AppWindow(
id,
Arc::new(boxed),
Arc::new(boxed_live),
view.map(|view| {
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
Arc::new(boxed)
@ -70,6 +89,7 @@ pub fn app_window<App: Application>(
#[cfg(all(feature = "wayland", target_os = "linux", feature = "winit"))]
#[must_use]
pub fn simple_window<Message: 'static>(
live_settings: impl Fn() -> LiveSettings + Send + Sync + 'static,
settings: impl Fn() -> window::Settings + Send + Sync + 'static,
view: Option<
impl Fn() -> crate::Element<'static, crate::Action<Message>> + Send + Sync + 'static,
@ -80,11 +100,15 @@ pub fn simple_window<Message: 'static>(
let boxed: Box<dyn Fn() -> window::Settings + Send + Sync + 'static> = Box::new(settings);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
let boxed_live: Box<dyn Fn() -> LiveSettings + Send + Sync + 'static> = Box::new(live_settings);
let boxed_live: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed_live);
(
id,
Action::Window(
id,
Arc::new(boxed),
Arc::new(boxed_live),
view.map(|view| {
let boxed: Box<
dyn Fn() -> crate::Element<'static, crate::Action<Message>>
@ -102,18 +126,12 @@ pub fn simple_window<Message: 'static>(
#[cfg(all(feature = "wayland", target_os = "linux", feature = "winit"))]
#[must_use]
pub fn app_popup<App: Application>(
live_settings: impl Fn(&App) -> LiveSettings + Send + Sync + 'static,
settings: impl Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
+ Send
+ Sync
+ 'static,
view: Option<
Box<
dyn for<'a> Fn(&'a App) -> crate::Element<'a, crate::Action<App::Message>>
+ Send
+ Sync
+ 'static,
>,
>,
view: BoxedView<App>,
) -> Action {
let boxed: Box<
dyn Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
@ -123,8 +141,13 @@ pub fn app_popup<App: Application>(
> = Box::new(settings);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
let boxed_live: Box<dyn Fn(&App) -> LiveSettings + Send + Sync + 'static> =
Box::new(live_settings);
let boxed_live: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed_live);
Action::AppPopup(
Arc::new(boxed),
Arc::new(boxed_live),
view.map(|view| {
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
Arc::new(boxed)
@ -154,6 +177,7 @@ pub fn simple_subsurface<Message: 'static, V>(
Action::Subsurface(
Arc::new(boxed),
Arc::new(Box::new(LiveSettings::default)),
view.map(|view| {
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
Arc::new(boxed)
@ -165,6 +189,7 @@ pub fn simple_subsurface<Message: 'static, V>(
#[cfg(all(feature = "wayland", target_os = "linux", feature = "winit"))]
#[must_use]
pub fn simple_popup<Message: 'static>(
live_settings: impl Fn() -> LiveSettings + Send + Sync + 'static,
settings: impl Fn() -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
+ Send
+ Sync
@ -181,8 +206,12 @@ pub fn simple_popup<Message: 'static>(
> = Box::new(settings);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
let boxed_live: Box<dyn Fn() -> LiveSettings + Send + Sync + 'static> = Box::new(live_settings);
let boxed_live: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed_live);
Action::Popup(
Arc::new(boxed),
Arc::new(boxed_live),
view.map(|view| {
let boxed: Box<
dyn Fn() -> crate::Element<'static, crate::Action<Message>> + Send + Sync + 'static,
@ -204,14 +233,7 @@ pub fn subsurface<App: Application>(
+ Sync
+ 'static,
// XXX Boxed trait object is required for less cumbersome type inference, but we box it anyways.
view: Option<
Box<
dyn for<'a> Fn(&'a App) -> crate::Element<'a, crate::Action<App::Message>>
+ Send
+ Sync
+ 'static,
>,
>,
view: BoxedView<App>,
) -> Action {
let boxed: Box<
dyn Fn(
@ -226,6 +248,7 @@ pub fn subsurface<App: Application>(
Action::AppSubsurface(
Arc::new(boxed),
Arc::new(Box::new(|_: &App| LiveSettings::default())),
view.map(|view| {
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
Arc::new(boxed)
@ -236,6 +259,7 @@ pub fn subsurface<App: Application>(
#[cfg(all(feature = "wayland", target_os = "linux", feature = "winit"))]
#[must_use]
pub fn simple_layer_shell<Message: 'static>(
live_settings: impl Fn() -> LiveSettings + Send + Sync + 'static,
settings: impl Fn()
-> iced_runtime::platform_specific::wayland::layer_surface::SctkLayerSurfaceSettings
+ Send
@ -253,9 +277,11 @@ pub fn simple_layer_shell<Message: 'static>(
+ 'static,
> = Box::new(settings);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
let boxed_live: Box<dyn Fn() -> LiveSettings + Send + Sync + 'static> = Box::new(live_settings);
let boxed_live: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed_live);
Action::LayerShell(
Arc::new(boxed),
Arc::new(boxed_live),
view.map(|view| {
let boxed: Box<
dyn Fn() -> crate::Element<'static, crate::Action<Message>> + Send + Sync + 'static,
@ -268,7 +294,8 @@ pub fn simple_layer_shell<Message: 'static>(
#[cfg(all(feature = "wayland", target_os = "linux", feature = "winit"))]
#[must_use]
pub fn layer_shell<App: Application>(
pub fn app_layer_shell<App: Application>(
live_settings: impl Fn(&App) -> LiveSettings + Send + Sync + 'static,
settings: impl Fn(
&mut App,
)
@ -277,14 +304,7 @@ pub fn layer_shell<App: Application>(
+ Sync
+ 'static,
// XXX Boxed trait object is required for less cumbersome type inference, but we box it anyways.
view: Option<
Box<
dyn for<'a> Fn(&'a App) -> crate::Element<'a, crate::Action<App::Message>>
+ Send
+ Sync
+ 'static,
>,
>,
view: BoxedView<App>,
) -> Action {
let boxed: Box<
dyn Fn(
@ -297,8 +317,13 @@ pub fn layer_shell<App: Application>(
> = Box::new(settings);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
let boxed_live: Box<dyn Fn(&App) -> LiveSettings + Send + Sync + 'static> =
Box::new(live_settings);
let boxed_live: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed_live);
Action::AppLayerShell(
Arc::new(boxed),
Arc::new(boxed_live),
view.map(|view| {
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
Arc::new(boxed)

View file

@ -4,34 +4,24 @@
pub mod action;
use iced::{Limits, Size, Task};
use std::future::Future;
use std::any::Any;
use std::sync::Arc;
type BoxedSetting = Arc<Box<dyn Any + Send + Sync + 'static>>;
/// Ignore this message in your application. It will be intercepted.
#[derive(Clone)]
pub enum Action {
/// Create a subsurface with a view function accepting the App as a parameter
AppSubsurface(
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
),
AppSubsurface(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
/// Create a subsurface with a view function
Subsurface(
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
),
Subsurface(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
/// Destroy a subsurface with a view function
DestroySubsurface(iced::window::Id),
/// Create a popup with a view function accepting the App as a parameter
AppPopup(
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
),
AppPopup(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
/// Create a popup
Popup(
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
),
Popup(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
/// Destroy a subsurface with a view function
DestroyPopup(iced::window::Id),
/// Destroys the global tooltip popup subsurface
@ -40,29 +30,25 @@ pub enum Action {
/// Create a window with a view function accepting the App as a parameter
AppWindow(
iced::window::Id,
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
BoxedSetting,
BoxedSetting,
Option<BoxedSetting>,
),
/// Create a window with a view function
Window(
iced::window::Id,
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
BoxedSetting,
BoxedSetting,
Option<BoxedSetting>,
),
/// Destroy a window
DestroyWindow(iced::window::Id),
/// Create a layer shell surface with a view function accepting the App as a parameter
AppLayerShell(
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
),
AppLayerShell(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
/// Create a layer shell surface with a view function
LayerShell(
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
),
LayerShell(BoxedSetting, BoxedSetting, Option<BoxedSetting>),
/// Destroy a layer shell surface
DestroyLayerShell(iced::window::Id),
@ -89,21 +75,33 @@ impl std::fmt::Debug for Action {
#[cold]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::AppSubsurface(arg0, arg1) => f
Self::AppSubsurface(arg0, arg1, arg2) => f
.debug_tuple("AppSubsurface")
.field(arg0)
.field(arg1)
.field(arg2)
.finish(),
Self::Subsurface(arg0, arg1, arg2) => f
.debug_tuple("Subsurface")
.field(arg0)
.field(arg1)
.field(arg2)
.finish(),
Self::Subsurface(arg0, arg1) => {
f.debug_tuple("Subsurface").field(arg0).field(arg1).finish()
}
Self::DestroySubsurface(arg0) => {
f.debug_tuple("DestroySubsurface").field(arg0).finish()
}
Self::AppPopup(arg0, arg1) => {
f.debug_tuple("AppPopup").field(arg0).field(arg1).finish()
}
Self::Popup(arg0, arg1) => f.debug_tuple("Popup").field(arg0).field(arg1).finish(),
Self::AppPopup(arg0, arg1, arg2) => f
.debug_tuple("AppPopup")
.field(arg0)
.field(arg1)
.field(arg2)
.finish(),
Self::Popup(arg0, arg1, arg2) => f
.debug_tuple("Popup")
.field(arg0)
.field(arg1)
.field(arg2)
.finish(),
Self::DestroyPopup(arg0) => f.debug_tuple("DestroyPopup").field(arg0).finish(),
Self::DestroyTooltipPopup => f.debug_tuple("DestroyTooltipPopup").finish(),
Self::ResponsiveMenuBar {
@ -117,28 +115,34 @@ impl std::fmt::Debug for Action {
.field("size", size)
.finish(),
Self::Ignore => write!(f, "Ignore"),
Self::AppWindow(id, arg0, arg1) => f
Self::AppWindow(id, arg0, arg1, arg2) => f
.debug_tuple("AppWindow")
.field(id)
.field(arg0)
.field(arg1)
.field(arg2)
.finish(),
Self::Window(id, arg0, arg1) => f
Self::Window(id, arg0, arg1, arg2) => f
.debug_tuple("Window")
.field(id)
.field(arg0)
.field(arg1)
.field(arg2)
.finish(),
Self::DestroyWindow(arg0) => f.debug_tuple("DestroyWindow").field(arg0).finish(),
Self::Task(_) => f.debug_tuple("Future").finish(),
Self::AppLayerShell(any, any1) => f
Self::AppLayerShell(arg, arg1, arg2) => f
.debug_tuple("AppLayerShell")
.field(any)
.field(any1)
.field(arg)
.field(arg1)
.field(arg2)
.finish(),
Self::LayerShell(arg, arg1, arg2) => f
.debug_tuple("LayerShell")
.field(arg)
.field(arg1)
.field(arg2)
.finish(),
Self::LayerShell(any, any1) => {
f.debug_tuple("LayerShell").field(any).field(any1).finish()
}
Self::DestroyLayerShell(arg0) => {
f.debug_tuple("DestroyLayerShell").field(arg0).finish()
}