Skip to content

Move re_ui UI functions to a trait to be implemented by egui::Ui #4569

@abey79

Description

@abey79

Most UI function in re_ui are #[allow(clippy::unused_self)], but they take a egui::Ui argument (obviously). This could be more cleanly implemented as a trait that would be implemented for egui::Ui.

Something like:

pub trait ReUi {
  fn ui(&mut self) -> &mut egui::Ui;

  fn small_icon_button(&self, icon: &Icon) -> egui::Response {
        ui.add(
            egui::ImageButton::new(icon.as_image().fit_to_exact_size(Self::small_icon_size()))
                .tint(self.ui().visuals().widgets.inactive.fg_stroke.color),
        )
    }

    // etc.
}

impl ReUi for egui::Ui {
  fn ui(&mut self) -> &mut egui::Ui { self }
}

Before (typical):

ctx.re_ui.small_icon_button(ui, icon);

After:

use re_ui::ReUi as _;

ui.small_icon_button(icon);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions