| ... | @@ -557,7 +557,8 @@ struct State { | ... | @@ -557,7 +557,8 @@ struct State { |
| 557 | scroll_target: f32, | 557 | scroll_target: f32, |
| 558 | /// Height of a scrolling box's children last frame. | 558 | /// Height of a scrolling box's children last frame. |
| 559 | content: f32, | 559 | content: f32, |
| 560 | rect: [f32; 4], | 560 | /// As last laid out; none for a box built this frame for the first time. |
| | 561 | rect: Option<[f32; 4]>, |
| 561 | /// A text field's selection, and the selection and unit of the press a drag extends. | 562 | /// A text field's selection, and the selection and unit of the press a drag extends. |
| 562 | selection: Selection, | 563 | selection: Selection, |
| 563 | press: (Selection, SelectionUnit), | 564 | press: (Selection, SelectionUnit), |
| ... | @@ -860,9 +861,9 @@ impl Ui { | ... | @@ -860,9 +861,9 @@ impl Ui { |
| 860 | Some(layout::narrowest(&self.nodes, index)) | 861 | Some(layout::narrowest(&self.nodes, index)) |
| 861 | } | 862 | } |
| 862 | | 863 | |
| 863 | /// The box's rectangle from the latest layout. | 864 | /// The box's rectangle from the latest layout; none for one not laid out yet. |
| 864 | pub fn rect(&self, id: Id) -> Option<[f32; 4]> { | 865 | pub fn rect(&self, id: Id) -> Option<[f32; 4]> { |
| 865 | self.states.get(&id).map(|state| state.rect) | 866 | self.states.get(&id).and_then(|state| state.rect) |
| 866 | } | 867 | } |
| 867 | | 868 | |
| 868 | /// Scrolls `scroller`, a scrolling box, until `target` within it starts at its top, both | 869 | /// Scrolls `scroller`, a scrolling box, until `target` within it starts at its top, both |
| ... | @@ -872,7 +873,7 @@ impl Ui { | ... | @@ -872,7 +873,7 @@ impl Ui { |
| 872 | return; | 873 | return; |
| 873 | }; | 874 | }; |
| 874 | let state = self.states.entry(scroller).or_default(); | 875 | let state = self.states.entry(scroller).or_default(); |
| 875 | let most = (state.content - (state.rect[3] - state.rect[1])).max(0.0); | 876 | let most = (state.content - (start[3] - start[1])).max(0.0); |
| 876 | state.scroll_target = (state.scroll + top[1] - start[1]).clamp(0.0, most); | 877 | state.scroll_target = (state.scroll + top[1] - start[1]).clamp(0.0, most); |
| 877 | self.animating |= state.scroll != state.scroll_target; | 878 | self.animating |= state.scroll != state.scroll_target; |
| 878 | } | 879 | } |
| ... | @@ -1035,7 +1036,8 @@ impl Ui { | ... | @@ -1035,7 +1036,8 @@ impl Ui { |
| 1035 | } | 1036 | } |
| 1036 | Some(id) => { | 1037 | Some(id) => { |
| 1037 | let state = self.states.entry(id).or_default(); | 1038 | let state = self.states.entry(id).or_default(); |
| 1038 | let most = (state.content - (state.rect[3] - state.rect[1])).max(0.0); | 1039 | let shown = state.rect.map_or(0.0, |rect| rect[3] - rect[1]); |
| | 1040 | let most = (state.content - shown).max(0.0); |
| 1039 | // The wheel moves the content at once, as on the page; only jumps ease. | 1041 | // The wheel moves the content at once, as on the page; only jumps ease. |
| 1040 | state.scroll = (state.scroll - delta[1]).clamp(0.0, most); | 1042 | state.scroll = (state.scroll - delta[1]).clamp(0.0, most); |
| 1041 | state.scroll_target = state.scroll; | 1043 | state.scroll_target = state.scroll; |
| ... | @@ -1363,7 +1365,7 @@ impl Ui { | ... | @@ -1363,7 +1365,7 @@ impl Ui { |
| 1363 | ); | 1365 | ); |
| 1364 | for node in &self.nodes { | 1366 | for node in &self.nodes { |
| 1365 | let state = self.states.entry(node.id).or_default(); | 1367 | let state = self.states.entry(node.id).or_default(); |
| 1366 | state.rect = node.rect; | 1368 | state.rect = Some(node.rect); |
| 1367 | state.hovers = node.hover_fill.is_some() || node.hover_border.is_some(); | 1369 | state.hovers = node.hover_fill.is_some() || node.hover_border.is_some(); |
| 1368 | if node.flags.contains(Flags::SCROLL) { | 1370 | if node.flags.contains(Flags::SCROLL) { |
| 1369 | state.content = node.content; | 1371 | state.content = node.content; |