1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 23:13:13 -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

@@ -134,6 +134,9 @@ pub fn window_builder<E>(
window_builder = window_builder.with_drag_and_drop(*drag_and_drop_support);
// Always use the default window size / position on iOS. Trying to restore the previous position
// causes the window to be shown too small.
#[cfg(not(target_os = "ios"))]
let inner_size_points = if let Some(mut window_settings) = window_settings {
// Restore pos/size from previous session
@@ -159,6 +162,7 @@ pub fn window_builder<E>(
*initial_window_size
};
#[cfg(not(target_os = "ios"))]
if *centered {
if let Some(monitor) = event_loop.available_monitors().next() {
let monitor_size = monitor.size().to_logical::<f64>(monitor.scale_factor());

View File

@@ -138,6 +138,7 @@ fn with_event_loop<R>(
})
}
#[cfg(not(target_os = "ios"))]
fn run_and_return(
event_loop: &mut EventLoop<UserEvent>,
mut winit_app: impl WinitApp,
@@ -413,6 +414,17 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
if time_until_next < std::time::Duration::from_secs(10_000) {
log::trace!("WaitUntil {time_until_next:?}");
}
// WaitUntil seems to not work on iOS
#[cfg(target_os = "ios")]
winit_app
.get_window_winit_id(ViewportId::MAIN)
.map(|window_id| {
winit_app
.window(window_id)
.map(|window| window.read().request_redraw())
});
control_flow.set_wait_until(next_repaint_time);
};
})
@@ -1687,6 +1699,7 @@ mod glow_integration {
mut native_options: epi::NativeOptions,
app_creator: epi::AppCreator,
) -> Result<()> {
#[cfg(not(target_os = "ios"))]
if native_options.run_and_return {
with_event_loop(native_options, |event_loop, native_options| {
let glow_eframe =
@@ -1698,6 +1711,13 @@ mod glow_integration {
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
run_and_exit(event_loop, glow_eframe);
}
#[cfg(target_os = "ios")]
{
let event_loop = create_event_loop_builder(&mut native_options).build();
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
run_and_exit(event_loop, glow_eframe);
}
}
}
@@ -2493,6 +2513,7 @@ mod wgpu_integration {
mut native_options: epi::NativeOptions,
app_creator: epi::AppCreator,
) -> Result<()> {
#[cfg(not(target_os = "ios"))]
if native_options.run_and_return {
with_event_loop(native_options, |event_loop, native_options| {
let wgpu_eframe =
@@ -2504,6 +2525,13 @@ mod wgpu_integration {
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
run_and_exit(event_loop, wgpu_eframe);
}
#[cfg(target_os = "ios")]
{
let event_loop = create_event_loop_builder(&mut native_options).build();
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
run_and_exit(event_loop, wgpu_eframe);
}
}
}

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)
}),
}

View File

@@ -66,6 +66,11 @@ impl super::View for ContextMenus {
ui.menu_button("Click for menu", Self::nested_menus);
ui.button("Right-click for menu")
.context_menu(Self::nested_menus);
if ui.ctx().is_context_menu_open() {
ui.label("Context menu is open");
} else {
ui.label("Context menu is closed");
}
});
ui.separator();