use crate::misc::Offset; use egui::{Button, Id, InnerResponse, Ui}; use std::ops::BitXorAssign; /// Creates an area ontop of a widget with an y offset pub fn widgets_ontop( ui: &egui::Ui, id: Id, re: &egui::Response, y_offset: f32, add_contents: impl FnOnce(&mut egui::Ui) -> R, ) -> InnerResponse { let area = egui::Area::new(id) .fixed_pos(re.rect.min.offset_y(y_offset)) .order(egui::Order::Foreground); area.show(ui.ctx(), |ui| add_contents(ui)) } /// A toggle button that XORs its state when clicked. /// Shows different hover text based on current state. pub fn toggle_button( ui: &mut Ui, state: &mut bool, label: &str, enabled_tip: &str, disabled_tip: &str, ) { state.bitxor_assign( ui.add(Button::new(label)) .on_hover_text(if *state { enabled_tip } else { disabled_tip }) .clicked(), ); }