Implement alignment support for table::column

This commit is contained in:
Héctor Ramón Jiménez 2025-07-16 04:06:38 +02:00
parent 1e89439aff
commit 6e71c7dd6f
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 67 additions and 18 deletions

View file

@ -4,7 +4,7 @@ use iced::widget::{
center_x, center_y, column, container, row, scrollable, slider, table,
text, tooltip,
};
use iced::{Center, Element, Font, Theme};
use iced::{Center, Element, Fill, Font, Right, Theme};
pub fn main() -> iced::Result {
iced::application(Table::new, Table::update, Table::view)
@ -59,7 +59,9 @@ impl Table {
} else {
text::default
})
}),
})
.align_x(Right)
.align_y(Center),
table::column(bold("Price"), |event: &Event| {
if event.price > 0.0 {
text!("${:.2}", event.price).style(
@ -70,9 +72,11 @@ impl Table {
},
)
} else {
text("Free").style(text::success)
text("Free").style(text::success).width(Fill).center()
}
}),
})
.align_x(Right)
.align_y(Center),
table::column(bold("Rating"), |event: &Event| {
text!("{:.2}", event.rating).style(if event.rating > 4.7 {
text::success
@ -81,7 +85,9 @@ impl Table {
} else {
text::default
})
}),
})
.align_x(Right)
.align_y(Center),
];
table(columns, &self.events)