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_servicesmethod. - 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() })
}
}
Members
TYPEto_refinitializeregister_serviceson_framework_initialization_completeddata_context_propertyactual_theme_variant_propertyrequested_theme_variant_propertyname_propertyconstructnewdata_contextset_data_contextrequested_theme_variantset_requested_theme_variantactual_theme_variantis_theme_variant_rootcurrentbind_currentdata_templatesis_data_templates_initializedinput_managerresourcesset_resourcesstylesis_styles_initializedhas_resourcesstyling_parentapplication_lifetimeset_application_lifetimeplatform_settingsresources_changedactual_theme_variant_changedtry_get_resourcenameset_nametry_get_featuretry_getinitialize_theme_variantas_global_stylesas_style_hostas_resource_hostas_theme_variant_hostas_global_data_templatesas_optional_feature_provideras_theme_variant_rootas_data_context_providerrunrun_windowrun_with_tokenrun_with_main_window
TYPE
const TYPE: &'static $crate::TypeInfo
The runtime type of this class.
to_ref
fn to_ref(self: &Self) -> $crate::Ref<Application>
Returns a strong reference to this object.
initialize
fn initialize(self: &Self)
Initializes the application by loading its styles and resources.
register_services
fn register_services(self: &Self)
Registers the services needed by the framework.
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.
data_context_property
fn data_context_property() -> &'static StyledProperty<Option<BoxedValue>>
Defines the DataContext property.
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.
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.
name_property
fn name_property() -> &'static DirectProperty<Application, Option<String>>
Defines the Name property.
construct
fn construct() -> Self
Creates the class data; see FerroObject::construct.
new
fn new() -> Ref<Self>
Creates an instance of the Application class.
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.
set_data_context
fn set_data_context(self: &Self, value: Option<BoxedValue>)
Sets the application's data context.
requested_theme_variant
fn requested_theme_variant(self: &Self) -> Option<ThemeVariant>
The UI theme variant that is requested for the application.
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.
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.
is_theme_variant_root
fn is_theme_variant_root(self: &Self) -> bool
The application is the root of the theme variant resolution.
current
fn current() -> Option<Ref<Application>>
The current instance of the Application class: the application
registered with the service locator (see
bind_current).
bind_current
fn bind_current(application: Ref<Application>)
Registers application with the current service locator as the
application returned by current.
data_templates
fn data_templates(self: &Self) -> DataTemplates
The application's global data templates.
is_data_templates_initialized
fn is_data_templates_initialized(self: &Self) -> bool
Whether the data templates collection has been created.
input_manager
fn input_manager(self: &Self) -> Option<Rc<InputManager>>
The application's input manager, once the services have been registered.
resources
fn resources(self: &Self) -> Ref<ResourceDictionary>
The application's global resource dictionary.
set_resources
fn set_resources(self: &Self, value: Ref<ResourceDictionary>)
Sets the application's global resource dictionary.
styles
fn styles(self: &Self) -> Ref<Styles>
The application's global styles.
Global styles apply to all windows in the application.
is_styles_initialized
fn is_styles_initialized(self: &Self) -> bool
Whether the styles collection has been created.
has_resources
fn has_resources(self: &Self) -> bool
Whether the application or its styles have resources.
styling_parent
fn styling_parent(self: &Self) -> Option<StyleHostRef>
The styling parent of the application, which is None.
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.
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.
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.
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.
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.
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.
name
fn name(self: &Self) -> Option<String>
The application name to be used for various platform-specific purposes.
set_name
fn set_name(self: &Self, value: Option<String>)
Sets the application name.
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 IPlatformSettingsdyn IActivatableLifetime
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.
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.
as_global_styles
fn as_global_styles(self: &Self) -> Rc<dyn IGlobalStyles>
The application as the host of the global styles.
as_style_host
fn as_style_host(self: &Self) -> Rc<dyn IStyleHost>
The application as a style host.
as_resource_host
fn as_resource_host(self: &Self) -> Rc<dyn IResourceHost>
The application as a resource host.
as_theme_variant_host
fn as_theme_variant_host(self: &Self) -> Rc<dyn IThemeVariantHost>
The application as a theme variant host.
as_global_data_templates
fn as_global_data_templates(self: &Self) -> Rc<dyn IGlobalDataTemplates>
The application as the host of the global data templates.
as_optional_feature_provider
fn as_optional_feature_provider(self: &Self) -> Rc<dyn IOptionalFeatureProvider>
The application as a provider of optional features.
as_theme_variant_root
fn as_theme_variant_root(self: &Self) -> Rc<dyn IThemeVariantRoot>
The application as a theme variant root.
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.
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.
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.
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.
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.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeApplicationImplExtBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>ReceiverAnyFerroObjectImplExtClassDefaultsErasedDestructorIntoEitherDerefUpcast<T>Upcast<Application>StaticTypeObjectTypeSubclassable<T>DefaultConstructibleNewApplicationFerroObjectImplApplicationImpl
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.