pub struct GridBox<T: Prop + 'static> {
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: Rc<T>,
children: Vector<Option<Box<ChildOf<dyn Prop>>>>,
) -> Self
pub fn new( id: Arc<SourceID>, props: Rc<T>, children: Vector<Option<Box<ChildOf<dyn Prop>>>>, ) -> Self
Examples found in repository?
examples/grid-rs.rs (lines 205-227)
110 fn call(
111 &mut self,
112 mut store: Self::Store,
113 args: &CounterState,
114 ) -> (Self::Store, im::HashMap<Arc<SourceID>, Option<Window>>) {
115 if store.0 != *args {
116 let button = {
117 let text = Text::<FixedData> {
118 id: gen_id!(),
119 props: FixedData {
120 area: feather_ui::URect {
121 abs: AbsRect::new(10.0, 15.0, 10.0, 15.0),
122 rel: RelRect::new(0.0, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
123 }
124 .into(),
125 anchor: feather_ui::RelPoint(Vec2 { x: 0.0, y: 0.0 }).into(),
126 ..Default::default()
127 }
128 .into(),
129 text: format!("Boxes: {}", args.count),
130 font_size: 40.0,
131 line_height: 56.0,
132 ..Default::default()
133 };
134
135 let rect = Shape::<DRect, { ShapeKind::RoundRect as u8 }>::new(
136 gen_id!(),
137 feather_ui::FILL_DRECT.into(),
138 0.0,
139 0.0,
140 Vec4::broadcast(10.0),
141 sRGB::new(0.2, 0.7, 0.4, 1.0),
142 sRGB::transparent(),
143 );
144
145 Button::<FixedData>::new(
146 gen_id!(),
147 FixedData {
148 area: feather_ui::URect {
149 abs: AbsRect::new(0.0, 20.0, 0.0, 0.0),
150 rel: RelRect::new(0.5, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
151 }
152 .into(),
153 anchor: feather_ui::RelPoint(Vec2 { x: 0.5, y: 0.0 }).into(),
154 zindex: 0,
155 },
156 Slot(feather_ui::APP_SOURCE_ID.into(), 0),
157 feather_ui::children![fixed::Prop, rect, text],
158 )
159 };
160
161 const NUM_COLUMNS: usize = 5;
162 let rectgrid = {
163 let mut children: im::Vector<Option<Box<ChildOf<dyn grid::Prop>>>> =
164 im::Vector::new();
165 let grid_id = gen_id!();
166 for i in 0..args.count {
167 children.push_back(Some(Box::new(Shape::<
168 GridChild,
169 { ShapeKind::RoundRect as u8 },
170 >::new(
171 grid_id.child(DataID::Int(i as i64)),
172 GridChild {
173 area: FILL_DRECT,
174 x: i % NUM_COLUMNS,
175 y: i / NUM_COLUMNS,
176 }
177 .into(),
178 0.0,
179 0.0,
180 Vec4::broadcast(4.0),
181 sRGB::new(
182 (0.1 * i as f32) % 1.0,
183 (0.65 * i as f32) % 1.0,
184 (0.2 * i as f32) % 1.0,
185 1.0,
186 ),
187 sRGB::transparent(),
188 ))));
189
190 /*children.push_back(Some(Box::new(Text::<GridChild> {
191 id: gen_id!(),
192 props: GridChild {
193 area: FILL_DRECT,
194 x: i % NUM_COLUMNS,
195 y: i / NUM_COLUMNS,
196 }
197 .into(),
198 text: format!("Cell: {}", i),
199 font_size: 20.0,
200 line_height: 22.0,
201 ..Default::default()
202 })));*/
203 }
204
205 GridBox::<GridData>::new(
206 gen_id!(),
207 GridData {
208 area: feather_ui::URect {
209 abs: AbsRect::new(0.0, 200.0, 0.0, 0.0),
210 rel: RelRect::new(0.0, 0.0, UNSIZED_AXIS, 1.0),
211 }
212 .into(),
213 rlimits: feather_ui::RelLimits::new(
214 ZERO_POINT,
215 Vec2::new(1.0, f32::INFINITY),
216 ),
217 direction: feather_ui::RowDirection::BottomToTop,
218 rows: [40.0, 20.0, 40.0, 20.0, 40.0, 20.0, 10.0]
219 .map(DValue::from)
220 .to_vec(),
221 columns: [80.0, 40.0, 80.0, 40.0, 80.0].map(DValue::from).to_vec(),
222 spacing: DPoint::from(Vec2::new(4.0, 4.0)),
223 padding: AbsRect::new(8.0, 8.0, 8.0, 8.0).into(),
224 }
225 .into(),
226 children,
227 )
228 };
229
230 let region = Region::new(
231 gen_id!(),
232 FixedData {
233 area: FILL_DRECT,
234 zindex: 0,
235 ..Default::default()
236 }
237 .into(),
238 feather_ui::children![fixed::Prop, button, rectgrid],
239 );
240 let window = Window::new(
241 gen_id!(),
242 winit::window::Window::default_attributes()
243 .with_title(env!("CARGO_CRATE_NAME"))
244 .with_resizable(true),
245 Box::new(region),
246 );
247
248 store.1 = im::HashMap::new();
249 store.1.insert(window.id.clone(), Some(window));
250 store.0 = args.clone();
251 }
252 let windows = store.1.clone();
253 (store, windows)
254 }
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