pub(crate) mod create_widgets;
pub mod custom_paint;
pub use custom_paint::CustomPaintControlBackend;
pub(crate) const LABEL_PROPERTY_NAMES: &[&str] = &["text", "title", "message"];
pub(crate) const TOGGLE_BUTTON_KIND: crate::widget::WidgetKind = {
#[cfg(widgets_unstripped)]
{
crate::widget::WidgetKind::ToggleButton
}
#[cfg(not(widgets_unstripped))]
{
crate::widget::WidgetKind::Button
}
};
#[allow(dead_code)]
pub(crate) const MENU_KIND: crate::widget::WidgetKind = {
#[cfg(widgets_unstripped)]
{
crate::widget::WidgetKind::Menu
}
#[cfg(not(widgets_unstripped))]
{
crate::widget::WidgetKind::Panel
}
};
impl CustomPaintControlBackend {
pub(crate) fn mount_widget_of_kind(
&self,
kind: crate::widget::WidgetKind,
parent: crate::core::ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> crate::core::ObjectId {
#[cfg(not(full_widgets))]
{
let _ = (kind, parent, text, x, y, width, height);
log::warn!(
"custom backend: widgets cannot be created in this profile (no constructor \
registry is compiled in); returning 0"
);
0
}
#[cfg(full_widgets)]
{
let rect = crate::core::Rect::new(x, y, width, height);
let name = kind_factory_name(kind);
if name.is_empty() {
log::warn!(
"custom backend: {kind:?} has no resolvable constructor; returning 0 rather \
than an id that addresses nothing"
);
return 0;
}
let Some(mut widget) =
crate::widget::WidgetFactory::new_with_defaults().create(name, rect, text)
else {
log::warn!(
"custom backend: the factory lists {name:?} but produced no widget for \
{kind:?}; returning 0"
);
return 0;
};
if kind != crate::widget::WidgetKind::Window {
if parent == 0 || !crate::widget::runtime::is_mounted(parent) {
log::warn!(
"custom backend: refusing to create {kind:?} under parent {parent}, which \
addresses no live container"
);
return 0;
}
widget.set_parent(Some(parent));
}
crate::widget::runtime::register(widget).unwrap_or(0)
}
}
#[cfg(not(alloc_frugal))]
pub(crate) fn with_live_widget<R>(
&self,
widget_id: crate::core::ObjectId,
f: impl FnOnce(&mut dyn crate::widget::Widget) -> R,
) -> Option<R> {
#[cfg(not(alloc_frugal))]
{
crate::widget::runtime::with_widget_mut(widget_id, f)
}
#[cfg(alloc_frugal)]
{
let _ = (widget_id, f);
None
}
}
}
#[cfg(widgets_unstripped)]
#[allow(dead_code)]
pub(crate) fn kind_factory_name(kind: crate::widget::WidgetKind) -> &'static str {
crate::widget::capability::factory_name_for_kind(kind)
}
#[cfg(all(test, not(embedded_surface), widgets_unstripped))]
mod tests;