paiagram/
status_bar_text.rs1use egui::{Rect, Response, Ui};
2use std::fmt::{Display, Write};
3
4pub trait SetStatusBarText {
5 fn set_status_bar_text(self, text: impl Display, target: &mut String) -> Self;
6}
7
8impl SetStatusBarText for Response {
9 fn set_status_bar_text(self, text: impl Display, target: &mut String) -> Self {
10 if self.hovered() {
12 target.clear();
13 write!(target, "{}", text);
14 }
15 self
16 }
17}
18
19impl SetStatusBarText for Ui {
20 fn set_status_bar_text(self, text: impl Display, target: &mut String) -> Self {
21 let rect = self.max_rect().expand2(self.style().spacing.item_spacing);
23 if self.rect_contains_pointer(rect) {
24 target.clear();
25 write!(target, "{}", text);
26 }
27 self
28 }
29}
30
31impl SetStatusBarText for (Rect, Response) {
32 fn set_status_bar_text(self, text: impl Display, target: &mut String) -> Self {
33 let (_, response) = self.clone();
34 if response.hovered() {
35 target.clear();
36 write!(target, "{}", text);
37 }
38 self
39 }
40}