Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move row_top_offset to the TableDelegate #14

Merged
merged 5 commits into from
Sep 11, 2024
Merged

Conversation

abey79
Copy link
Member

@abey79 abey79 commented Sep 11, 2024

The initial implementation for arbitrary row height used a row_top_offset closure pass the Table alongside the delegate. This approach is, however, not ideal. Often, the delegate
needs mutable access to data that is used to compute row height, thereby forcing the use of a lock of some kind.

This PR moves the row_top_offset to TableDelegate, with a default implementation which always returns None. Also, Table::row_height is now renamed Table::default_row_height. The provided value is used when row_top_offset() is not implemented.

Note: row_top_offset() must always return either None, or Some(offset). Returning inconsistant Option varient will lead to incoherent display.

@abey79 abey79 added enhancement New feature or request include in changelog labels Sep 11, 2024
egui_table/src/table.rs Outdated Show resolved Hide resolved
egui_table/src/table.rs Outdated Show resolved Hide resolved
table_delegate: &dyn TableDelegate,
row_nr: u64,
) -> f32 {
table_delegate.row_top_offset(ctx, self.id_salt, row_nr)
Copy link
Member

@emilk emilk Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not the salt - the globally unique Id of the table (constructed from the salt and the parent ui id)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Related (but I worked around it): I'm very confused by Table::get_id(). It's supposed to be the unique id for this table, but the returned result is going to be dependant on the Ui that is passed to it, right? Shouldn't the persistent id be generated once at the beginning of Table::show(), and then used throughout?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see the test app you see we use get_id to access the state before calling .show. I'd love to have a better design for this, but not sure what it should be.

We could replace fn id_salt(salt impl Hash) with an fn id(id: Id), for instance. This is a recurring problem in egui, and one I haven't a uniform or nice solution for - yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Anyways, for the row offset stuff I could work around this in an acceptable way.

egui_table/src/table.rs Outdated Show resolved Hide resolved
@abey79 abey79 merged commit 08bba8f into main Sep 11, 2024
10 checks passed
@abey79 abey79 deleted the antoine/delegate-top-of-row branch September 11, 2024 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants