truce_iced/lib.rs
1//! Iced GUI backend for truce plugins.
2//!
3//! An alternative GUI backend that replaces the built-in tiny-skia/wgpu
4//! renderer with [iced](https://github.com/iced-rs/iced), giving plugin
5//! authors access to a full retained-mode widget toolkit.
6//!
7//! # Usage Modes
8//!
9//! ## Auto mode - zero custom code
10//!
11//! ```rust,ignore
12//! fn editor(&mut self) -> Option<Box<dyn Editor>> {
13//! let layout = self.layout();
14//! Some(Box::new(IcedEditor::from_layout(self.params.clone(), layout)))
15//! }
16//! ```
17//!
18//! ## Custom mode - full iced control
19//!
20//! ```rust,ignore
21//! fn editor(&mut self) -> Option<Box<dyn Editor>> {
22//! Some(Box::new(IcedEditor::<_, MyIcedUi>::new(
23//! self.params.clone(),
24//! (600, 400),
25//! )))
26//! }
27//! ```
28
29pub mod auto_layout;
30#[cfg(not(target_os = "ios"))]
31pub mod editor;
32pub mod font;
33pub mod param_cache;
34pub mod param_message;
35#[cfg(not(target_os = "ios"))]
36pub mod platform;
37#[cfg(not(target_os = "ios"))]
38mod screenshot;
39pub mod theme;
40pub mod widgets;
41
42#[cfg(target_os = "ios")]
43mod editor_ios;
44
45// Re-export primary types for convenience.
46#[cfg(not(target_os = "ios"))]
47pub use editor::{AutoPlugin, IcedEditor, IcedPlugin};
48
49#[cfg(target_os = "ios")]
50pub use editor_ios::{AutoPlugin, IcedEditor, IcedPlugin};
51pub use param_cache::ParamCache;
52pub use param_message::{Message, ParamMessage};
53// Re-export `PluginContext` so plugin authors can use it without a direct
54// truce-core dependency.
55pub use truce_core::editor::PluginContext;
56
57// Re-export widget helper functions.
58pub use widgets::{
59 knob, meter, param_dropdown, param_selector, param_slider, param_toggle, xy_pad,
60};
61
62use iced::Element;
63use std::fmt::Debug;
64
65/// Convert any truce-iced widget into an `Element` with `.el()`.
66///
67/// Avoids the verbose `Into::<Element<'a, Message<M>>>::into(...)` pattern.
68///
69/// ```ignore
70/// Row::new()
71/// .push(knob(P::Gain, params).label("Gain").el())
72/// .push(knob(P::Pan, params).label("Pan").el())
73/// ```
74pub trait IntoElement<'a, M: Clone + Debug + 'static> {
75 fn el(self) -> Element<'a, Message<M>>;
76}
77
78impl<'a, M: Clone + Debug + 'static, T: Into<Element<'a, Message<M>>>> IntoElement<'a, M> for T {
79 fn el(self) -> Element<'a, Message<M>> {
80 self.into()
81 }
82}