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

egui_extras: table cell dividers #4783

Open
littleBitsman opened this issue Jul 4, 2024 · 4 comments
Open

egui_extras: table cell dividers #4783

littleBitsman opened this issue Jul 4, 2024 · 4 comments

Comments

@littleBitsman
Copy link

Is your feature request related to a problem? Please describe. Kinda. I want to make cell dividers but adding separators makes the text literally disappear, which is a problem on its own.

Describe the solution you'd like
I want the ability to add cell dividers (both between rows and columns) and a border around the edge of the table. All of which should be customizable by color and size in pixels.

Describe alternatives you've considered
I tried using separators (e.g., ui.add(Separator::default().vertical()); on both sides of the label in each row/column) which made the text disappear.

I haven't seen any issues for this so I'm making this one

@littleBitsman littleBitsman changed the title Table cell dividers egui_extras: table cell dividers Jul 4, 2024
@littleBitsman
Copy link
Author

Turns out this is (kinda) possible using Frame and Stroke but that guarantees a full border (all 4 sides)

Frame::none().stroke(Stroke::new(2.0, Rgba::from_black_alpha(1.0))).show(ui, |ui| {
    // whatever here...
})

@YgorSouza
Copy link
Contributor

You can also draw the lines manually with ui.painter().vline() and hline(), although it is a bit cumbersome to keep track of all the rects. This does however give you complete flexibility to draw any lines you want on top of the table. If it were to get an API for that, it would be a matter of deciding what subset of this functionality it should support, e.g., include or exclude the header, or make shorter lines in the middle instead of going end to end.

@littleBitsman
Copy link
Author

littleBitsman commented Jul 5, 2024

Yeah, more controllable styles would be really nice especially for things like Tables and Grids. #3284 seems to be getting onto that though.
I'll look into the ui.painter().vline() and hline() stuff though

@littleBitsman
Copy link
Author

littleBitsman commented Jul 5, 2024

I made these utilities just to make it a bit faster for me to write:

fn draw_hlines<R>(ui: &mut Ui, length: f32, next: impl FnOnce(&mut Ui) -> R) {
  ui.painter().hline(0.0..=length, 0.0, PathStroke::new(2.0, Rgba::from_rgb(0.0, 0.0, 0.0)));
  next(ui);
  ui.painter().hline(0.0..=length, ui.min_rect().height() + 2.0, PathStroke::new(2.0, Rgba::from_rgb(0.0, 0.0, 0.0)));
}
fn draw_vlines<R>(ui: &mut Ui, height: f32, next: impl FnOnce(&mut Ui) -> R) {
  ui.painter().vline(0.0, 0.0..=height, PathStroke::new(2.0, Rgba::from_rgb(0.0, 0.0, 0.0)));
  next(ui);
  ui.painter().vline(ui.min_rect().width() + 2.0, 0.0..=height, PathStroke::new(2.0, Rgba::from_rgb(0.0, 0.0, 0.0)));
}
fn draw_box<R>(ui: &mut Ui, length: f32, height: f32, next: impl FnOnce(&mut Ui) -> R) {
  draw_hlines(ui, length, |ui| draw_vlines(ui, height, next))
}

Calling it in the header (column initialization) callbacks results in nothing happening.
Not sure if this is correct but...yea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants