Struct FlexBox

Source
pub struct FlexBox<T: Prop + 'static> {
    pub id: Arc<SourceID>,
    /* private fields */
}

Fields§

§id: Arc<SourceID>

Implementations§

Source§

impl<T: Prop + 'static> FlexBox<T>

Source

pub fn new( id: Arc<SourceID>, props: Rc<T>, children: Vector<Option<Box<ChildOf<dyn Prop>>>>, ) -> Self

Examples found in repository?
examples/list-rs.rs (lines 261-270)
125    fn call(
126        &mut self,
127        mut store: Self::Store,
128        args: &CounterState,
129    ) -> (Self::Store, im::HashMap<Arc<SourceID>, Option<Window>>) {
130        if store.0 != *args {
131            let button = {
132                let text = Text::<FixedData> {
133                    id: gen_id!(),
134                    props: FixedData {
135                        area: feather_ui::URect {
136                            abs: AbsRect::new(10.0, 15.0, 10.0, 15.0),
137                            rel: RelRect::new(0.0, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
138                        }
139                        .into(),
140                        anchor: feather_ui::RelPoint(Vec2 { x: 0.0, y: 0.0 }).into(),
141                        ..Default::default()
142                    }
143                    .into(),
144                    text: format!("Boxes: {}", args.count),
145                    font_size: 40.0,
146                    line_height: 56.0,
147                    ..Default::default()
148                };
149
150                let rect = Shape::<DRect, { ShapeKind::RoundRect as u8 }>::new(
151                    gen_id!(),
152                    feather_ui::FILL_DRECT.into(),
153                    0.0,
154                    0.0,
155                    Vec4::broadcast(10.0),
156                    sRGB::new(0.2, 0.7, 0.4, 1.0),
157                    sRGB::transparent(),
158                );
159
160                Button::<FixedData>::new(
161                    gen_id!(),
162                    FixedData {
163                        area: feather_ui::URect {
164                            abs: AbsRect::new(0.0, 20.0, 0.0, 0.0),
165                            rel: RelRect::new(0.5, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
166                        }
167                        .into(),
168                        anchor: feather_ui::RelPoint(Vec2 { x: 0.5, y: 0.0 }).into(),
169                        zindex: 0,
170                    },
171                    Slot(feather_ui::APP_SOURCE_ID.into(), 0),
172                    feather_ui::children![fixed::Prop, rect, text],
173                )
174            };
175
176            let rectlist = {
177                let mut children: im::Vector<Option<Box<ChildOf<dyn list::Prop>>>> =
178                    im::Vector::new();
179
180                let rect_id = gen_id!();
181
182                for i in 0..args.count {
183                    children.push_back(Some(Box::new(Shape::<
184                        ListChild,
185                        { ShapeKind::RoundRect as u8 },
186                    >::new(
187                        rect_id.child(DataID::Int(i as i64)),
188                        ListChild {
189                            area: AbsRect::new(0.0, 0.0, 40.0, 40.0).into(),
190                            margin: AbsRect::new(8.0, 8.0, 4.0, 4.0).into(),
191                        }
192                        .into(),
193                        0.0,
194                        0.0,
195                        Vec4::broadcast(8.0),
196                        sRGB::new(
197                            (0.1 * i as f32) % 1.0,
198                            (0.65 * i as f32) % 1.0,
199                            (0.2 * i as f32) % 1.0,
200                            1.0,
201                        ),
202                        sRGB::transparent(),
203                    ))));
204                }
205
206                ListBox::<ListData>::new(
207                    gen_id!(),
208                    ListData {
209                        area: feather_ui::URect {
210                            abs: AbsRect::new(0.0, 200.0, 0.0, 0.0),
211                            rel: RelRect::new(0.0, 0.0, UNSIZED_AXIS, 1.0),
212                        }
213                        .into(),
214                        rlimits: feather_ui::RelLimits::new(
215                            ZERO_POINT,
216                            Vec2::new(1.0, f32::INFINITY),
217                        ),
218                        direction: feather_ui::RowDirection::BottomToTop,
219                    }
220                    .into(),
221                    children,
222                )
223            };
224
225            let flexlist = {
226                let mut children: im::Vector<Option<Box<ChildOf<dyn flex::Prop>>>> =
227                    im::Vector::new();
228
229                let box_id = gen_id!();
230                for i in 0..args.count {
231                    children.push_back(Some(Box::new(Shape::<
232                        FlexChild,
233                        { ShapeKind::RoundRect as u8 },
234                    >::new(
235                        box_id.child(DataID::Int(i as i64)),
236                        FlexChild {
237                            area: feather_ui::URect {
238                                abs: AbsRect::new(0.0, 0.0, 0.0, 40.0),
239                                rel: RelRect::new(0.0, 0.0, 1.0, 0.0),
240                            }
241                            .into(),
242                            margin: AbsRect::new(8.0, 8.0, 4.0, 4.0).into(),
243                            basis: 40.0.into(),
244                            grow: 0.0,
245                            shrink: 0.0,
246                        }
247                        .into(),
248                        0.0,
249                        0.0,
250                        Vec4::broadcast(8.0),
251                        sRGB::new(
252                            (0.1 * i as f32) % 1.0,
253                            (0.65 * i as f32) % 1.0,
254                            (0.2 * i as f32) % 1.0,
255                            1.0,
256                        ),
257                        sRGB::transparent(),
258                    ))));
259                }
260
261                FlexBox::<MinimalFlex>::new(
262                    gen_id!(),
263                    MinimalFlex {
264                        area: (AbsRect::new(40.0, 40.0, 0.0, 200.0)
265                            + RelRect::new(0.0, 0.0, 1.0, 0.0))
266                        .into(),
267                    }
268                    .into(),
269                    children,
270                )
271            };
272
273            let region = Region::new(
274                gen_id!(),
275                FixedData {
276                    area: FILL_DRECT,
277                    zindex: 0,
278                    ..Default::default()
279                }
280                .into(),
281                feather_ui::children![fixed::Prop, button, flexlist, rectlist],
282            );
283            let window = Window::new(
284                gen_id!(),
285                feather_ui::winit::window::Window::default_attributes()
286                    .with_title(env!("CARGO_CRATE_NAME"))
287                    .with_resizable(true),
288                Box::new(region),
289            );
290
291            store.1 = im::HashMap::new();
292            store.1.insert(window.id.clone(), Some(window));
293            store.0 = args.clone();
294        }
295        let windows = store.1.clone();
296        (store, windows)
297    }

Trait Implementations§

Source§

impl<T: Prop + 'static> Clone for FlexBox<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: Prop + 'static> Component for FlexBox<T>

Source§

type Props = T

Source§

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

Source§

impl<T: Prop + 'static> StateMachineChild for FlexBox<T>

Source§

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

Source§

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

Source§

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

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> 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> 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