math_app: extract toggle_button helper to reduce UI code duplication
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::misc::Offset;
|
||||
use egui::{Id, InnerResponse};
|
||||
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<R>(
|
||||
@@ -15,3 +16,13 @@ pub fn widgets_ontop<R>(
|
||||
|
||||
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(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user