mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
ability to scroll to the end of the content for scrollviewer/scrollpanel
This commit is contained in:
@@ -29,6 +29,8 @@ pub enum ScrollPanelMessage {
|
||||
HorizontalScroll(f32),
|
||||
/// Adjusts vertical and horizontal scroll values so given node will be in "view box" of scroll panel.
|
||||
BringIntoView(Handle<UiNode>),
|
||||
/// Scrolls to end of the content.
|
||||
ScrollToEnd,
|
||||
}
|
||||
|
||||
impl ScrollPanelMessage {
|
||||
@@ -44,6 +46,10 @@ impl ScrollPanelMessage {
|
||||
/// Creates [`ScrollPanelMessage::BringIntoView`] message.
|
||||
ScrollPanelMessage:BringIntoView => fn bring_into_view(Handle<UiNode>), layout: true
|
||||
);
|
||||
define_constructor!(
|
||||
/// Creates [`ScrollPanelMessage::ScrollToEnd`] message.
|
||||
ScrollPanelMessage:ScrollToEnd => fn scroll_to_end(), layout: true
|
||||
);
|
||||
}
|
||||
|
||||
/// Scroll panel widget is used to arrange its children widgets, so they can be offset by a certain amount of units
|
||||
@@ -296,6 +302,33 @@ impl Control for ScrollPanel {
|
||||
}
|
||||
}
|
||||
}
|
||||
ScrollPanelMessage::ScrollToEnd => {
|
||||
let mut max_size = Vector2::default();
|
||||
for child_handle in self.widget.children() {
|
||||
let child = ui.nodes.borrow(*child_handle);
|
||||
let child_desired_size = child.desired_size();
|
||||
if child_desired_size.x > max_size.x {
|
||||
max_size.x = child_desired_size.x;
|
||||
}
|
||||
if child_desired_size.y > max_size.y {
|
||||
max_size.y = child_desired_size.y;
|
||||
}
|
||||
}
|
||||
if self.vertical_scroll_allowed {
|
||||
ui.send_message(ScrollPanelMessage::vertical_scroll(
|
||||
self.handle,
|
||||
MessageDirection::ToWidget,
|
||||
(max_size.y - self.actual_local_size().y).max(0.0),
|
||||
));
|
||||
}
|
||||
if self.horizontal_scroll_allowed {
|
||||
ui.send_message(ScrollPanelMessage::horizontal_scroll(
|
||||
self.handle,
|
||||
MessageDirection::ToWidget,
|
||||
(max_size.x - self.actual_local_size().x).max(0.0),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ pub enum ScrollViewerMessage {
|
||||
VScrollSpeed(f32),
|
||||
/// Sets the new horizontal scrolling speed.
|
||||
HScrollSpeed(f32),
|
||||
/// Scrolls to end of the content.
|
||||
ScrollToEnd,
|
||||
}
|
||||
|
||||
impl ScrollViewerMessage {
|
||||
@@ -51,6 +53,10 @@ impl ScrollViewerMessage {
|
||||
/// Creates [`ScrollViewerMessage::HScrollSpeed`] message.
|
||||
ScrollViewerMessage:HScrollSpeed => fn h_scroll_speed(f32), layout: true
|
||||
);
|
||||
define_constructor!(
|
||||
/// Creates [`ScrollViewerMessage::ScrollToEnd`] message.
|
||||
ScrollViewerMessage:ScrollToEnd => fn scroll_to_end(), layout: true
|
||||
);
|
||||
}
|
||||
|
||||
/// Scroll viewer is a scrollable region with two scroll bars for each axis. It is used to wrap a content of unknown
|
||||
@@ -339,6 +345,13 @@ impl Control for ScrollViewer {
|
||||
ui.send_message(message.reverse());
|
||||
}
|
||||
}
|
||||
ScrollViewerMessage::ScrollToEnd => {
|
||||
// Re-cast message to inner panel.
|
||||
ui.send_message(ScrollPanelMessage::scroll_to_end(
|
||||
self.scroll_panel,
|
||||
MessageDirection::ToWidget,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user