1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

Merge branch 'master' of https://github.com/emilk/egui into multiples_viewports

This commit is contained in:
Konkitoman
2023-08-23 06:10:34 +03:00
9 changed files with 65 additions and 11 deletions

View File

@@ -1686,6 +1686,14 @@ impl Context {
pub fn highlight_widget(&self, id: Id) {
self.frame_state_mut(|fs| fs.highlight_next_frame.insert(id));
}
/// Is an egui context menu open?
pub fn is_context_menu_open(&self) -> bool {
self.data(|d| {
d.get_temp::<crate::menu::BarState>(menu::CONTEXT_MENU_ID_STR.into())
.map_or(false, |state| state.has_root())
})
}
}
// Ergonomic methods to forward some calls often used in 'if let' without holding the borrow

View File

@@ -796,7 +796,7 @@ impl Key {
Key::ArrowLeft => "",
Key::ArrowRight => "",
Key::ArrowUp => "",
Key::Minus => "-",
Key::Minus => crate::MINUS_CHAR_STR,
Key::PlusEquals => "+",
_ => self.name(),
}

View File

@@ -25,7 +25,7 @@
//! fn ui_counter(ui: &mut egui::Ui, counter: &mut i32) {
//! // Put the buttons and label on the same row:
//! ui.horizontal(|ui| {
//! if ui.button("-").clicked() {
//! if ui.button("").clicked() {
//! *counter -= 1;
//! }
//! ui.label(counter.to_string());
@@ -469,6 +469,9 @@ macro_rules! egui_assert {
// ----------------------------------------------------------------------------
/// The minus character: <https://www.compart.com/en/unicode/U+2212>
pub(crate) const MINUS_CHAR_STR: &str = "";
/// The default egui fonts supports around 1216 emojis in total.
/// Here are some of the most useful:
/// ∞⊗⎗⎘⎙⏏⏴⏵⏶⏷

View File

@@ -48,6 +48,10 @@ impl BarState {
MenuRoot::stationary_click_interaction(response, &mut self.open_menu, response.id);
self.open_menu.show(response, add_contents)
}
pub(crate) fn has_root(&self) -> bool {
self.open_menu.inner.is_some()
}
}
impl std::ops::Deref for BarState {
@@ -212,12 +216,14 @@ fn stationary_menu_image_impl<'c, R>(
InnerResponse::new(inner.map(|r| r.inner), button_response)
}
pub(crate) const CONTEXT_MENU_ID_STR: &str = "__egui::context_menu";
/// Response to secondary clicks (right-clicks) by showing the given menu.
pub(crate) fn context_menu(
response: &Response,
add_contents: impl FnOnce(&mut Ui),
) -> Option<InnerResponse<()>> {
let menu_id = Id::new("__egui::context_menu");
let menu_id = Id::new(CONTEXT_MENU_ID_STR);
let mut bar_state = BarState::load(&response.ctx, menu_id);
MenuRoot::context_click_interaction(response, &mut bar_state, response.id);

View File

@@ -271,7 +271,7 @@ impl<'a> DragValue<'a> {
self.custom_formatter(move |n, _| format!("{:0>min_width$b}", n as i64))
} else {
self.custom_formatter(move |n, _| {
let sign = if n < 0.0 { "-" } else { "" };
let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" };
format!("{sign}{:0>min_width$b}", n.abs() as i64)
})
}
@@ -306,7 +306,7 @@ impl<'a> DragValue<'a> {
self.custom_formatter(move |n, _| format!("{:0>min_width$o}", n as i64))
} else {
self.custom_formatter(move |n, _| {
let sign = if n < 0.0 { "-" } else { "" };
let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" };
format!("{sign}{:0>min_width$o}", n.abs() as i64)
})
}
@@ -345,11 +345,11 @@ impl<'a> DragValue<'a> {
self.custom_formatter(move |n, _| format!("{:0>min_width$x}", n as i64))
}
(false, true) => self.custom_formatter(move |n, _| {
let sign = if n < 0.0 { "-" } else { "" };
let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" };
format!("{sign}{:0>min_width$X}", n.abs() as i64)
}),
(false, false) => self.custom_formatter(move |n, _| {
let sign = if n < 0.0 { "-" } else { "" };
let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" };
format!("{sign}{:0>min_width$x}", n.abs() as i64)
}),
}

View File

@@ -395,7 +395,7 @@ impl<'a> Slider<'a> {
self.custom_formatter(move |n, _| format!("{:0>min_width$b}", n as i64))
} else {
self.custom_formatter(move |n, _| {
let sign = if n < 0.0 { "-" } else { "" };
let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" };
format!("{sign}{:0>min_width$b}", n.abs() as i64)
})
}
@@ -430,7 +430,7 @@ impl<'a> Slider<'a> {
self.custom_formatter(move |n, _| format!("{:0>min_width$o}", n as i64))
} else {
self.custom_formatter(move |n, _| {
let sign = if n < 0.0 { "-" } else { "" };
let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" };
format!("{sign}{:0>min_width$o}", n.abs() as i64)
})
}
@@ -469,11 +469,11 @@ impl<'a> Slider<'a> {
self.custom_formatter(move |n, _| format!("{:0>min_width$x}", n as i64))
}
(false, true) => self.custom_formatter(move |n, _| {
let sign = if n < 0.0 { "-" } else { "" };
let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" };
format!("{sign}{:0>min_width$X}", n.abs() as i64)
}),
(false, false) => self.custom_formatter(move |n, _| {
let sign = if n < 0.0 { "-" } else { "" };
let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" };
format!("{sign}{:0>min_width$x}", n.abs() as i64)
}),
}