mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-05 02:14:22 +02:00
This commit introduces a new wrapper, CustomUi, which is used to implement custom methods on top of eframe::egui::Ui. The default ui::add_sized method always has the text in a label centered, which is not desirable for a status bar where the layout should be ltr. A new function CustomUi::add_sized_left_to_right has been added to ensure that labels can be truncated with a custom width (which requires allocate_ui_with_layout), while also retaining the ability for the text to be aligned to the left rather than the center of the allocated layout.
23 lines
595 B
Rust
23 lines
595 B
Rust
use eframe::egui::Align;
|
|
use eframe::egui::Layout;
|
|
use eframe::egui::Response;
|
|
use eframe::egui::Ui;
|
|
use eframe::egui::Vec2;
|
|
use eframe::egui::Widget;
|
|
|
|
pub struct CustomUi<'ui>(pub &'ui mut Ui);
|
|
|
|
impl CustomUi<'_> {
|
|
pub fn add_sized_left_to_right(
|
|
&mut self,
|
|
max_size: impl Into<Vec2>,
|
|
widget: impl Widget,
|
|
) -> Response {
|
|
let layout =
|
|
Layout::from_main_dir_and_cross_align(self.0.layout().main_dir(), Align::Center);
|
|
self.0
|
|
.allocate_ui_with_layout(max_size.into(), layout, |ui| ui.add(widget))
|
|
.inner
|
|
}
|
|
}
|