pub struct FlexBox<T> {
pub id: Arc<SourceID>,
/* private fields */
}
Fields§
§id: Arc<SourceID>
Implementations§
Source§impl<T: Prop + 'static> FlexBox<T>
impl<T: Prop + 'static> FlexBox<T>
Sourcepub fn new(
id: Arc<SourceID>,
props: T,
children: Vector<Option<Box<ChildOf<dyn Prop>>>>,
) -> Self
pub fn new( id: Arc<SourceID>, props: T, children: Vector<Option<Box<ChildOf<dyn Prop>>>>, ) -> Self
Examples found in repository?
examples/list-rs.rs (lines 270-277)
132 fn call(
133 &mut self,
134 mut store: Self::Store,
135 args: CounterState,
136 mut scope: ScopeID<'_>,
137 ) -> (Self::Store, im::HashMap<Arc<SourceID>, Option<Window>>) {
138 if store.0 != args {
139 let button = {
140 let text = Text::<FixedData> {
141 id: gen_id!(scope),
142 props: FixedData {
143 area: AbsRect::new(10.0, 15.0, 10.0, 15.0)
144 + RelRect::new(0.0, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
145
146 anchor: feather_ui::RelPoint::new(0.0, 0.0).into(),
147 ..Default::default()
148 }
149 .into(),
150 text: format!("Boxes: {}", args.count),
151 font_size: 40.0,
152 line_height: 56.0,
153 ..Default::default()
154 };
155
156 let rect = Shape::<DRect, { ShapeKind::RoundRect as u8 }>::new(
157 gen_id!(scope),
158 feather_ui::FILL_DRECT,
159 0.0,
160 0.0,
161 wide::f32x4::splat(10.0),
162 sRGB::new(0.2, 0.7, 0.4, 1.0),
163 sRGB::transparent(),
164 DAbsPoint::zero(),
165 );
166
167 Button::<FixedData>::new(
168 gen_id!(scope),
169 FixedData {
170 area: AbsRect::new(0.0, 20.0, 0.0, 0.0)
171 + RelRect::new(0.5, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
172
173 anchor: feather_ui::RelPoint::new(0.5, 0.0).into(),
174 zindex: 0,
175 },
176 Slot(feather_ui::APP_SOURCE_ID.into(), 0),
177 feather_ui::children![fixed::Prop, rect, text],
178 )
179 };
180
181 let rectlist = {
182 let mut children: im::Vector<Option<Box<ChildOf<dyn list::Prop>>>> =
183 im::Vector::new();
184
185 for (i, id) in scope.iter(0..args.count) {
186 children.push_back(Some(Box::new(Shape::<
187 ListChild,
188 { ShapeKind::RoundRect as u8 },
189 >::new(
190 id,
191 ListChild {
192 area: AbsRect::new(0.0, 0.0, 40.0, 40.0).into(),
193 margin: AbsRect::new(8.0, 8.0, 4.0, 4.0).into(),
194 },
195 0.0,
196 0.0,
197 wide::f32x4::splat(8.0),
198 sRGB::new(
199 (0.1 * i as f32) % 1.0,
200 (0.65 * i as f32) % 1.0,
201 (0.2 * i as f32) % 1.0,
202 1.0,
203 ),
204 sRGB::transparent(),
205 DAbsPoint::zero(),
206 ))));
207 }
208
209 ListBox::<ListData>::new(
210 gen_id!(scope),
211 ListData {
212 area: AbsRect::new(0.0, 200.0, 0.0, 0.0)
213 + RelRect::new(0.0, 0.0, UNSIZED_AXIS, 1.0),
214
215 rlimits: feather_ui::RelLimits::new(0.0..1.0, 0.0..),
216 direction: feather_ui::RowDirection::BottomToTop,
217 },
218 children,
219 )
220 };
221
222 let flexlist = {
223 let mut children: im::Vector<Option<Box<ChildOf<dyn flex::Prop>>>> =
224 im::Vector::new();
225
226 for (i, id) in scope.iter(0..args.count) {
227 let rect = Shape::<FlexChild, { ShapeKind::RoundRect as u8 }>::new(
228 gen_id!(id),
229 FlexChild {
230 area: AbsRect::new(0.0, 0.0, 0.0, 40.0)
231 + RelRect::new(0.0, 0.0, 1.0, 0.0),
232
233 margin: AbsRect::new(8.0, 8.0, 4.0, 4.0).into(),
234 basis: 40.0.into(),
235 grow: 0.0,
236 shrink: 0.0,
237 },
238 0.0,
239 0.0,
240 wide::f32x4::splat(8.0),
241 sRGB::new(
242 (0.1 * i as f32) % 1.0,
243 (0.65 * i as f32) % 1.0,
244 (0.2 * i as f32) % 1.0,
245 1.0,
246 ),
247 sRGB::transparent(),
248 DAbsPoint::zero(),
249 );
250
251 // We include a "useless" region around the rectangle because this catches some edge cases
252 // in the layout logic.
253 let reg = Region::<FlexChild>::new(
254 id,
255 FlexChild {
256 area: AbsRect::new(0.0, 0.0, 0.0, 40.0)
257 + RelRect::new(0.0, 0.0, 1.0, 0.0),
258
259 margin: AbsRect::new(8.0, 8.0, 4.0, 4.0).into(),
260 basis: 40.0.into(),
261 grow: 0.0,
262 shrink: 0.0,
263 },
264 feather_ui::children![fixed::Prop, rect],
265 );
266
267 children.push_back(Some(Box::new(reg)));
268 }
269
270 FlexBox::<MinimalFlex>::new(
271 gen_id!(scope),
272 MinimalFlex {
273 area: (AbsRect::new(40.0, 40.0, 0.0, 200.0)
274 + RelRect::new(0.0, 0.0, 1.0, 0.0)),
275 },
276 children,
277 )
278 };
279
280 let region = Region::new(
281 gen_id!(scope),
282 FixedData {
283 area: FILL_DRECT,
284 zindex: 0,
285 ..Default::default()
286 },
287 feather_ui::children![fixed::Prop, button, flexlist, rectlist],
288 );
289 let window = Window::new(
290 gen_id!(scope),
291 feather_ui::winit::window::Window::default_attributes()
292 .with_title(env!("CARGO_CRATE_NAME"))
293 .with_resizable(true),
294 Box::new(region),
295 );
296
297 store.1 = im::HashMap::new();
298 store.1.insert(window.id.clone(), Some(window));
299 store.0 = args.clone();
300 }
301 let windows = store.1.clone();
302 (store, windows)
303 }
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for FlexBox<T>
impl<T> !RefUnwindSafe for FlexBox<T>
impl<T> !Send for FlexBox<T>
impl<T> !Sync for FlexBox<T>
impl<T> Unpin for FlexBox<T>
impl<T> !UnwindSafe for FlexBox<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