ferroui_base/media/
cache_mode.rs1use crate::media::BitmapCache;
2use crate::utilities::FormatError;
3use crate::rendering::composition::{CompositionCacheMode, Compositor};
4use crate::{ferro_class, ferro_impl_classes, FerroObjectImpl, Ref, StyledElement, StyledElementImpl};
5use std::rc::Rc;
6
7#[repr(C)]
9pub struct CacheMode {
10 base: StyledElement,
11}
12
13ferro_class! {
14 CacheMode: StyledElement, virtuals CacheModeImpl: StyledElementImpl {
15 fn get_for_compositor(this, c: &Rc<Compositor>) -> Rc<CompositionCacheMode>;
19 }
20}
21ferro_impl_classes!(CacheMode: FerroObjectImpl, StyledElementImpl);
22
23impl CacheModeImpl for CacheMode {
24 fn get_for_compositor(_this: &Self, _c: &Rc<Compositor>) -> Rc<CompositionCacheMode> {
25 panic!("the cache mode class is abstract")
26 }
27}
28
29impl CacheMode {
30 pub fn construct() -> Self {
32 Self { base: StyledElement::construct() }
33 }
34
35 pub fn parse(s: &str) -> Result<Ref<CacheMode>, FormatError> {
37 if s == "BitmapCache" {
38 return Ok(BitmapCache::new().upcast());
39 }
40 Err(FormatError::from_string(format!("Unknown CacheMode: {s}")))
41 }
42}