FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    Application

    struct · ferroui-controls · v0.5.0

    struct Application
    

    Encapsulates a FerroUI application.

    The Application class encapsulates application-specific functionality, including:

    • A global set of data_templates.
    • A global set of styles.
    • An input manager.
    • Registers services needed by the rest of the framework in the register_services method.
    • Tracks the lifetime of the application.

    An application class derives from it and overrides the members of ApplicationImpl:

    #[repr(C)]
    pub struct App { base: Application }
    
    ferro_class!(App: Application);
    ferro_impl_classes!(App: FerroObjectImpl);
    
    impl ApplicationImpl for App {
        fn initialize(this: &Self) {
            this.styles().add(theme());
        }
    }
    
    impl NewApplication for App {
        fn new_application() -> Ref<Self> {
            instantiate(Self { base: Application::construct() })
        }
    }
    

    View source

    Members

    TYPE

    const TYPE: &'static $crate::TypeInfo
    

    The runtime type of this class.

    Source

    to_ref

    fn to_ref(self: &Self) -> $crate::Ref<Application>
    

    Returns a strong reference to this object.

    Source

    initialize

    fn initialize(self: &Self)
    

    Initializes the application by loading its styles and resources.

    Source

    register_services

    fn register_services(self: &Self)
    

    Registers the services needed by the framework.

    Source

    on_framework_initialization_completed

    fn on_framework_initialization_completed(self: &Self)
    

    Called when the framework has completed its initialization: the place to create the main window or view of the lifetime.

    Source

    data_context_property

    fn data_context_property() -> &'static StyledProperty<Option<BoxedValue>>
    

    Defines the DataContext property.

    Source

    actual_theme_variant_property

    fn actual_theme_variant_property() -> &'static StyledProperty<Option<ThemeVariant>>
    

    Defines the ActualThemeVariant property: the UI theme variant that is currently used by the application.

    Source

    requested_theme_variant_property

    fn requested_theme_variant_property() -> &'static StyledProperty<Option<ThemeVariant>>
    

    Defines the RequestedThemeVariant property: the UI theme variant that is requested for the application.

    Source

    name_property

    fn name_property() -> &'static DirectProperty<Application, Option<String>>
    

    Defines the Name property.

    Source

    construct

    fn construct() -> Self
    

    Creates the class data; see FerroObject::construct.

    Source

    new

    fn new() -> Ref<Self>
    

    Creates an instance of the Application class.

    Source

    data_context

    fn data_context(self: &Self) -> Option<BoxedValue>
    

    The application's data context.

    The data context property specifies the default object that will be used for data binding.

    Source

    set_data_context

    fn set_data_context(self: &Self, value: Option<BoxedValue>)
    

    Sets the application's data context.

    Source

    requested_theme_variant

    fn requested_theme_variant(self: &Self) -> Option<ThemeVariant>
    

    The UI theme variant that is requested for the application.

    Source

    set_requested_theme_variant

    fn set_requested_theme_variant(self: &Self, value: Option<ThemeVariant>)
    

    Sets the UI theme variant that is requested for the application.

    Source

    actual_theme_variant

    fn actual_theme_variant(self: &Self) -> Option<ThemeVariant>
    

    The UI theme variant that is currently used by the application.

    None until the services of the application have been registered.

    Source

    is_theme_variant_root

    fn is_theme_variant_root(self: &Self) -> bool
    

    The application is the root of the theme variant resolution.

    Source

    current

    fn current() -> Option<Ref<Application>>
    

    The current instance of the Application class: the application registered with the service locator (see bind_current).

    Source

    bind_current

    fn bind_current(application: Ref<Application>)
    

    Registers application with the current service locator as the application returned by current.

    Source

    data_templates

    fn data_templates(self: &Self) -> DataTemplates
    

    The application's global data templates.

    Source

    is_data_templates_initialized

    fn is_data_templates_initialized(self: &Self) -> bool
    

    Whether the data templates collection has been created.

    Source

    input_manager

    fn input_manager(self: &Self) -> Option<Rc<InputManager>>
    

    The application's input manager, once the services have been registered.

    Source

    resources

    fn resources(self: &Self) -> Ref<ResourceDictionary>
    

    The application's global resource dictionary.

    Source

    set_resources

    fn set_resources(self: &Self, value: Ref<ResourceDictionary>)
    

    Sets the application's global resource dictionary.

    Source

    styles

    fn styles(self: &Self) -> Ref<Styles>
    

    The application's global styles.

    Global styles apply to all windows in the application.

    Source

    is_styles_initialized

    fn is_styles_initialized(self: &Self) -> bool
    

    Whether the styles collection has been created.

    Source

    has_resources

    fn has_resources(self: &Self) -> bool
    

    Whether the application or its styles have resources.

    Source

    styling_parent

    fn styling_parent(self: &Self) -> Option<StyleHostRef>
    

    The styling parent of the application, which is None.

    Source

    application_lifetime

    fn application_lifetime(self: &Self) -> Option<Rc<dyn IApplicationLifetime>>
    

    The application lifetime; use it for things like setting the main window or view and exiting the application from code.

    Source

    set_application_lifetime

    fn set_application_lifetime(self: &Self, value: Option<Rc<dyn IApplicationLifetime>>)
    

    Sets the application lifetime.

    Panics

    Panics when the application has already been initialized.

    Source

    platform_settings

    fn platform_settings(self: &Self) -> Option<Rc<dyn IPlatformSettings>>
    

    The contract for accessing global platform-specific settings.

    It can be None only if the application wasn't initialized yet. The platform settings of a top-level are an equivalent which should always be preferred over the global one, as specific top-levels might have different settings set up.

    Source

    resources_changed

    fn resources_changed(self: &Self, handler: impl Fn(&ResourcesChangedEventArgs) -> () + 'static) -> Subscription
    

    Raised when the resources of the application change. Dropping the returned guard removes the handler; Subscription::detach keeps it for the life of the application.

    Source

    actual_theme_variant_changed

    fn actual_theme_variant_changed(self: &Self, handler: impl Fn() -> () + 'static) -> Subscription
    

    Raised when the actual theme variant of the application has changed. Dropping the returned guard removes the handler; Subscription::detach keeps it for the life of the application.

    Source

    try_get_resource

    fn try_get_resource(self: &Self, key: &ResourceKey, theme: Option<&ThemeVariant>) -> Option<ResourceValue>
    

    Tries to find a resource within the application: in its resource dictionary, then in its styles.

    Source

    name

    fn name(self: &Self) -> Option<String>
    

    The application name to be used for various platform-specific purposes.

    Source

    set_name

    fn set_name(self: &Self, value: Option<String>)
    

    Sets the application name.

    Source

    try_get_feature

    fn try_get_feature(self: &Self, feature_type: TypeId) -> Option<Rc<dyn Any>>
    

    Queries for an optional feature.

    feature_type is the TypeId of the feature's trait object type; the returned value holds the Rc<dyn ..> handle of the feature. Features currently supported:

    • dyn IPlatformSettings
    • dyn IActivatableLifetime

    Source

    try_get

    fn try_get<T: ?Sized + 'static>(self: &Self) -> Option<Rc<T>>
    

    Queries for an optional feature registered as Rc<T>; see try_get_feature.

    Source

    initialize_theme_variant

    fn initialize_theme_variant(self: &Self)
    

    Establishes the actual theme variant of the application and keeps it up to date with the color values of the platform settings.

    The subscription lasts as long as the platform settings do; it does not keep the application alive.

    Source

    as_global_styles

    fn as_global_styles(self: &Self) -> Rc<dyn IGlobalStyles>
    

    The application as the host of the global styles.

    Source

    as_style_host

    fn as_style_host(self: &Self) -> Rc<dyn IStyleHost>
    

    The application as a style host.

    Source

    as_resource_host

    fn as_resource_host(self: &Self) -> Rc<dyn IResourceHost>
    

    The application as a resource host.

    Source

    as_theme_variant_host

    fn as_theme_variant_host(self: &Self) -> Rc<dyn IThemeVariantHost>
    

    The application as a theme variant host.

    Source

    as_global_data_templates

    fn as_global_data_templates(self: &Self) -> Rc<dyn IGlobalDataTemplates>
    

    The application as the host of the global data templates.

    Source

    as_optional_feature_provider

    fn as_optional_feature_provider(self: &Self) -> Rc<dyn IOptionalFeatureProvider>
    

    The application as a provider of optional features.

    Source

    as_theme_variant_root

    fn as_theme_variant_root(self: &Self) -> Rc<dyn IThemeVariantRoot>
    

    The application as a theme variant root.

    Source

    as_data_context_provider

    fn as_data_context_provider(self: &Self) -> Rc<dyn ferroui_base::IDataContextProvider>
    

    The application as an element with a data context that can be used for binding.

    Source

    run

    fn run(self: &Self, closable: &dyn ICloseable)
    

    On desktop-style platforms runs the application's main loop until closable is closed.

    Consider using a classic desktop lifetime instead. Without run loops this returns right after subscribing to the closed event.

    Source

    run_window

    fn run_window(self: &Self, main_window: impl Into<Nullable<Window>>)
    

    On desktop-style platforms runs the application's main loop until the main window is closed. The window is shown if it is not visible.

    Consider using a classic desktop lifetime instead. Without run loops this returns right after showing the window, which stays alive until it is closed.

    Panics

    Panics when main_window is null.

    Source

    run_with_token

    fn run_with_token(self: &Self, token: &CancellationToken)
    

    On desktop-style platforms runs the application's main loop with a custom cancellation token, without setting a lifetime: the loop runs until token is canceled.

    Without run loops this does nothing and returns.

    Source

    run_with_main_window

    fn run_with_main_window<TWindow: ObjectType + Upcast<Window>>(self: &Self, new_window: impl FnOnce() -> Ref<TWindow>)
    

    Creates a window with new_window, shows it and runs the application's main loop until it is closed; see run_window.

    Source

    Trait implementations

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.