[yew-devel] [PATCH yew-widget-toolkit 1/2] widget: data table: column: allow setting vertical align
Dominik Csapak
d.csapak at proxmox.com
Tue Sep 9 10:16:39 CEST 2025
by default the vertical align is set to 'baseline', which is good for
text, but if we want to render something else in a column (e.g. a
`Meter`) we must use 'middle' otherwise the element will be also aligned
on the baseline making it not centered.
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/widget/data_table/column.rs | 14 ++++++++++++++
src/widget/data_table/row.rs | 6 +++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/widget/data_table/column.rs b/src/widget/data_table/column.rs
index 1b95c3e..d702576 100644
--- a/src/widget/data_table/column.rs
+++ b/src/widget/data_table/column.rs
@@ -30,6 +30,9 @@ pub struct DataTableColumn<T: 'static> {
/// Horizontal table cell justification (start, end, left, center, right, justify).
#[prop_or(AttrValue::Static("start"))]
pub justify: AttrValue,
+ /// Vertical table cell align ("top", "bottom", "middle", "baseline").
+ #[prop_or_default]
+ pub vertical_align: Option<AttrValue>,
// only internal, use `apply_render` instead
render_cell: DataTableCellRenderer<T>,
@@ -196,6 +199,17 @@ impl<T: 'static> DataTableColumn<T> {
self.justify = justify.into();
}
+ /// Builder style method to set the vertical cell alignment.
+ pub fn vertical_align(mut self, vertical_align: impl IntoPropValue<Option<AttrValue>>) -> Self {
+ self.set_vertical_align(vertical_align);
+ self
+ }
+
+ /// Method to set the vertical cell alignment.
+ pub fn set_vertical_align(&mut self, vertical_align: impl IntoPropValue<Option<AttrValue>>) {
+ self.vertical_align = vertical_align.into_prop_value();
+ }
+
/// Builder style method to set the render function.
pub fn render(self, render: impl Into<RenderFn<T>>) -> Self {
let render = render.into();
diff --git a/src/widget/data_table/row.rs b/src/widget/data_table/row.rs
index 2770eb9..34bbbdf 100644
--- a/src/widget/data_table/row.rs
+++ b/src/widget/data_table/row.rs
@@ -128,7 +128,11 @@ impl<T: Clone + PartialEq + 'static> Component for PwtDataTableRow<T> {
continue;
}
- let vertical_align = props.vertical_align.to_owned().unwrap_or("baseline".into());
+ let vertical_align = props
+ .vertical_align
+ .to_owned()
+ .or(column.vertical_align.clone())
+ .unwrap_or("baseline".into());
let text_align = column.justify.to_owned();
let cell_active = match props.active_cell {
--
2.47.2
More information about the yew-devel
mailing list