pub struct DesktopIconData { /* private fields */ }Expand description
The desktop app’s identity and native-integration vocabulary, re-exported
from the desktop core so app code never names a shell crate:
DesktopConfig (the whole declaration — app name, reverse-DNS id, window
icon, menu bar, last-window-close policy — handed to App::desktop,
run_desktop_config or app!’s desktop = { .. } argument),
MenuSpec/MenuItemSpec/MenuRole (the platform-independent native
menu tree a per-OS shell translates into an NSApp menu bar or an HMENU),
DesktopIconData (decoded, tightly-packed RGBA8 — decoding a
PNG/ICO/ICNS is the caller’s job), and DEFAULT_APP_NAME (the window
title a config that names nothing still gets).
frust-shell-desktop‘s IconData is re-exported renamed: the facade
already carries frust-widgets’ IconData, an in-UI vector icon, and the
two are unrelated (one is a BezPath a widget paints, the other is the
window/taskbar bitmap the OS shows). The Desktop prefix matches
DesktopConfig, whose with_window_icon is its only consumer.
use frust::{DesktopConfig, MenuItemSpec, MenuRole, MenuSpec};
let file = MenuSpec::new()
.with_item(MenuItemSpec::item("file.open", "Open…").with_accelerator("CmdOrCtrl+O"))
.with_item(MenuItemSpec::separator())
.with_item(MenuItemSpec::role(MenuRole::Quit));
let config = DesktopConfig::new()
.with_app_name("Huddle")
.with_app_id("dev.frust.huddle")
.with_menu_spec(MenuSpec::new().with_item(MenuItemSpec::submenu("File", file)));Desktop-only, unlike the menu_events read side: these types are
defined in frust-shell-desktop, which is not in a mobile build’s or a
wasm32 build’s dependency graph at all (see this crate’s Cargo.toml).
Code shared with a mobile or wasm32 target keeps a DesktopConfig behind
its own
#[cfg(not(any(target_os = "android", target_os = "ios", target_arch = "wasm32")))]
— or, more simply, writes it inline in app!’s desktop = { .. }
argument, which the macro already emits only on the targets that have it.
A decoded window/app icon: tightly-packed, non-premultiplied RGBA8 rows,
top-to-bottom — the one representation every desktop platform can be fed
from (winit’s Icon::from_rgba, an NSImage bitmap rep, an HICON DIB).
Decoding a PNG/ICNS/ICO into this is the caller’s job: this crate carries no image decoder, and the tooling tier already owns the icon pipeline.
The rgba/width/height triple is an invariant, not three independent
fields (rgba.len() == width * height * 4), so the fields are private and
IconData::from_rgba is the only way in — an inconsistent icon reaches a
platform API as a buffer overrun, not a wrong picture.
Debug is hand-written rather than derived (see the manual impl below):
a derived one would dump the whole pixel buffer, drowning a log line in
thousands of byte values for even a small icon.
Implementations§
Source§impl IconData
impl IconData
Sourcepub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Option<IconData>
pub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Option<IconData>
Wrap decoded RGBA8 pixels, or None when they do not describe a
width × height image: either dimension is zero or exceeds
MAX_ICON_SIDE, or rgba.len() != width * height * 4.
Option rather than a <Type>Error enum because there is exactly one
failure mode and nothing to match on — and this crate carries no
thiserror dependency to add one with (version pins are law). The
caller that decoded the image is the one holding the context worth
reporting.
Check order matters. The dimension cap runs before the size
arithmetic below it, so a hostile width/height is rejected on a
cheap comparison rather than reaching the multiply (or, on a caller
that already allocated rgba to match, whatever cost that
allocation carried) at all.
Trait Implementations§
impl Eq for IconData
impl StructuralPartialEq for IconData
Auto Trait Implementations§
impl Freeze for IconData
impl RefUnwindSafe for IconData
impl Send for IconData
impl Sync for IconData
impl Unpin for IconData
impl UnsafeUnpin for IconData
impl UnwindSafe for IconData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.