Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cadfba05dd | ||
|
|
38b3a81053 |
No files matched your search
+23
-27
@@ -267,36 +267,32 @@ impl<'a> Painter<'a> {
|
|||||||
let widgets = self.rsc.widgets();
|
let widgets = self.rsc.widgets();
|
||||||
// A rule is the answer where there is one: it wins over whatever the
|
// A rule is the answer where there is one: it wins over whatever the
|
||||||
// widget would draw, so it has to win over what the widget says too.
|
// widget would draw, so it has to win over what the widget says too.
|
||||||
let hint = widgets
|
let hint = widgets.size_rules(id.id()).axis(axis).exact().or_else(|| {
|
||||||
.size_rules(id.id())
|
widgets
|
||||||
.axis(axis)
|
.get_dyn(id.id())
|
||||||
.exact()
|
.and_then(|widget| widget.size_hint(axis))
|
||||||
.or_else(|| {
|
});
|
||||||
widgets
|
let frame = self.frame.axis(axis);
|
||||||
.get_dyn(id.id())
|
let resolved = hint.map(|hint| hint.within_len(frame));
|
||||||
.and_then(|widget| widget.size_hint(axis))
|
|
||||||
})
|
|
||||||
.map(|hint| hint.within_len(self.frame.axis(axis)));
|
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
diag::hint_read(id.id(), self.id, axis, hint);
|
{
|
||||||
match hint {
|
diag::hint_read(id.id(), self.id, axis, resolved);
|
||||||
Some(hint) => {
|
diag::bump(match resolved {
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
Some(_) => Counter::HintHits,
|
||||||
diag::bump(Counter::HintHits);
|
None => Counter::HintMisses,
|
||||||
self.depend_on(id);
|
});
|
||||||
// A fraction was just resolved against this frame, so what
|
}
|
||||||
// this draw does with it is a function of the frame's length.
|
if let Some(hint) = hint {
|
||||||
if hint.rel != Rel::ZERO {
|
self.depend_on(id);
|
||||||
self.frame_own_len[axis as usize] = Some(self.frame.axis(axis));
|
// Resolving a fraction against this frame makes this draw a
|
||||||
}
|
// function of the frame's length. The fraction to ask about is
|
||||||
Some(hint)
|
// the child's own: resolved against a frame of pixels, none is
|
||||||
}
|
// left to see it by.
|
||||||
None => {
|
if hint.rel != Rel::ZERO {
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
self.frame_own_len[axis as usize] = Some(frame);
|
||||||
diag::bump(Counter::HintMisses);
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
resolved
|
||||||
}
|
}
|
||||||
|
|
||||||
fn depend_on<W: ?Sized>(&mut self, child: &StrongWidget<W>) {
|
fn depend_on<W: ?Sized>(&mut self, child: &StrongWidget<W>) {
|
||||||
|
|||||||
@@ -28,16 +28,13 @@ impl Widget for Span {
|
|||||||
// given whatever else is in it and wherever this child sits among
|
// given whatever else is in it and wherever this child sits among
|
||||||
// them; what a drawn child is asked in is the room left from the
|
// them; what a drawn child is asked in is the room left from the
|
||||||
// cursor, because a text has to wrap at the width actually there.
|
// cursor, because a text has to wrap at the width actually there.
|
||||||
// This is the one ask a drawn fixed child gets: its slot is its
|
|
||||||
// answer, and the drawing is moved there once the shares are known.
|
|
||||||
// A hinted child is asked once, in its slot.
|
|
||||||
let mut cursor = Len::rel_min();
|
let mut cursor = Len::rel_min();
|
||||||
let mut lens = Vec::with_capacity(self.children.len());
|
let mut lens = Vec::with_capacity(self.children.len());
|
||||||
let mut measured = Vec::with_capacity(self.children.len());
|
let mut drawn_across = Vec::with_capacity(self.children.len());
|
||||||
for child in &self.children {
|
for child in &self.children {
|
||||||
let size = match painter.size_hint(child, axis) {
|
let len = match painter.size_hint(child, axis) {
|
||||||
Some(len) => {
|
Some(len) => {
|
||||||
measured.push(None);
|
drawn_across.push(None);
|
||||||
len
|
len
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@@ -45,11 +42,10 @@ impl Widget for Span {
|
|||||||
let size = painter
|
let size = painter
|
||||||
.widget_at(child, [None; 2], axis.pair(room, across))
|
.widget_at(child, [None; 2], axis.pair(room, across))
|
||||||
.size();
|
.size();
|
||||||
measured.push(Some(size));
|
drawn_across.push(Some(size.axis(!axis)));
|
||||||
size.axis(axis)
|
size.axis(axis)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let len = size;
|
|
||||||
cursor.px += len.px + self.gap;
|
cursor.px += len.px + self.gap;
|
||||||
cursor.rel += len.rel;
|
cursor.rel += len.rel;
|
||||||
lens.push(len);
|
lens.push(len);
|
||||||
@@ -104,8 +100,7 @@ impl Widget for Span {
|
|||||||
let mut taken = Weight::ZERO;
|
let mut taken = Weight::ZERO;
|
||||||
let mut start = Len::rel_min();
|
let mut start = Len::rel_min();
|
||||||
let mut ortho = LayoutLen::ZERO;
|
let mut ortho = LayoutLen::ZERO;
|
||||||
for ((child, len), measured) in self.children.iter().zip(&lens).zip(&measured) {
|
for ((child, &len), &across_len) in self.children.iter().zip(&lens).zip(&drawn_across) {
|
||||||
let len = *len;
|
|
||||||
// A child asking for nothing but a part of what is left over,
|
// A child asking for nothing but a part of what is left over,
|
||||||
// when nothing is, is not drawn at all. One that also asked for
|
// when nothing is, is not drawn at all. One that also asked for
|
||||||
// pixels or a fraction keeps those and overflows.
|
// pixels or a fraction keeps those and overflows.
|
||||||
@@ -135,10 +130,10 @@ impl Widget for Span {
|
|||||||
if len.leftover > Weight::ZERO && shares {
|
if len.leftover > Weight::ZERO && shares {
|
||||||
narrow[axis as usize] = Some(slot.len());
|
narrow[axis as usize] = Some(slot.len());
|
||||||
}
|
}
|
||||||
let used = match (measured, narrow[axis as usize]) {
|
let used = match (across_len, narrow[axis as usize]) {
|
||||||
(Some(size), None) => {
|
(Some(across_len), None) => {
|
||||||
painter.place_at(child, place);
|
painter.place_at(child, place);
|
||||||
size.axis(!axis)
|
across_len
|
||||||
}
|
}
|
||||||
_ => painter.widget_at(child, narrow, place).len(!axis),
|
_ => painter.widget_at(child, narrow, place).len(!axis),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user