Skip to main content

Application

Struct Application 

Source
pub struct Application { /* private fields */ }
Expand description

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() })
    }
}

Implementations§

Source§

impl Application

Source

pub const TYPE: &'static TypeInfo = <Application as ::ferroui_base::StaticType>::TYPE

The runtime type of this class.

Source

pub fn to_ref(&self) -> Ref<Application>

Returns a strong reference to this object.

Source§

impl Application

Source

pub fn initialize(&self)

Initializes the application by loading its styles and resources.

Source

pub fn register_services(&self)

Registers the services needed by the framework.

Source

pub fn on_framework_initialization_completed(&self)

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

Source§

impl Application

Source

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

Defines the DataContext property.

Source

pub 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

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

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

Source

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

Defines the Name property.

Source§

impl Application

Source

pub fn construct() -> Self

Creates the class data; see FerroObject::construct.

Source

pub fn new() -> Ref<Self>

Creates an instance of the Application class.

Source

pub fn data_context(&self) -> Option<BoxedValue>

The application’s data context.

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

Source

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

Sets the application’s data context.

Source

pub fn requested_theme_variant(&self) -> Option<ThemeVariant>

The UI theme variant that is requested for the application.

Source

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

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

Source

pub fn actual_theme_variant(&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

pub fn is_theme_variant_root(&self) -> bool

The application is the root of the theme variant resolution.

Source

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

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

Source

pub fn bind_current(application: Ref<Application>)

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

Source

pub fn data_templates(&self) -> DataTemplates

The application’s global data templates.

Source

pub fn is_data_templates_initialized(&self) -> bool

Whether the data templates collection has been created.

Source

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

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

Source

pub fn resources(&self) -> Ref<ResourceDictionary>

The application’s global resource dictionary.

Source

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

Sets the application’s global resource dictionary.

Source

pub fn styles(&self) -> Ref<Styles>

The application’s global styles.

Global styles apply to all windows in the application.

Source

pub fn is_styles_initialized(&self) -> bool

Whether the styles collection has been created.

Source

pub fn has_resources(&self) -> bool

Whether the application or its styles have resources.

Source

pub fn styling_parent(&self) -> Option<StyleHostRef>

The styling parent of the application, which is None.

Source

pub fn application_lifetime(&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

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

Sets the application lifetime.

§Panics

Panics when the application has already been initialized.

Source

pub fn platform_settings(&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

pub fn resources_changed( &self, handler: impl Fn(&ResourcesChangedEventArgs) + 'static, ) -> Rc<dyn IDisposable>

Raised when the resources of the application change. Disposing the returned handle unsubscribes.

Source

pub fn actual_theme_variant_changed( &self, handler: impl Fn() + 'static, ) -> Rc<dyn IDisposable>

Raised when the actual theme variant of the application has changed. Disposing the returned handle unsubscribes.

Source

pub fn try_get_resource( &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

pub fn name(&self) -> Option<String>

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

Source

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

Sets the application name.

Source

pub fn try_get_feature(&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

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

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

Source

pub fn initialize_theme_variant(&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

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

The application as the host of the global styles.

Source

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

The application as a style host.

Source

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

The application as a resource host.

Source

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

The application as a theme variant host.

Source

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

The application as the host of the global data templates.

Source

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

The application as a provider of optional features.

Source

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

The application as a theme variant root.

Source

pub fn as_data_context_provider(&self) -> Rc<dyn IDataContextProvider>

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

Source§

impl Application

Source

pub fn run(&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

pub fn run_window(&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

pub fn run_with_token(&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

pub fn run_with_main_window<TWindow: ObjectType + Upcast<Window>>( &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.

Methods from Deref<Target = FerroObject>§

Source

pub fn dispatcher(&self) -> &Arc<Dispatcher> ⓘ

Returns the Dispatcher that this object is associated with: the dispatcher of the thread that owns the object.

Source

pub fn check_access(&self) -> bool

Returns whether the calling thread is the thread that owns this object.

Source

pub fn verify_access(&self)

Checks that the calling thread is the thread that owns this object.

§Panics

Panics when it is not.

Source

pub fn to_ref(&self) -> Ref<FerroObject>

A strong reference to this object.

Source

pub fn to_weak(&self) -> WeakRef<FerroObject>

A weak reference to this object.

Source

pub fn get_type(&self) -> &'static TypeInfo

The runtime type of the object.

Source

pub fn is<T>(&self) -> bool
where T: ObjectType,

Whether the object is of class T or a class derived from it.

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: ObjectType,

Returns the object viewed as class T if it is one.

Source

pub fn on_property_changed(&self, change: &FerroPropertyChangedEventArgs<'_>)

Invokes the on_property_changed virtual member.

Source

pub fn inheritance_parent(&self) -> Option<Ref<FerroObject>>

The parent object that inherited property values are inherited from.

Source

pub fn set_inheritance_parent(&self, value: impl Into<Nullable<FerroObject>>)

Sets the parent object that inherited property values are inherited from.

Source

pub fn clear_value<T>(&self, property: &'static StyledProperty<T>)
where T: PropertyValue,

Clears a property’s local value.

Source

pub fn get_value<T>(&self, property: &'static StyledProperty<T>) -> T
where T: PropertyValue,

Gets a property value.

Source

pub fn get_base_value<T>( &self, property: &'static StyledProperty<T>, ) -> Option<T>
where T: PropertyValue,

Gets a property’s base value: the value excluding animated values. Returns None if the value comes from inheritance or the default.

Source

pub fn is_animating(&self, property: &FerroProperty) -> bool

Checks whether a property is animating.

Source

pub fn is_set(&self, property: &FerroProperty) -> bool

Checks whether a styled property has a value assigned to it or a binding targeting it.

Source

pub fn set_value<T>(&self, property: &'static StyledProperty<T>, value: T)
where T: PropertyValue,

Sets a property value with local value priority.

Source

pub fn set_value_with_priority<T>( &self, property: &'static StyledProperty<T>, value: T, priority: BindingPriority, ) -> Option<Rc<dyn IDisposable>>
where T: PropertyValue,

Sets a property value with the given priority. For priorities other than local value, disposing the returned handle removes the value.

Source

pub fn set_current_value<T>( &self, property: &'static StyledProperty<T>, value: T, )
where T: PropertyValue,

Sets the value of a property without changing its value source.

This is used by a component that programmatically sets the value of one of its own properties without disabling an application’s declared use of the property: the effective value changes, but existing bindings and styles continue to work. The new value has the property’s current priority.

Source

pub fn bind_binding( &self, property: &'static FerroProperty, binding: &dyn BindingBase, ) -> Rc<dyn BindingExpressionBase>

Binds a property to a binding. Returns the binding expression which represents the binding instance on this object.

Source

pub fn bind_binding_with_anchor( &self, property: &'static FerroProperty, binding: &dyn BindingBase, anchor: Option<&Ref<FerroObject>>, ) -> Rc<dyn BindingExpressionBase>

Binds a property to a binding.

Some bindings need context to locate their source: a data context, named elements or resources. If this object is not an element, or is not yet attached to the tree, anchor provides that context.

Source

pub fn indexer(&self, binding: &IndexerDescriptor) -> IndexerBinding

Gets a binding to a property of this object: the indexer taking an IndexerDescriptor (source[!Property] is source.indexer(&Property.bind())).

Source

pub fn bind_indexer( &self, binding: &IndexerDescriptor, value: &dyn BindingBase, ) -> Rc<dyn BindingExpressionBase>

Binds the property of an IndexerDescriptor to a binding: the setter of the indexer (target[!Property] = binding is target.bind_indexer(&Property.bind(), &binding)).

Source

pub fn bind<T>( &self, property: &'static StyledProperty<T>, source: Rc<dyn IObservable<T>>, priority: BindingPriority, ) -> Rc<dyn IDisposable>
where T: PropertyValue,

Binds a property to an observable.

Source

pub fn bind_value<T>( &self, property: &'static StyledProperty<T>, source: Rc<dyn IObservable<BindingValue<T>>>, priority: BindingPriority, ) -> Rc<dyn IDisposable>
where T: PropertyValue,

Binds a property to an observable of binding values.

Source

pub fn bind_untyped<T>( &self, property: &'static StyledProperty<T>, source: Rc<dyn IObservable<Rc<dyn AnyValue>>>, priority: BindingPriority, ) -> Rc<dyn IDisposable>
where T: PropertyValue,

Binds a property to an observable of untyped values.

Source

pub fn coerce_value(&self, property: &'static FerroProperty)

Coerces the specified property.

Source

pub fn get_direct_value<T>(&self, property: &'static DirectPropertyBase<T>) -> T
where T: PropertyValue,

Gets a direct property value.

Source

pub fn set_direct_value<T>( &self, property: &'static DirectPropertyBase<T>, value: T, )
where T: PropertyValue,

Sets a direct property value.

Source

pub fn clear_direct_value<T>(&self, property: &'static DirectPropertyBase<T>)
where T: PropertyValue,

Resets a direct property to its unset value.

Source

pub fn bind_direct<T>( &self, property: &'static DirectPropertyBase<T>, source: Rc<dyn IObservable<T>>, ) -> Rc<dyn IDisposable>
where T: PropertyValue,

Binds a direct property to an observable.

Source

pub fn bind_direct_value<T>( &self, property: &'static DirectPropertyBase<T>, source: Rc<dyn IObservable<BindingValue<T>>>, ) -> Rc<dyn IDisposable>
where T: PropertyValue,

Binds a direct property to an observable of binding values.

Source

pub fn bind_direct_untyped<T>( &self, property: &'static DirectPropertyBase<T>, source: Rc<dyn IObservable<Rc<dyn AnyValue>>>, ) -> Rc<dyn IDisposable>
where T: PropertyValue,

Binds a direct property to an observable of untyped values.

Source

pub fn set_and_raise<T>( &self, property: &'static DirectPropertyBase<T>, field: &RefCell<T>, value: T, ) -> bool
where T: PropertyValue,

Sets the backing field of a direct property, raising a change notification if the value changed. Returns true if it changed.

Source

pub fn set_and_raise_cell<T>( &self, property: &'static DirectPropertyBase<T>, field: &Cell<T>, value: T, ) -> bool
where T: PropertyValue + Copy,

set_and_raise for Copy values stored in a Cell.

Source

pub fn get_value_untyped( &self, property: &'static FerroProperty, ) -> Rc<dyn AnyValue>

Gets a property value as an untyped value.

Source

pub fn set_value_untyped( &self, property: &'static FerroProperty, value: &(dyn Any + 'static), priority: BindingPriority, ) -> Option<Rc<dyn IDisposable>>

Sets a property from an untyped value, which must hold exactly the property’s value type or the unset marker.

Source

pub fn set_current_value_untyped( &self, property: &'static FerroProperty, value: &(dyn Any + 'static), )

set_current_value with an untyped value.

Source

pub fn clear_value_untyped(&self, property: &'static FerroProperty)

Clears a property’s local value.

Source

pub fn bind_property_untyped( &self, property: &'static FerroProperty, source: Rc<dyn IObservable<Rc<dyn AnyValue>>>, priority: BindingPriority, ) -> Rc<dyn IDisposable>

Binds a property to an observable of untyped values.

Source

pub fn property_changed( &self, handler: impl Fn(&FerroPropertyChangedEventArgs<'_>) + 'static, ) -> Rc<dyn IDisposable>

Subscribes to property changes on this object. Disposing the returned handle unsubscribes.

Source

pub fn add_property_changed_handler( &self, handler: Rc<dyn Fn(&FerroPropertyChangedEventArgs<'_>)>, ) -> u64

Subscribes handler to property changes on this object and returns the token that remove_property_changed_handler takes: property_changed for a subscriber that keeps the object and the token itself, so that no handle is made.

Source

pub fn remove_property_changed_handler(&self, token: u64) -> bool

Ends a subscription of add_property_changed_handler.

Source

pub fn property_changed_subscriber_count(&self) -> usize

The number of subscribers to property changes on this object (a diagnostics member, used by tests to verify that subscriptions are released).

Source

pub fn raise_property_changed<T>( &self, property: &'static FerroProperty, old_value: Option<&T>, new_value: &T, priority: BindingPriority, is_effective_value: bool, )
where T: PropertyValue,

Raises a property changed notification.

Source

pub fn raise_direct_property_changed<T>( &self, property: &'static DirectPropertyBase<T>, old_value: &T, new_value: &T, )
where T: PropertyValue,

Raises a property changed notification for a direct property.

Trait Implementations§

Source§

impl ApplicationImpl for Application

Source§

fn initialize(_this: &Self)

Initializes the application by loading its styles and resources.
Source§

fn register_services(this: &Self)

Registers the services needed by the framework.
Source§

fn on_framework_initialization_completed(_this: &Self)

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

impl Deref for Application

Source§

type Target = FerroObject

The resulting type after dereferencing.
Source§

fn deref(&self) -> &FerroObject

Dereferences the value.
Source§

impl FerroObjectImpl for Application

Source§

fn constructed(this: &Self)

Called once, right after the object has been allocated. This is where constructor logic that needs a reference to the object runs. Overrides must call parent_constructed first.
Source§

fn on_property_changed(this: &Self, change: &FerroPropertyChangedEventArgs<'_>)

Called when the effective value of a property changes on the object.
Source§

fn on_property_changed_core( this: &Self, change: &FerroPropertyChangedEventArgs<'_>, )

Called for every property change on the object, including changes of non-effective (base) values. Overriding this is rarely needed; override on_property_changed instead.
Source§

fn update_data_validation( this: &Self, property: &'static FerroProperty, state: BindingValueType, error: Option<&BindingError>, )

Called to update the validation state for properties for which data validation is enabled.
Source§

impl NewApplication for Application

Source§

fn new_application() -> Ref<Self>

Creates the application.
Source§

impl ObjectType for Application

Source§

type Parent = FerroObject

The base class. The root class is its own parent.
Source§

type VTable = ApplicationVTable

The virtual table of the class.
Source§

fn vtable() -> &'static Self::VTable

The virtual table used by instances whose most-derived class is Self.
Source§

fn register_class()

The static initialisation of the class. The first call on a thread, after doing the same for the base class: Read more
Source§

impl StaticType for Application

Source§

const TYPE: &'static TypeInfo

The runtime type.
Source§

impl<T: ApplicationImpl> Subclassable<T> for Application

Source§

impl Upcast<Application> for Application

Source§

impl<T: ?Sized> Upcast<T> for Application
where FerroObject: Upcast<T>,

Source§

fn upcast(&self) -> &T

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ApplicationImplExt for T
where T: ApplicationImpl,

Source§

fn parent_initialize(this: &Self)

Calls the base class implementation of the member.
Source§

fn parent_register_services(this: &Self)

Calls the base class implementation of the member.
Source§

fn parent_on_framework_initialization_completed(this: &Self)

Calls the base class implementation of the member.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> FerroObjectImplExt for T
where T: FerroObjectImpl,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.