pub struct GridBox<T> {
pub id: Arc<SourceID>,
/* private fields */
}
Fields§
§id: Arc<SourceID>
Implementations§
Source§impl<T: Prop + 'static> GridBox<T>
impl<T: Prop + 'static> GridBox<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/grid-rs.rs (lines 189-205)
109 fn call(
110 &mut self,
111 mut store: Self::Store,
112 args: CounterState,
113 mut scope: ScopeID<'_>,
114 ) -> (Self::Store, im::HashMap<Arc<SourceID>, Option<Window>>) {
115 if store.0 != args {
116 let button = {
117 let text = {
118 Text::<FixedData> {
119 id: scope.create(),
120 props: FixedData {
121 area: AbsRect::new(10.0, 15.0, 10.0, 15.0)
122 + RelRect::new(0.0, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
123 anchor: feather_ui::RelPoint::zero().into(),
124 ..Default::default()
125 }
126 .into(),
127 text: format!("Boxes: {}", args.count),
128 font_size: 40.0,
129 line_height: 56.0,
130 ..Default::default()
131 }
132 };
133
134 let rect = Shape::<DRect, { ShapeKind::RoundRect as u8 }>::new(
135 scope.create(),
136 feather_ui::FILL_DRECT,
137 0.0,
138 0.0,
139 wide::f32x4::splat(10.0),
140 sRGB::new(0.2, 0.7, 0.4, 1.0),
141 sRGB::transparent(),
142 DAbsPoint::zero(),
143 );
144
145 Button::<FixedData>::new(
146 scope.create(),
147 FixedData {
148 area: AbsRect::new(0.0, 20.0, 0.0, 0.0)
149 + RelRect::new(0.5, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
150 anchor: feather_ui::RelPoint::new(0.5, 0.0).into(),
151 zindex: 0,
152 },
153 Slot(feather_ui::APP_SOURCE_ID.into(), 0),
154 feather_ui::children![fixed::Prop, rect, text],
155 )
156 };
157
158 const NUM_COLUMNS: usize = 5;
159 let rectgrid = {
160 let mut children: im::Vector<Option<Box<ChildOf<dyn grid::Prop>>>> =
161 im::Vector::new();
162 {
163 for (i, id) in scope.iter(0..args.count) {
164 children.push_back(Some(Box::new(Shape::<
165 GridChild,
166 { ShapeKind::RoundRect as u8 },
167 >::new(
168 id,
169 GridChild {
170 area: FILL_DRECT,
171 x: i % NUM_COLUMNS,
172 y: i / NUM_COLUMNS,
173 },
174 0.0,
175 0.0,
176 wide::f32x4::splat(4.0),
177 sRGB::new(
178 (0.1 * i as f32) % 1.0,
179 (0.65 * i as f32) % 1.0,
180 (0.2 * i as f32) % 1.0,
181 1.0,
182 ),
183 sRGB::transparent(),
184 DAbsPoint::zero(),
185 ))));
186 }
187 }
188
189 GridBox::<GridData>::new(
190 scope.create(),
191 GridData {
192 area: AbsRect::new(0.0, 200.0, 0.0, 0.0)
193 + RelRect::new(0.0, 0.0, UNSIZED_AXIS, 1.0),
194
195 rlimits: feather_ui::RelLimits::new(0.0..1.0, 0.0..),
196 direction: feather_ui::RowDirection::LeftToRight,
197 rows: [40.0, 20.0, 40.0, 20.0, 40.0, 20.0, 10.0]
198 .map(DValue::from)
199 .to_vec(),
200 columns: [80.0, 40.0, 80.0, 40.0, 80.0].map(DValue::from).to_vec(),
201 spacing: AbsPoint::new(4.0, 4.0).into(),
202 padding: AbsRect::new(8.0, 8.0, 8.0, 8.0).into(),
203 },
204 children,
205 )
206 };
207
208 let region = Region::new(
209 scope.create(),
210 FixedData {
211 area: FILL_DRECT,
212 zindex: 0,
213 ..Default::default()
214 },
215 feather_ui::children![fixed::Prop, button, rectgrid],
216 );
217 let window = Window::new(
218 scope.create(),
219 winit::window::Window::default_attributes()
220 .with_title(env!("CARGO_CRATE_NAME"))
221 .with_resizable(true),
222 Box::new(region),
223 );
224
225 store.1 = im::HashMap::new();
226 store.1.insert(window.id.clone(), Some(window));
227 store.0 = args.clone();
228 }
229 let windows = store.1.clone();
230 (store, windows)
231 }
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for GridBox<T>
impl<T> !RefUnwindSafe for GridBox<T>
impl<T> !Send for GridBox<T>
impl<T> !Sync for GridBox<T>
impl<T> Unpin for GridBox<T>
impl<T> !UnwindSafe for GridBox<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