pub struct RowSetter<D, T: RowTemp, S: RowStorage> { /* private fields */ }
Expand description
A RulesSetter
for rows (and, without loss of generality, for columns).
This is parameterised over:
D:
Directional
— whether this represents a row or a columnT:
RowTemp
— temporary storage typeS:
RowStorage
— persistent storage type
Implementations§
source§impl<D: Directional, T: RowTemp, S: RowStorage> RowSetter<D, T, S>
impl<D: Directional, T: RowTemp, S: RowStorage> RowSetter<D, T, S>
sourcepub fn new(rect: Rect, (direction, len): (D, usize), storage: &mut S) -> Self
pub fn new(rect: Rect, (direction, len): (D, usize), storage: &mut S) -> Self
Construct
Argument order is consistent with other RulesSetter
s.
rect
: theRect
within which to position children(direction, len)
: direction and number of itemsstorage
: access to the solver’s storage
Examples found in repository?
src/layout/visitor.rs (line 352)
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
fn set_rect(&mut self, mgr: &mut ConfigMgr, rect: Rect) {
let dim = (self.direction, self.children.len());
let mut setter = RowSetter::<D, Vec<i32>, _>::new(rect, dim, self.data);
for (n, child) in (&mut self.children).enumerate() {
child.set_rect(mgr, setter.child_rect(self.data, n));
}
}
fn find_id(&mut self, coord: Coord) -> Option<WidgetId> {
// TODO(opt): more efficient search strategy?
self.children.find_map(|child| child.find_id(coord))
}
fn draw(&mut self, mut draw: DrawMgr) {
for child in &mut self.children {
child.draw(draw.re_clone());
}
}
}
/// Float layout
struct Float<'a, I>
where
I: DoubleEndedIterator<Item = Visitor<'a>>,
{
children: I,
}
impl<'a, I> Layout for Float<'a, I>
where
I: DoubleEndedIterator<Item = Visitor<'a>>,
{
fn size_rules(&mut self, mgr: SizeMgr, axis: AxisInfo) -> SizeRules {
let mut rules = SizeRules::EMPTY;
for child in &mut self.children {
rules = rules.max(child.size_rules(mgr.re(), axis));
}
rules
}
fn set_rect(&mut self, mgr: &mut ConfigMgr, rect: Rect) {
for child in &mut self.children {
child.set_rect(mgr, rect);
}
}
fn find_id(&mut self, coord: Coord) -> Option<WidgetId> {
self.children.find_map(|child| child.find_id(coord))
}
fn draw(&mut self, mut draw: DrawMgr) {
let mut iter = (&mut self.children).rev();
if let Some(first) = iter.next() {
first.draw(draw.re_clone());
}
for child in iter {
draw.with_pass(|draw| child.draw(draw));
}
}
}
/// A row/column over a slice
struct Slice<'a, W: Widget, D: Directional> {
data: &'a mut DynRowStorage,
direction: D,
children: &'a mut [W],
}
impl<'a, W: Widget, D: Directional> Layout for Slice<'a, W, D> {
fn size_rules(&mut self, mgr: SizeMgr, axis: AxisInfo) -> SizeRules {
let dim = (self.direction, self.children.len());
let mut solver = RowSolver::new(axis, dim, self.data);
for (n, child) in self.children.iter_mut().enumerate() {
solver.for_child(self.data, n, |axis| child.size_rules(mgr.re(), axis));
}
solver.finish(self.data)
}
fn set_rect(&mut self, mgr: &mut ConfigMgr, rect: Rect) {
let dim = (self.direction, self.children.len());
let mut setter = RowSetter::<D, Vec<i32>, _>::new(rect, dim, self.data);
for (n, child) in self.children.iter_mut().enumerate() {
child.set_rect(mgr, setter.child_rect(self.data, n));
}
}
sourcepub fn new_unsolved(
rect: Rect,
(direction, len): (D, usize),
storage: &mut S
) -> Self
pub fn new_unsolved(
rect: Rect,
(direction, len): (D, usize),
storage: &mut S
) -> Self
Construct without solving
In this case, it is assumed that the storage was already solved by a
previous RowSetter
. The user should optionally call solve_range
on
any ranges needing updating and finally call update_offsets
before
using this RowSetter
to calculate child positions.
sourcepub fn update_offsets(&mut self, storage: &mut S)
pub fn update_offsets(&mut self, storage: &mut S)
Examples found in repository?
src/layout/row_solver.rs (line 140)
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
pub fn new(rect: Rect, (direction, len): (D, usize), storage: &mut S) -> Self {
let mut offsets = T::default();
offsets.set_len(len);
storage.set_dim(len);
if len > 0 {
let is_horiz = direction.is_horizontal();
let width = if is_horiz { rect.size.0 } else { rect.size.1 };
let (widths, rules) = storage.widths_and_rules();
SizeRules::solve_seq(widths, rules, width);
}
let _s = Default::default();
let mut row = RowSetter {
rect,
offsets,
direction,
_s,
};
row.update_offsets(storage);
row
}
pub fn solve_range(&mut self, storage: &mut S, range: Range<usize>, width: i32)
Trait Implementations§
source§impl<D: Directional, T: RowTemp, S: RowStorage> RulesSetter for RowSetter<D, T, S>
impl<D: Directional, T: RowTemp, S: RowStorage> RulesSetter for RowSetter<D, T, S>
§type ChildInfo = usize
type ChildInfo = usize
Type required by
RulesSolver::for_child
(see implementation documentation)Auto Trait Implementations§
impl<D, T, S> RefUnwindSafe for RowSetter<D, T, S>where
D: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<D, T, S> Send for RowSetter<D, T, S>where
D: Send,
S: Send,
T: Send,
impl<D, T, S> Sync for RowSetter<D, T, S>where
D: Sync,
S: Sync,
T: Sync,
impl<D, T, S> Unpin for RowSetter<D, T, S>where
D: Unpin,
S: Unpin,
T: Unpin,
impl<D, T, S> UnwindSafe for RowSetter<D, T, S>where
D: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating Read more
source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer Read more
source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer Read more