#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
#![warn(missing_docs)]
#![deny(unsafe_code)]
#![doc(html_logo_url = "https://slint-ui.com/logo/slint-logo-square-light.svg")]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
#[cfg(not(feature = "compat-0-2-0"))]
compile_error!(
"The feature `compat-0-2-0` must be enabled to ensure \
forward compatibility with future version of this crate"
);
pub use slint_macros::slint;
pub use i_slint_core::api::*;
pub use i_slint_core::graphics::{
Brush, Color, Image, LoadImageError, Rgb8Pixel, Rgba8Pixel, RgbaColor, SharedPixelBuffer,
};
pub use i_slint_core::model::{
Model, ModelExt, ModelNotify, ModelPeer, ModelRc, ModelTracker, StandardListViewItem, VecModel,
};
pub use i_slint_core::sharedvector::SharedVector;
pub use i_slint_core::string::SharedString;
pub use i_slint_core::timers::{Timer, TimerMode};
#[doc(hidden)]
#[cfg(feature = "std")]
pub fn register_font_from_memory(data: &'static [u8]) -> Result<(), Box<dyn std::error::Error>> {
i_slint_backend_selector::backend().register_font_from_memory(data)
}
#[doc(hidden)]
#[cfg(feature = "std")]
pub fn register_font_from_path<P: AsRef<std::path::Path>>(
path: P,
) -> Result<(), Box<dyn std::error::Error>> {
i_slint_backend_selector::backend().register_font_from_path(path.as_ref())
}
#[doc(hidden)]
pub mod re_exports {
pub use alloc::boxed::Box;
pub use alloc::format;
pub use alloc::rc::{Rc, Weak};
pub use alloc::string::String;
pub use alloc::{vec, vec::Vec};
pub use const_field_offset::{self, FieldOffsets, PinnedDrop};
pub use core::iter::FromIterator;
pub use i_slint_backend_selector::native_widgets::*;
pub use i_slint_core::animations::EasingCurve;
pub use i_slint_core::callbacks::Callback;
pub use i_slint_core::component::{
free_component_item_graphics_resources, init_component_items, Component, ComponentRefPin,
ComponentVTable, ComponentWeak, IndexRange,
};
pub use i_slint_core::graphics::*;
pub use i_slint_core::input::{
FocusEvent, InputEventResult, KeyEvent, KeyEventResult, KeyboardModifiers, MouseEvent,
};
pub use i_slint_core::item_tree::{
visit_item_tree, ItemTreeNode, ItemVisitorRefMut, ItemVisitorVTable, ItemWeak,
TraversalOrder, VisitChildrenResult,
};
pub use i_slint_core::items::*;
pub use i_slint_core::layout::*;
pub use i_slint_core::model::*;
pub use i_slint_core::properties::{set_state_binding, Property, PropertyTracker, StateInfo};
pub use i_slint_core::slice::Slice;
pub use i_slint_core::window::{Window, WindowHandleAccess, WindowRc};
pub use i_slint_core::Color;
pub use i_slint_core::ComponentVTable_static;
pub use i_slint_core::Coord;
pub use i_slint_core::SharedString;
pub use i_slint_core::SharedVector;
pub use num_traits::float::Float;
pub use once_cell::race::OnceBox;
pub use once_cell::unsync::OnceCell;
pub use pin_weak::rc::PinWeak;
pub use vtable::{self, *};
}
#[doc(hidden)]
pub mod internal {
use crate::re_exports::*;
use alloc::rc::Rc;
use core::pin::Pin;
pub trait StrongComponentRef: Sized {
type Weak: Clone + 'static;
fn to_weak(&self) -> Self::Weak;
fn from_weak(weak: &Self::Weak) -> Option<Self>;
}
impl<C: 'static> StrongComponentRef for VRc<ComponentVTable, C> {
type Weak = VWeak<ComponentVTable, C>;
fn to_weak(&self) -> Self::Weak {
VRc::downgrade(self)
}
fn from_weak(weak: &Self::Weak) -> Option<Self> {
weak.upgrade()
}
}
impl<C: 'static> StrongComponentRef for VRcMapped<ComponentVTable, C> {
type Weak = VWeakMapped<ComponentVTable, C>;
fn to_weak(&self) -> Self::Weak {
VRcMapped::downgrade(self)
}
fn from_weak(weak: &Self::Weak) -> Option<Self> {
weak.upgrade()
}
}
impl<C: 'static> StrongComponentRef for Pin<Rc<C>> {
type Weak = PinWeak<C>;
fn to_weak(&self) -> Self::Weak {
PinWeak::downgrade(self.clone())
}
fn from_weak(weak: &Self::Weak) -> Option<Self> {
weak.upgrade()
}
}
pub fn set_property_binding<T: Clone + 'static, StrongRef: StrongComponentRef + 'static>(
property: Pin<&Property<T>>,
component_strong: &StrongRef,
binding: fn(StrongRef) -> T,
) {
let weak = component_strong.to_weak();
property.set_binding(move || {
binding(<StrongRef as StrongComponentRef>::from_weak(&weak).unwrap())
})
}
pub fn set_animated_property_binding<
T: Clone + i_slint_core::properties::InterpolatedPropertyValue + 'static,
StrongRef: StrongComponentRef + 'static,
>(
property: Pin<&Property<T>>,
component_strong: &StrongRef,
binding: fn(StrongRef) -> T,
animation_data: PropertyAnimation,
) {
let weak = component_strong.to_weak();
property.set_animated_binding(
move || binding(<StrongRef as StrongComponentRef>::from_weak(&weak).unwrap()),
animation_data,
)
}
pub fn set_animated_property_binding_for_transition<
T: Clone + i_slint_core::properties::InterpolatedPropertyValue + 'static,
StrongRef: StrongComponentRef + 'static,
>(
property: Pin<&Property<T>>,
component_strong: &StrongRef,
binding: fn(StrongRef) -> T,
compute_animation_details: fn(
StrongRef,
)
-> (PropertyAnimation, i_slint_core::animations::Instant),
) {
let weak_1 = component_strong.to_weak();
let weak_2 = weak_1.clone();
property.set_animated_binding_for_transition(
move || binding(<StrongRef as StrongComponentRef>::from_weak(&weak_1).unwrap()),
move || {
compute_animation_details(
<StrongRef as StrongComponentRef>::from_weak(&weak_2).unwrap(),
)
},
)
}
pub fn set_property_state_binding<StrongRef: StrongComponentRef + 'static>(
property: Pin<&Property<StateInfo>>,
component_strong: &StrongRef,
binding: fn(StrongRef) -> i32,
) {
let weak = component_strong.to_weak();
crate::re_exports::set_state_binding(property, move || {
binding(<StrongRef as StrongComponentRef>::from_weak(&weak).unwrap())
})
}
pub fn set_callback_handler<
Arg: ?Sized + 'static,
Ret: Default + 'static,
StrongRef: StrongComponentRef + 'static,
>(
callback: Pin<&Callback<Arg, Ret>>,
component_strong: &StrongRef,
handler: fn(StrongRef, &Arg) -> Ret,
) {
let weak = component_strong.to_weak();
callback.set_handler(move |arg| {
handler(<StrongRef as StrongComponentRef>::from_weak(&weak).unwrap(), arg)
})
}
#[doc(hidden)]
pub fn register_bitmap_font(font_data: &'static super::re_exports::BitmapFont) {
i_slint_backend_selector::backend().register_bitmap_font(font_data)
}
}
#[doc(hidden)]
pub fn create_window() -> re_exports::WindowRc {
i_slint_backend_selector::backend().create_window()
}
pub fn run_event_loop() {
i_slint_backend_selector::backend()
.run_event_loop(i_slint_core::backend::EventLoopQuitBehavior::QuitOnLastWindowClosed);
}
pub fn quit_event_loop() {
i_slint_backend_selector::backend().quit_event_loop();
}
#[cfg(feature = "std")]
pub mod testing {
use core::cell::Cell;
thread_local!(static KEYBOARD_MODIFIERS : Cell<crate::re_exports::KeyboardModifiers> = Default::default());
use super::ComponentHandle;
pub use i_slint_core::tests::slint_mock_elapsed_time as mock_elapsed_time;
pub fn send_mouse_click<
X: vtable::HasStaticVTable<i_slint_core::component::ComponentVTable>
+ crate::re_exports::WindowHandleAccess
+ 'static,
Component: Into<vtable::VRc<i_slint_core::component::ComponentVTable, X>> + ComponentHandle,
>(
component: &Component,
x: f32,
y: f32,
) {
let rc = component.clone_strong().into();
let dyn_rc = vtable::VRc::into_dyn(rc.clone());
i_slint_core::tests::slint_send_mouse_click(&dyn_rc, x, y, &rc.window_handle().clone());
}
pub fn set_current_keyboard_modifiers<
X: vtable::HasStaticVTable<i_slint_core::component::ComponentVTable>
+ crate::re_exports::WindowHandleAccess,
Component: Into<vtable::VRc<i_slint_core::component::ComponentVTable, X>> + ComponentHandle,
>(
_component: &Component,
modifiers: crate::re_exports::KeyboardModifiers,
) {
KEYBOARD_MODIFIERS.with(|x| x.set(modifiers))
}
pub fn send_keyboard_string_sequence<
X: vtable::HasStaticVTable<i_slint_core::component::ComponentVTable>
+ crate::re_exports::WindowHandleAccess,
Component: Into<vtable::VRc<i_slint_core::component::ComponentVTable, X>> + ComponentHandle,
>(
component: &Component,
sequence: &str,
) {
let component = component.clone_strong().into();
i_slint_core::tests::send_keyboard_string_sequence(
&super::SharedString::from(sequence),
KEYBOARD_MODIFIERS.with(|x| x.get()),
&component.window_handle().clone(),
)
}
pub fn set_window_scale_factor<
X: vtable::HasStaticVTable<i_slint_core::component::ComponentVTable>
+ crate::re_exports::WindowHandleAccess,
Component: Into<vtable::VRc<i_slint_core::component::ComponentVTable, X>> + ComponentHandle,
>(
component: &Component,
factor: f32,
) {
let component = component.clone_strong().into();
component.window_handle().set_scale_factor(factor)
}
}
#[macro_export]
macro_rules! include_modules {
() => {
include!(env!("SLINT_INCLUDE_GENERATED"));
};
}
#[doc(hidden)]
#[allow(non_camel_case_types)]
pub struct VersionCheck_0_2_2;
#[cfg(doctest)]
mod compile_fail_tests;
#[cfg(doc)]
pub mod docs;