This commit is contained in:
2025-09-04 23:52:04 -05:00
parent e07b5044f9
commit ddf5c377f6
3 changed files with 45 additions and 26 deletions
+21 -3
View File
@@ -1,12 +1,15 @@
use eframe::egui::{Align, InnerResponse, Layout, Response, Ui, Widget};
use eframe::egui::{Align, Button, Color32, InnerResponse, IntoAtoms, Layout, Response, RichText, Ui, Widget};
pub trait UiExtensions {
fn fill_button(&mut self, widget: impl Widget) -> Response;
/// A widget that fills the width of its container. Good for buttons.
fn add_fill_width(&mut self, widget: impl Widget) -> Response;
/// A sub-Ui with a specific width and 100% height
fn column<R>(&mut self, width: f32, f: impl FnOnce(&mut Self)-> R) -> InnerResponse<R>;
}
impl UiExtensions for Ui {
fn fill_button(&mut self, widget: impl Widget) -> Response {
fn add_fill_width(&mut self, widget: impl Widget) -> Response {
self.add_sized((self.available_width(), 20.0), widget)
}
@@ -14,4 +17,19 @@ impl UiExtensions for Ui {
let third = (width, self.available_height()).into();
self.allocate_ui_with_layout(third, Layout::top_down(Align::Max), f)
}
}
pub trait ButtonExtensions<'a> {
fn red(atoms: impl IntoAtoms<'a>) -> Self;
fn green(text: impl Into<String>) -> Self;
}
impl<'a> ButtonExtensions<'a> for Button<'a> {
fn red(atoms: impl IntoAtoms<'a>) -> Self {
Self::new(atoms).fill(Color32::DARK_RED)
}
fn green(text: impl Into<String>) -> Self {
Self::new(RichText::new(text).color(Color32::WHITE)).fill(Color32::DARK_GREEN)
}
}