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>
impl<T: Padded + 'static> Image<T>
Sourcepub fn new(
id: Arc<SourceID>,
props: T,
resource: &dyn Location,
size: DAbsPoint,
dynamic: bool,
) -> Self
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§
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> 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<U, C> ComponentWrap<U> for C
impl<U, C> ComponentWrap<U> for C
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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