Image

Struct Image 

Source
pub struct Image<T> {
    pub id: Arc<SourceID>,
    pub props: Rc<T>,
    pub resource: Box<dyn Location>,
    pub size: DAbsPoint,
    pub dynamic: bool,
}

Fields§

§id: Arc<SourceID>§props: Rc<T>§resource: Box<dyn Location>§size: DAbsPoint§dynamic: bool

Implementations§

Source§

impl<T: Padded + 'static> Image<T>

Source

pub fn new( id: Arc<SourceID>, props: T, resource: &dyn Location, size: DAbsPoint, dynamic: bool, ) -> Self

Examples found in repository?
examples/image-rs.rs (lines 71-87)
45    fn call(
46        &mut self,
47        _: Self::Store,
48        _: (),
49        mut scope: ScopeID<'_>,
50    ) -> (Self::Store, im::HashMap<Arc<SourceID>, Option<Window>>) {
51        let pixel = Shape::<DRect, { ShapeKind::RoundRect as u8 }>::new(
52            scope.create(),
53            PxRect::new(1.0, 1.0, 2.0, 2.0).into(),
54            0.0,
55            0.0,
56            wide::f32x4::splat(0.0),
57            sRGB::new(1.0, 1.0, 1.0, 1.0),
58            sRGB::transparent(),
59            feather_ui::DAbsPoint::zero(),
60        );
61
62        let mut children: im::Vector<Option<Box<feather_ui::component::ChildOf<dyn fixed::Prop>>>> =
63            im::Vector::new();
64        children.push_back(Some(Box::new(pixel)));
65
66        let mut genimage = |pos: AbsPoint,
67                            w: Option<f32>,
68                            h: Option<f32>,
69                            res: &dyn feather_ui::resource::Location,
70                            size: Option<AbsPoint>| {
71            Image::<DRect>::new(
72                scope.create(),
73                AbsRect::new(
74                    pos.x,
75                    pos.y,
76                    w.map(|x| x + pos.x).unwrap_or_default(),
77                    h.map(|y| y + pos.y).unwrap_or_default(),
78                ) + RelRect::new(
79                    0.0,
80                    0.0,
81                    if w.is_none() { UNSIZED_AXIS } else { 0.0 },
82                    if h.is_none() { UNSIZED_AXIS } else { 0.0 },
83                ),
84                res,
85                size.unwrap_or_default().into(),
86                false,
87            )
88        };
89
90        #[cfg(feature = "png")]
91        {
92            let testimage = PathBuf::from("./premul_test.png");
93
94            children.push_back(Some(Box::new(genimage(
95                AbsPoint::new(0.0, 0.0),
96                Some(100.0),
97                Some(100.0),
98                &testimage,
99                None,
100            ))));
101
102            children.push_back(Some(Box::new(genimage(
103                AbsPoint::new(100.0, 0.0),
104                None,
105                Some(100.0),
106                &testimage,
107                None,
108            ))));
109
110            children.push_back(Some(Box::new(genimage(
111                AbsPoint::new(0.0, 100.0),
112                None,
113                None,
114                &testimage,
115                Some(AbsPoint::new(100.0, 100.0)),
116            ))));
117
118            children.push_back(Some(Box::new(genimage(
119                AbsPoint::new(100.0, 100.0),
120                None,
121                None,
122                &testimage,
123                None,
124            ))));
125        }
126
127        #[cfg(feature = "svg")]
128        {
129            let testsvg = PathBuf::from("./FRI_logo.svg");
130
131            children.push_back(Some(Box::new(genimage(
132                AbsPoint::new(200.0, 0.0),
133                Some(100.0),
134                Some(100.0),
135                &testsvg,
136                None,
137            ))));
138
139            children.push_back(Some(Box::new(genimage(
140                AbsPoint::new(300.0, 0.0),
141                None,
142                Some(100.0),
143                &testsvg,
144                None,
145            ))));
146
147            children.push_back(Some(Box::new(genimage(
148                AbsPoint::new(200.0, 100.0),
149                None,
150                None,
151                &testsvg,
152                Some(AbsPoint::new(100.0, 100.0)),
153            ))));
154
155            children.push_back(Some(Box::new(genimage(
156                AbsPoint::new(300.0, 100.0),
157                None,
158                None,
159                &testsvg,
160                None,
161            ))));
162        }
163
164        #[cfg(feature = "png")]
165        {
166            let testimage = PathBuf::from("./test_color.png");
167
168            children.push_back(Some(Box::new(genimage(
169                AbsPoint::new(0.0, 200.0),
170                Some(100.0),
171                Some(100.0),
172                &testimage,
173                None,
174            ))));
175
176            children.push_back(Some(Box::new(genimage(
177                AbsPoint::new(100.0, 200.0),
178                Some(100.0),
179                None,
180                &testimage,
181                None,
182            ))));
183
184            children.push_back(Some(Box::new(genimage(
185                AbsPoint::new(0.0, 300.0),
186                None,
187                None,
188                &testimage,
189                Some(AbsPoint::new(100.0, 100.0)),
190            ))));
191
192            children.push_back(Some(Box::new(genimage(
193                AbsPoint::new(100.0, 300.0),
194                None,
195                None,
196                &testimage,
197                None,
198            ))));
199        }
200
201        #[cfg(feature = "jxl")]
202        {
203            let testimage = PathBuf::from("./dice.jxl");
204
205            children.push_back(Some(Box::new(genimage(
206                AbsPoint::new(200.0, 200.0),
207                Some(100.0),
208                Some(100.0),
209                &testimage,
210                None,
211            ))));
212
213            children.push_back(Some(Box::new(genimage(
214                AbsPoint::new(300.0, 200.0),
215                Some(100.0),
216                None,
217                &testimage,
218                None,
219            ))));
220
221            children.push_back(Some(Box::new(genimage(
222                AbsPoint::new(200.0, 300.0),
223                None,
224                None,
225                &testimage,
226                Some(AbsPoint::new(100.0, 100.0)),
227            ))));
228
229            children.push_back(Some(Box::new(genimage(
230                AbsPoint::new(300.0, 300.0),
231                None,
232                None,
233                &testimage,
234                None,
235            ))));
236        }
237
238        let region = Region::new(
239            gen_id!(scope),
240            FixedData {
241                area: AbsRect::new(10.0, 10.0, -10.0, -10.0) + RelRect::new(0.0, 0.0, 1.0, 1.0),
242
243                zindex: 0,
244                ..Default::default()
245            },
246            children,
247        );
248
249        #[cfg(feature = "svg")]
250        let icon = Some(
251            feather_ui::resource::load_icon(&std::path::PathBuf::from("./FRI_logo.svg")).unwrap(),
252        );
253        #[cfg(not(feature = "svg"))]
254        let icon = None;
255
256        let window = Window::new(
257            gen_id!(scope),
258            winit::window::Window::default_attributes()
259                .with_title(env!("CARGO_CRATE_NAME"))
260                .with_resizable(true)
261                .with_window_icon(icon),
262            Box::new(region),
263        );
264
265        let mut store = im::HashMap::new();
266        store.insert(window.id.clone(), Some(window));
267        let windows = store.clone();
268        (store, windows)
269    }

Trait Implementations§

Source§

impl<T> Clone for Image<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Padded + 'static> Component for Image<T>
where for<'a> &'a T: Into<&'a (dyn Padded + 'static)>,

Source§

type Props = T

Source§

fn layout( &self, manager: &mut StateManager, driver: &Driver, window: &Arc<SourceID>, ) -> Box<dyn Layout<T>>

Source§

impl<T> StateMachineChild for Image<T>

Source§

fn id(&self) -> Arc<SourceID>

Source§

fn init( &self, driver: &Weak<Driver>, ) -> Result<Box<dyn StateMachineWrapper>, Error>

Source§

fn apply_children( &self, _: &mut dyn FnMut(&dyn StateMachineChild) -> Result<()>, ) -> Result<()>

Auto Trait Implementations§

§

impl<T> Freeze for Image<T>

§

impl<T> !RefUnwindSafe for Image<T>

§

impl<T> !Send for Image<T>

§

impl<T> !Sync for Image<T>

§

impl<T> Unpin for Image<T>

§

impl<T> !UnwindSafe for Image<T>

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<U, C> ComponentWrap<U> for C
where C: Component, &'a U: for<'a> From<&'a <C as Component>::Props>, <C as Component>::Props: Sized, U: ?Sized,

Source§

fn layout( &self, state: &mut StateManager, driver: &Driver, window: &Arc<SourceID>, ) -> Box<dyn Layout<U>>

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T