pub struct Context {
pub tree: Tree<Entity>,
pub tree_updates: Vec<Option<TreeUpdate>>,
pub windows: HashMap<Entity, WindowState>,
pub mouse: MouseState<Entity>,
pub text_context: TextContext,
pub ignore_default_theme: bool,
pub window_has_focus: bool,
pub ime_state: ImeState,
/* private fields */
}Expand description
The main storage and control object for a Vizia application.
Fields§
§tree: Tree<Entity>§tree_updates: Vec<Option<TreeUpdate>>§windows: HashMap<Entity, WindowState>§mouse: MouseState<Entity>§text_context: TextContext§ignore_default_theme: bool§window_has_focus: bool§ime_state: ImeStateImplementations§
Source§impl Context
impl Context
Sourcepub fn current(&self) -> Entity
pub fn current(&self) -> Entity
The “current” entity, generally the entity which is currently being built or the entity which is currently having an event dispatched to it.
Sourcepub fn with_current<T>(
&mut self,
current: Entity,
f: impl FnOnce(&mut Context) -> T,
) -> T
pub fn with_current<T>( &mut self, current: Entity, f: impl FnOnce(&mut Context) -> T, ) -> T
Makes the above black magic more explicit
Sourcepub fn environment(&self) -> &Environment
pub fn environment(&self) -> &Environment
Returns a reference to the Environment model.
Sourcepub fn parent_window(&self) -> Entity
pub fn parent_window(&self) -> Entity
Returns the entity id of the parent window to the current view.
Sourcepub fn scale_factor(&self) -> f32
pub fn scale_factor(&self) -> f32
Returns the scale factor of the display.
Sourcepub fn needs_redraw(&mut self, entity: Entity)
pub fn needs_redraw(&mut self, entity: Entity)
Mark the application as needing to rerun the draw method
Sourcepub fn needs_restyle(&mut self, entity: Entity)
pub fn needs_restyle(&mut self, entity: Entity)
Mark the application as needing to recompute view styles
pub fn needs_retransform(&mut self, entity: Entity)
pub fn needs_reclip(&mut self, entity: Entity)
Sourcepub fn needs_relayout(&mut self)
pub fn needs_relayout(&mut self)
Mark the application as needing to rerun layout computations
Sourcepub fn focus_with_visibility(&mut self, focus_visible: bool)
pub fn focus_with_visibility(&mut self, focus_visible: bool)
Sets application focus to the current entity with the specified focus visiblity
Sourcepub fn focus(&mut self)
pub fn focus(&mut self)
Sets application focus to the current entity using the previous focus visibility
Sourcepub fn toggle_class(&mut self, name: &str, applied: impl Res<bool>)
pub fn toggle_class(&mut self, name: &str, applied: impl Res<bool>)
Sets whether a view should have the given class name.
Sourcepub fn add_listener<F, W>(&mut self, listener: F)
pub fn add_listener<F, W>(&mut self, listener: F)
Add a listener to an entity.
A listener can be used to handle events which would not normally propagate to the entity. For example, mouse events when a different entity has captured them. Useful for things like closing a popup when clicking outside of its bounding box.
Sourcepub fn add_global_listener<F>(&mut self, listener: F)
pub fn add_global_listener<F>(&mut self, listener: F)
Adds a global listener to the application.
Global listeners have the first opportunity to handle every event that is sent in an
application. They will never be removed. If you need a listener tied to the lifetime of a
view, use add_listener.
Sourcepub fn add_font_mem(&mut self, data: impl AsRef<[u8]>)
pub fn add_font_mem(&mut self, data: impl AsRef<[u8]>)
Adds a font to the application from memory.
pub fn add_stylesheet(&mut self, style: impl IntoCssStr) -> Result<(), Error>
Sourcepub fn add_built_in_styles(&mut self)
pub fn add_built_in_styles(&mut self)
Remove all user themes from the application.
Sourcepub fn add_built_in_translations(&mut self)
pub fn add_built_in_translations(&mut self)
Adds built-in translations for default view strings.
pub fn add_animation(&mut self, animation: AnimationBuilder<'_>) -> Animation
pub fn set_image_loader<F: 'static + Fn(&mut ResourceContext<'_>, &str)>( &mut self, loader: F, )
Sourcepub fn add_translation(
&mut self,
lang: LanguageIdentifier,
ftl: impl ToString,
) -> Result<(), TranslationError>
pub fn add_translation( &mut self, lang: LanguageIdentifier, ftl: impl ToString, ) -> Result<(), TranslationError>
Adds a translation to the application for the provided language.
Returns an error if the FTL syntax is invalid or the resource cannot be added to the bundle.
Sourcepub fn add_timer(
&mut self,
interval: Duration,
duration: Option<Duration>,
callback: impl Fn(&mut EventContext<'_>, TimerAction) + 'static,
) -> Timer
pub fn add_timer( &mut self, interval: Duration, duration: Option<Duration>, callback: impl Fn(&mut EventContext<'_>, TimerAction) + 'static, ) -> Timer
Adds a timer to the application.
interval - The time between ticks of the timer.
duration - An optional duration for the timer. Pass None for a continuos timer.
callback - A callback which is called on when the timer is started, ticks, and stops. Disambiguated by the TimerAction parameter of the callback.
Returns a Timer id which can be used to start and stop the timer.
§Example
Creates a timer which calls the provided callback every second for 5 seconds:
let timer = cx.add_timer(Duration::from_secs(1), Some(Duration::from_secs(5)), |cx, reason|{
match reason {
TimerAction::Start => {
debug!("Start timer");
}
TimerAction::Tick(delta) => {
debug!("Tick timer: {:?}", delta);
}
TimerAction::Stop => {
debug!("Stop timer");
}
}
});Sourcepub fn start_timer(&mut self, timer: Timer)
pub fn start_timer(&mut self, timer: Timer)
Starts a timer with the provided timer id.
Events sent within the timer callback provided in add_timer() will target the current view.
Sourcepub fn modify_timer(
&mut self,
timer: Timer,
timer_function: impl Fn(&mut TimerState),
)
pub fn modify_timer( &mut self, timer: Timer, timer_function: impl Fn(&mut TimerState), )
Modifies the state of an existing timer with the provided Timer id.
Sourcepub fn timer_is_running(&mut self, timer: Timer) -> bool
pub fn timer_is_running(&mut self, timer: Timer) -> bool
Returns true if the timer with the provided timer id is currently running.
Sourcepub fn stop_timer(&mut self, timer: Timer)
pub fn stop_timer(&mut self, timer: Timer)
Stops the timer with the given timer id.
Any events emitted in response to the timer stopping, as determined by the callback provided in add_timer(), will target the view which called start_timer().
Sourcepub fn load_image(
&mut self,
path: &str,
data: &'static [u8],
policy: ImageRetentionPolicy,
)
pub fn load_image( &mut self, path: &str, data: &'static [u8], policy: ImageRetentionPolicy, )
Loads an image from memory and associates it with the provided path.
pub fn load_svg( &mut self, path: &str, data: &[u8], policy: ImageRetentionPolicy, ) -> ImageId
pub fn spawn<F>(&self, target: F)
pub fn get_proxy(&self) -> ContextProxy
pub fn set_ime_state(&mut self, new_state: ImeState)
Trait Implementations§
Source§impl DataContext for Context
impl DataContext for Context
Source§fn try_data<T: 'static>(&self) -> Option<&T>
fn try_data<T: 'static>(&self) -> Option<&T>
None if the data does not exist.Source§fn localization_context(&self) -> Option<LocalizationContext<'_>>
fn localization_context(&self) -> Option<LocalizationContext<'_>>
Source§impl EmitContext for Context
impl EmitContext for Context
Source§fn emit<M: Any + Send>(&mut self, message: M)
fn emit<M: Any + Send>(&mut self, message: M)
Source§fn emit_to<M: Any + Send>(&mut self, target: Entity, message: M)
fn emit_to<M: Any + Send>(&mut self, target: Entity, message: M)
Source§fn emit_custom(&mut self, event: Event)
fn emit_custom(&mut self, event: Event)
Source§fn schedule_emit<M: Any + Send>(
&mut self,
message: M,
at: Instant,
) -> TimedEventHandle
fn schedule_emit<M: Any + Send>( &mut self, message: M, at: Instant, ) -> TimedEventHandle
Source§fn schedule_emit_to<M: Any + Send>(
&mut self,
target: Entity,
message: M,
at: Instant,
) -> TimedEventHandle
fn schedule_emit_to<M: Any + Send>( &mut self, target: Entity, message: M, at: Instant, ) -> TimedEventHandle
Source§fn schedule_emit_custom(
&mut self,
event: Event,
at: Instant,
) -> TimedEventHandle
fn schedule_emit_custom( &mut self, event: Event, at: Instant, ) -> TimedEventHandle
Source§fn cancel_scheduled(&mut self, handle: TimedEventHandle)
fn cancel_scheduled(&mut self, handle: TimedEventHandle)
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl !Send for Context
impl !Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.