pub struct Limits<U> {
pub v: f32x4,
/* private fields */
}
Expand description
The Limits type represents both a minimum size and a maximum size for a given unit. Adding limits together actually merges them, by taking the largest minimum size and the smallest maximum size of either. You aren’t expected to construct this type manually, however - the Limits constructor takes a range parameter to make it easier to represent the minimum and maximum range of sizes you want.
§Examples
use feather_ui::euclid::Size2D;
use feather_ui::{AbsLimits, RelLimits, Logical, Relative};
// Results in a minimum size of [-inf, 10.0] and a maximum size of [inf, 200.0]
let limits = AbsLimits::new(.., 10.0..200.0);
assert_eq!(limits.min(), Size2D::<f32, Logical>::new(f32::NEG_INFINITY, 10.0));
assert_eq!(limits.max(), Size2D::<f32, Logical>::new(f32::INFINITY, 200.0));
// Results in a minimum size of [-inf, -inf] and a maximum size of [1.0, inf]
let rlimits = RelLimits::new(..1.0, ..);
assert_eq!(rlimits.min(), Size2D::<f32, Relative>::new(f32::NEG_INFINITY, f32::NEG_INFINITY));
assert_eq!(rlimits.max(), Size2D::<f32, Relative>::new(1.0, f32::INFINITY));
// Result in a minimum size of [0.0, 10.0] and a maximum size of [inf, 100.0]
let merged = AbsLimits::new(0.0.., 5.0..100.0) + limits;
assert_eq!(merged.min(), Size2D::<f32, Logical>::new(0.0, 10.0));
assert_eq!(merged.max(), Size2D::<f32, Logical>::new(f32::INFINITY, 100.0));
Fields§
§v: f32x4
Implementations§
Source§impl<U> Limits<U>
impl<U> Limits<U>
Sourcepub fn new(x: impl RangeBounds<f32>, y: impl RangeBounds<f32>) -> Self
pub fn new(x: impl RangeBounds<f32>, y: impl RangeBounds<f32>) -> Self
Examples found in repository?
examples/grid-rs.rs (line 195)
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 }
More examples
examples/basic-rs.rs (line 106)
53 fn call(
54 &mut self,
55 mut store: Self::Store,
56 app: CounterState,
57 mut id: ScopeID<'_>,
58 ) -> (Self::Store, im::HashMap<Arc<SourceID>, Option<Window>>) {
59 if store.0 != app {
60 let button = {
61 let text = Text::<FixedData> {
62 id: gen_id!(id),
63 props: Rc::new(FixedData {
64 area: AbsRect::new(8.0, 0.0, 8.0, 0.0)
65 + RelRect::new(0.0, 0.5, UNSIZED_AXIS, UNSIZED_AXIS),
66 anchor: feather_ui::RelPoint::new(0.0, 0.5).into(),
67 ..Default::default()
68 }),
69 color: sRGB::new(1.0, 1.0, 0.0, 1.0),
70 text: format!("Clicks: {}", app.count),
71 font_size: 40.0,
72 line_height: 56.0,
73 align: Some(cosmic_text::Align::Center),
74 ..Default::default()
75 };
76
77 let rect = shape::round_rect::<DRect>(
78 gen_id!(id),
79 feather_ui::FILL_DRECT,
80 0.0,
81 0.0,
82 wide::f32x4::splat(10.0),
83 sRGB::new(0.2, 0.7, 0.4, 1.0),
84 sRGB::transparent(),
85 DAbsPoint::zero(),
86 );
87
88 Button::<FixedData>::new(
89 gen_id!(id),
90 FixedData {
91 area: AbsRect::new(45.0, 45.0, 0.0, 0.0)
92 + RelRect::new(0.0, 0.0, UNSIZED_AXIS, 1.0),
93
94 ..Default::default()
95 },
96 Slot(feather_ui::APP_SOURCE_ID.into(), 0),
97 feather_ui::children![fixed::Prop, rect, text],
98 )
99 };
100
101 let block = {
102 let text = Text::<FixedData> {
103 id: gen_id!(id),
104 props: Rc::new(FixedData {
105 area: RelRect::new(0.5, 0.0, UNSIZED_AXIS, UNSIZED_AXIS).into(),
106 limits: feather_ui::AbsLimits::new(.., 10.0..200.0).into(),
107 rlimits: feather_ui::RelLimits::new(..1.0, ..),
108 anchor: feather_ui::RelPoint::new(0.5, 0.0).into(),
109 padding: AbsRect::new(8.0, 8.0, 8.0, 8.0).into(),
110 ..Default::default()
111 }),
112 text: (0..app.count).map(|_| "█").collect::<String>(),
113 font_size: 40.0,
114 line_height: 56.0,
115 wrap: feather_ui::cosmic_text::Wrap::WordOrGlyph,
116 align: Some(cosmic_text::Align::Center),
117 ..Default::default()
118 };
119
120 let rect = shape::round_rect::<DRect>(
121 gen_id!(id),
122 feather_ui::FILL_DRECT,
123 0.0,
124 0.0,
125 wide::f32x4::splat(10.0),
126 sRGB::new(0.7, 0.2, 0.4, 1.0),
127 sRGB::transparent(),
128 DAbsPoint::zero(),
129 );
130
131 Region::<FixedData>::new_layer(
132 gen_id!(id),
133 FixedData {
134 area: AbsRect::new(45.0, 245.0, 0.0, 0.0)
135 + RelRect::new(0.0, 0.0, UNSIZED_AXIS, UNSIZED_AXIS),
136 limits: feather_ui::AbsLimits::new(100.0..300.0, ..).into(),
137 ..Default::default()
138 },
139 sRGB32::from_alpha(128),
140 0.0,
141 feather_ui::children![fixed::Prop, rect, text],
142 )
143 };
144
145 let pixel = shape::round_rect::<DRect>(
146 gen_id!(id),
147 PxRect::new(1.0, 1.0, 2.0, 2.0).into(),
148 0.0,
149 0.0,
150 wide::f32x4::zeroed(),
151 sRGB::new(1.0, 1.0, 1.0, 1.0),
152 sRGB::transparent(),
153 DAbsPoint::zero(),
154 );
155
156 let region = Region::new(
157 gen_id!(id),
158 FixedData {
159 area: AbsRect::new(90.0, 90.0, 0.0, 200.0)
160 + RelRect::new(0.0, 0.0, UNSIZED_AXIS, 0.0),
161 zindex: 0,
162 ..Default::default()
163 },
164 feather_ui::children![fixed::Prop, button, block, pixel],
165 );
166 let window = Window::new(
167 gen_id!(id),
168 winit::window::Window::default_attributes()
169 .with_title(env!("CARGO_CRATE_NAME"))
170 .with_resizable(true),
171 Box::new(region),
172 );
173
174 store.1 = im::HashMap::new();
175 store.1.insert(window.id.clone(), Some(window));
176 store.0 = app.clone();
177 }
178 let windows = store.1.clone();
179 (store, windows)
180 }
examples/list-rs.rs (line 215)
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 }
pub fn min(&self) -> Size2D<f32, U>
pub fn max(&self) -> Size2D<f32, U>
pub fn set_min(&mut self, bound: Size2D<f32, U>)
pub fn set_max(&mut self, bound: Size2D<f32, U>)
Sourcepub fn to_untyped(self) -> Limits<UnknownUnit>
pub fn to_untyped(self) -> Limits<UnknownUnit>
Discard the units
Trait Implementations§
impl<U: Copy> Copy for Limits<U>
impl<U> StructuralPartialEq for Limits<U>
Auto Trait Implementations§
impl<U> Freeze for Limits<U>
impl<U> RefUnwindSafe for Limits<U>where
U: RefUnwindSafe,
impl<U> Send for Limits<U>where
U: Send,
impl<U> Sync for Limits<U>where
U: Sync,
impl<U> Unpin for Limits<U>where
U: Unpin,
impl<U> UnwindSafe for Limits<U>where
U: UnwindSafe,
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<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> DowncastSync for T
impl<T> DowncastSync for T
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian()
.