mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Truncate text in clipped Table columns (#5023)
* Closes https://github.com/emilk/egui/issues/5013 * Columns with `clip = true` will have `TextWrapMode::Truncate` set * Added setting `Column::auto_size_this_frame` (acts like a double-click on column resizer) * Set `sizing_pass` on all cells in a column that is being auto-sized (e.g. on double-click) 
This commit is contained in:
@@ -33,6 +33,9 @@ pub(crate) struct StripLayoutFlags {
|
||||
pub(crate) striped: bool,
|
||||
pub(crate) hovered: bool,
|
||||
pub(crate) selected: bool,
|
||||
|
||||
/// Used when we want to accruately measure the size of this cell.
|
||||
pub(crate) sizing_pass: bool,
|
||||
}
|
||||
|
||||
/// Positions cells in [`CellDirection`] and starts a new line on [`StripLayout::end_line`]
|
||||
@@ -197,19 +200,27 @@ impl<'l> StripLayout<'l> {
|
||||
child_ui_id_source: egui::Id,
|
||||
add_cell_contents: impl FnOnce(&mut Ui),
|
||||
) -> Ui {
|
||||
let mut child_ui = self.ui.new_child(
|
||||
UiBuilder::new()
|
||||
.id_source(child_ui_id_source)
|
||||
.ui_stack_info(egui::UiStackInfo::new(egui::UiKind::TableCell))
|
||||
.max_rect(max_rect)
|
||||
.layout(self.cell_layout),
|
||||
);
|
||||
let mut ui_builder = UiBuilder::new()
|
||||
.id_source(child_ui_id_source)
|
||||
.ui_stack_info(egui::UiStackInfo::new(egui::UiKind::TableCell))
|
||||
.max_rect(max_rect)
|
||||
.layout(self.cell_layout);
|
||||
if flags.sizing_pass {
|
||||
ui_builder = ui_builder.sizing_pass();
|
||||
}
|
||||
|
||||
let mut child_ui = self.ui.new_child(ui_builder);
|
||||
|
||||
if flags.clip {
|
||||
let margin = egui::Vec2::splat(self.ui.visuals().clip_rect_margin);
|
||||
let margin = margin.min(0.5 * self.ui.spacing().item_spacing);
|
||||
let clip_rect = max_rect.expand2(margin);
|
||||
child_ui.set_clip_rect(clip_rect.intersect(child_ui.clip_rect()));
|
||||
|
||||
if !child_ui.is_sizing_pass() {
|
||||
// Better to truncate (if we can), rather than hard clipping:
|
||||
child_ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate);
|
||||
}
|
||||
}
|
||||
|
||||
if flags.selected {
|
||||
|
||||
Reference in New Issue
Block a user