From b2d74eaef603324ff2e471f4706ba0f8765b5431 Mon Sep 17 00:00:00 2001 From: frederik-uni <147479464+frederik-uni@users.noreply.github.com> Date: Mon, 15 Jul 2024 20:49:41 +0200 Subject: [PATCH] Return `ScrollAreaOutput` from `Table::body` (#4829) 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 --- crates/egui_extras/src/table.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/egui_extras/src/table.rs b/crates/egui_extras/src/table.rs index eb3cc7def3f..91041dcdaa7 100644 --- a/crates/egui_extras/src/table.rs +++ b/crates/egui_extras/src/table.rs @@ -4,8 +4,8 @@ //! Takes all available height, so if you want something below the table, put it in a strip. use egui::{ - scroll_area::ScrollBarVisibility, Align, NumExt as _, Rangef, Rect, Response, ScrollArea, Ui, - Vec2, Vec2b, + scroll_area::{ScrollAreaOutput, ScrollBarVisibility}, + Align, NumExt as _, Rangef, Rect, Response, ScrollArea, Ui, Vec2, Vec2b, }; use crate::{ @@ -474,7 +474,7 @@ impl<'a> TableBuilder<'a> { } /// Create table body without a header row - pub fn body(self, add_body_contents: F) + pub fn body(self, add_body_contents: F) -> ScrollAreaOutput<()> where F: for<'b> FnOnce(TableBody<'b>), { @@ -515,7 +515,7 @@ impl<'a> TableBuilder<'a> { scroll_options, sense, } - .body(add_body_contents); + .body(add_body_contents) } } @@ -641,7 +641,7 @@ impl<'a> Table<'a> { } /// Create table body after adding a header row - pub fn body(self, add_body_contents: F) + pub fn body(self, add_body_contents: F) -> ScrollAreaOutput<()> where F: for<'b> FnOnce(TableBody<'b>), { @@ -692,7 +692,7 @@ impl<'a> Table<'a> { let widths_ref = &state.column_widths; let max_used_widths_ref = &mut max_used_widths; - scroll_area.show(ui, move |ui| { + let scroll_area_out = scroll_area.show(ui, move |ui| { let mut scroll_to_y_range = None; let clip_rect = ui.clip_rect(); @@ -843,6 +843,7 @@ impl<'a> Table<'a> { state.max_used_widths = max_used_widths; state.store(ui, state_id); + scroll_area_out } }