Skip to content

Commit b2d74ea

Browse files
authored
Return ScrollAreaOutput from Table::body (#4829)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> added return ScrollAreaOutput. This can be used to monitor the scroll progress of a table(usage example: custom scroll progress bar or lazy loading table) * [X] I have followed the instructions in the PR template
1 parent 1741f0a commit b2d74ea

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

crates/egui_extras/src/table.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//! Takes all available height, so if you want something below the table, put it in a strip.
55
66
use egui::{
7-
scroll_area::ScrollBarVisibility, Align, NumExt as _, Rangef, Rect, Response, ScrollArea, Ui,
8-
Vec2, Vec2b,
7+
scroll_area::{ScrollAreaOutput, ScrollBarVisibility},
8+
Align, NumExt as _, Rangef, Rect, Response, ScrollArea, Ui, Vec2, Vec2b,
99
};
1010

1111
use crate::{
@@ -474,7 +474,7 @@ impl<'a> TableBuilder<'a> {
474474
}
475475

476476
/// Create table body without a header row
477-
pub fn body<F>(self, add_body_contents: F)
477+
pub fn body<F>(self, add_body_contents: F) -> ScrollAreaOutput<()>
478478
where
479479
F: for<'b> FnOnce(TableBody<'b>),
480480
{
@@ -515,7 +515,7 @@ impl<'a> TableBuilder<'a> {
515515
scroll_options,
516516
sense,
517517
}
518-
.body(add_body_contents);
518+
.body(add_body_contents)
519519
}
520520
}
521521

@@ -641,7 +641,7 @@ impl<'a> Table<'a> {
641641
}
642642

643643
/// Create table body after adding a header row
644-
pub fn body<F>(self, add_body_contents: F)
644+
pub fn body<F>(self, add_body_contents: F) -> ScrollAreaOutput<()>
645645
where
646646
F: for<'b> FnOnce(TableBody<'b>),
647647
{
@@ -692,7 +692,7 @@ impl<'a> Table<'a> {
692692
let widths_ref = &state.column_widths;
693693
let max_used_widths_ref = &mut max_used_widths;
694694

695-
scroll_area.show(ui, move |ui| {
695+
let scroll_area_out = scroll_area.show(ui, move |ui| {
696696
let mut scroll_to_y_range = None;
697697

698698
let clip_rect = ui.clip_rect();
@@ -843,6 +843,7 @@ impl<'a> Table<'a> {
843843
state.max_used_widths = max_used_widths;
844844

845845
state.store(ui, state_id);
846+
scroll_area_out
846847
}
847848
}
848849

0 commit comments

Comments
 (0)