mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Rename functions in Context to avoid confusion (#7773)
It's important to avoid confusion after * https://github.com/emilk/egui/pull/7770
This commit is contained in:
@@ -196,11 +196,13 @@ pub(crate) fn on_keydown(event: web_sys::KeyboardEvent, runner: &mut AppRunner)
|
|||||||
|
|
||||||
let prevent_default = should_prevent_default_for_key(runner, &modifiers, egui_key);
|
let prevent_default = should_prevent_default_for_key(runner, &modifiers, egui_key);
|
||||||
|
|
||||||
// log::debug!(
|
if false {
|
||||||
// "On keydown {:?} {egui_key:?}, has_focus: {has_focus}, egui_wants_keyboard: {}, prevent_default: {prevent_default}",
|
log::debug!(
|
||||||
// event.key().as_str(),
|
"On keydown {:?} {egui_key:?}, has_focus: {has_focus}, egui_wants_keyboard: {}, prevent_default: {prevent_default}",
|
||||||
// runner.egui_ctx().wants_keyboard_input()
|
event.key().as_str(),
|
||||||
// );
|
runner.egui_ctx().egui_wants_keyboard_input()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if prevent_default {
|
if prevent_default {
|
||||||
event.prevent_default();
|
event.prevent_default();
|
||||||
|
|||||||
@@ -309,21 +309,21 @@ impl State {
|
|||||||
self.on_mouse_button_input(*state, *button);
|
self.on_mouse_button_input(*state, *button);
|
||||||
EventResponse {
|
EventResponse {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
consumed: self.egui_ctx.wants_pointer_input(),
|
consumed: self.egui_ctx.egui_wants_pointer_input(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::MouseWheel { delta, phase, .. } => {
|
WindowEvent::MouseWheel { delta, phase, .. } => {
|
||||||
self.on_mouse_wheel(window, *delta, *phase);
|
self.on_mouse_wheel(window, *delta, *phase);
|
||||||
EventResponse {
|
EventResponse {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
consumed: self.egui_ctx.wants_pointer_input(),
|
consumed: self.egui_ctx.egui_wants_pointer_input(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
self.on_cursor_moved(window, *position);
|
self.on_cursor_moved(window, *position);
|
||||||
EventResponse {
|
EventResponse {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
consumed: self.egui_ctx.is_using_pointer(),
|
consumed: self.egui_ctx.egui_is_using_pointer(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::CursorLeft { .. } => {
|
WindowEvent::CursorLeft { .. } => {
|
||||||
@@ -340,8 +340,10 @@ impl State {
|
|||||||
let consumed = match touch.phase {
|
let consumed = match touch.phase {
|
||||||
winit::event::TouchPhase::Started
|
winit::event::TouchPhase::Started
|
||||||
| winit::event::TouchPhase::Ended
|
| winit::event::TouchPhase::Ended
|
||||||
| winit::event::TouchPhase::Cancelled => self.egui_ctx.wants_pointer_input(),
|
| winit::event::TouchPhase::Cancelled => {
|
||||||
winit::event::TouchPhase::Moved => self.egui_ctx.is_using_pointer(),
|
self.egui_ctx.egui_wants_pointer_input()
|
||||||
|
}
|
||||||
|
winit::event::TouchPhase::Moved => self.egui_ctx.egui_is_using_pointer(),
|
||||||
};
|
};
|
||||||
EventResponse {
|
EventResponse {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
@@ -392,7 +394,7 @@ impl State {
|
|||||||
|
|
||||||
EventResponse {
|
EventResponse {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
consumed: self.egui_ctx.wants_keyboard_input(),
|
consumed: self.egui_ctx.egui_wants_keyboard_input(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
@@ -413,7 +415,7 @@ impl State {
|
|||||||
self.on_keyboard_input(event);
|
self.on_keyboard_input(event);
|
||||||
|
|
||||||
// When pressing the Tab key, egui focuses the first focusable element, hence Tab always consumes.
|
// When pressing the Tab key, egui focuses the first focusable element, hence Tab always consumes.
|
||||||
let consumed = self.egui_ctx.wants_keyboard_input()
|
let consumed = self.egui_ctx.egui_wants_keyboard_input()
|
||||||
|| event.logical_key
|
|| event.logical_key
|
||||||
== winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab);
|
== winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab);
|
||||||
EventResponse {
|
EventResponse {
|
||||||
@@ -528,7 +530,7 @@ impl State {
|
|||||||
self.egui_input.events.push(egui::Event::Zoom(zoom_factor));
|
self.egui_input.events.push(egui::Event::Zoom(zoom_factor));
|
||||||
EventResponse {
|
EventResponse {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
consumed: self.egui_ctx.wants_pointer_input(),
|
consumed: self.egui_ctx.egui_wants_pointer_input(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,7 +543,7 @@ impl State {
|
|||||||
.push(egui::Event::Rotate(-delta.to_radians()));
|
.push(egui::Event::Rotate(-delta.to_radians()));
|
||||||
EventResponse {
|
EventResponse {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
consumed: self.egui_ctx.wants_pointer_input(),
|
consumed: self.egui_ctx.egui_wants_pointer_input(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,7 +558,7 @@ impl State {
|
|||||||
});
|
});
|
||||||
EventResponse {
|
EventResponse {
|
||||||
repaint: true,
|
repaint: true,
|
||||||
consumed: self.egui_ctx.wants_pointer_input(),
|
consumed: self.egui_ctx.egui_wants_pointer_input(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -712,7 +712,7 @@ fn automatic_area_position(ctx: &Context, layer_id: LayerId) -> Pos2 {
|
|||||||
|
|
||||||
// NOTE: for the benefit of the egui demo, we position the windows so they don't
|
// NOTE: for the benefit of the egui demo, we position the windows so they don't
|
||||||
// cover the side panels, which means we use `available_rect` here instead of `constrain_rect` or `screen_rect`.
|
// cover the side panels, which means we use `available_rect` here instead of `constrain_rect` or `screen_rect`.
|
||||||
let available_rect = ctx.available_rect();
|
let available_rect = ctx.globally_available_rect();
|
||||||
|
|
||||||
let spacing = 16.0;
|
let spacing = 16.0;
|
||||||
let left = available_rect.left() + spacing;
|
let left = available_rect.left() + spacing;
|
||||||
|
|||||||
@@ -754,7 +754,7 @@ impl Panel {
|
|||||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let side = self.side;
|
let side = self.side;
|
||||||
let available_rect = ctx.available_rect();
|
let available_rect = ctx.globally_available_rect();
|
||||||
let mut panel_ui = Ui::new(
|
let mut panel_ui = Ui::new(
|
||||||
ctx.clone(),
|
ctx.clone(),
|
||||||
self.id,
|
self.id,
|
||||||
@@ -1050,7 +1050,7 @@ impl CentralPanel {
|
|||||||
id,
|
id,
|
||||||
UiBuilder::new()
|
UiBuilder::new()
|
||||||
.layer_id(LayerId::background())
|
.layer_id(LayerId::background())
|
||||||
.max_rect(ctx.available_rect().round_ui()),
|
.max_rect(ctx.globally_available_rect().round_ui()),
|
||||||
);
|
);
|
||||||
panel_ui.set_clip_rect(ctx.content_rect());
|
panel_ui.set_clip_rect(ctx.content_rect());
|
||||||
|
|
||||||
|
|||||||
@@ -2798,12 +2798,18 @@ impl Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// How much space is still available after panels have been added.
|
/// How much space is still available after panels have been added.
|
||||||
pub fn available_rect(&self) -> Rect {
|
pub fn globally_available_rect(&self) -> Rect {
|
||||||
self.pass_state(|s| s.available_rect()).round_ui()
|
self.pass_state(|s| s.available_rect()).round_ui()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// How much space is still available after panels have been added.
|
||||||
|
#[deprecated = "Renamed to globally_available_rect"]
|
||||||
|
pub fn available_rect(&self) -> Rect {
|
||||||
|
self.globally_available_rect()
|
||||||
|
}
|
||||||
|
|
||||||
/// How much space is used by panels and windows.
|
/// How much space is used by panels and windows.
|
||||||
pub fn used_rect(&self) -> Rect {
|
pub fn globally_used_rect(&self) -> Rect {
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
let mut used = ctx.viewport().this_pass.used_by_panels;
|
let mut used = ctx.viewport().this_pass.used_by_panels;
|
||||||
for (_id, window) in ctx.memory.areas().visible_windows() {
|
for (_id, window) in ctx.memory.areas().visible_windows() {
|
||||||
@@ -2813,17 +2819,31 @@ impl Context {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// How much space is used by panels and windows.
|
||||||
|
#[deprecated = "Renamed to globally_used_rect"]
|
||||||
|
pub fn used_rect(&self) -> Rect {
|
||||||
|
self.globally_used_rect()
|
||||||
|
}
|
||||||
|
|
||||||
/// How much space is used by panels and windows.
|
/// How much space is used by panels and windows.
|
||||||
///
|
///
|
||||||
/// You can shrink your egui area to this size and still fit all egui components.
|
/// You can shrink your egui area to this size and still fit all egui components.
|
||||||
|
pub fn globally_used_size(&self) -> Vec2 {
|
||||||
|
(self.globally_used_rect().max - Pos2::ZERO).round_ui()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How much space is used by panels and windows.
|
||||||
|
///
|
||||||
|
/// You can shrink your egui area to this size and still fit all egui components.
|
||||||
|
#[deprecated = "Renamed to globally_used_size"]
|
||||||
pub fn used_size(&self) -> Vec2 {
|
pub fn used_size(&self) -> Vec2 {
|
||||||
(self.used_rect().max - Pos2::ZERO).round_ui()
|
(self.globally_used_rect().max - Pos2::ZERO).round_ui()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/// Is the pointer (mouse/touch) over any egui area?
|
/// Is the pointer (mouse/touch) over any egui area?
|
||||||
pub fn is_pointer_over_area(&self) -> bool {
|
pub fn is_pointer_over_egui(&self) -> bool {
|
||||||
let pointer_pos = self.input(|i| i.pointer.interact_pos());
|
let pointer_pos = self.input(|i| i.pointer.interact_pos());
|
||||||
if let Some(pointer_pos) = pointer_pos {
|
if let Some(pointer_pos) = pointer_pos {
|
||||||
if let Some(layer) = self.layer_id_at(pointer_pos) {
|
if let Some(layer) = self.layer_id_at(pointer_pos) {
|
||||||
@@ -2840,29 +2860,60 @@ impl Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is the pointer (mouse/touch) over any egui area?
|
||||||
|
#[deprecated = "Renamed to is_pointer_over_egui"]
|
||||||
|
pub fn is_pointer_over_area(&self) -> bool {
|
||||||
|
self.is_pointer_over_egui()
|
||||||
|
}
|
||||||
|
|
||||||
/// True if egui is currently interested in the pointer (mouse or touch).
|
/// True if egui is currently interested in the pointer (mouse or touch).
|
||||||
///
|
///
|
||||||
/// Could be the pointer is hovering over a [`crate::Window`] or the user is dragging a widget.
|
/// Could be the pointer is hovering over a [`crate::Window`] or the user is dragging a widget.
|
||||||
/// If `false`, the pointer is outside of any egui area and so
|
/// If `false`, the pointer is outside of any egui area and so
|
||||||
/// you may be interested in what it is doing (e.g. controlling your game).
|
/// you may be interested in what it is doing (e.g. controlling your game).
|
||||||
/// Returns `false` if a drag started outside of egui and then moved over an egui area.
|
/// Returns `false` if a drag started outside of egui and then moved over an egui area.
|
||||||
|
pub fn egui_wants_pointer_input(&self) -> bool {
|
||||||
|
self.egui_is_using_pointer()
|
||||||
|
|| (self.is_pointer_over_egui() && !self.input(|i| i.pointer.any_down()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// True if egui is currently interested in the pointer (mouse or touch).
|
||||||
|
///
|
||||||
|
/// Could be the pointer is hovering over a [`crate::Window`] or the user is dragging a widget.
|
||||||
|
/// If `false`, the pointer is outside of any egui area and so
|
||||||
|
/// you may be interested in what it is doing (e.g. controlling your game).
|
||||||
|
/// Returns `false` if a drag started outside of egui and then moved over an egui area.
|
||||||
|
#[deprecated = "Renamed to egui_wants_pointer_input"]
|
||||||
pub fn wants_pointer_input(&self) -> bool {
|
pub fn wants_pointer_input(&self) -> bool {
|
||||||
self.is_using_pointer()
|
self.egui_wants_pointer_input()
|
||||||
|| (self.is_pointer_over_area() && !self.input(|i| i.pointer.any_down()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is egui currently using the pointer position (e.g. dragging a slider)?
|
/// Is egui currently using the pointer position (e.g. dragging a slider)?
|
||||||
///
|
///
|
||||||
/// NOTE: this will return `false` if the pointer is just hovering over an egui area.
|
/// NOTE: this will return `false` if the pointer is just hovering over an egui area.
|
||||||
pub fn is_using_pointer(&self) -> bool {
|
pub fn egui_is_using_pointer(&self) -> bool {
|
||||||
self.memory(|m| m.interaction().is_using_pointer())
|
self.memory(|m| m.interaction().is_using_pointer())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is egui currently using the pointer position (e.g. dragging a slider)?
|
||||||
|
///
|
||||||
|
/// NOTE: this will return `false` if the pointer is just hovering over an egui area.
|
||||||
|
#[deprecated = "Renamed to egui_is_using_pointer"]
|
||||||
|
pub fn is_using_pointer(&self) -> bool {
|
||||||
|
self.egui_is_using_pointer()
|
||||||
|
}
|
||||||
|
|
||||||
/// If `true`, egui is currently listening on text input (e.g. typing text in a [`crate::TextEdit`]).
|
/// If `true`, egui is currently listening on text input (e.g. typing text in a [`crate::TextEdit`]).
|
||||||
pub fn wants_keyboard_input(&self) -> bool {
|
pub fn egui_wants_keyboard_input(&self) -> bool {
|
||||||
self.memory(|m| m.focused().is_some())
|
self.memory(|m| m.focused().is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If `true`, egui is currently listening on text input (e.g. typing text in a [`crate::TextEdit`]).
|
||||||
|
#[deprecated = "Renamed to egui_wants_keyboard_input"]
|
||||||
|
pub fn wants_keyboard_input(&self) -> bool {
|
||||||
|
self.egui_wants_keyboard_input()
|
||||||
|
}
|
||||||
|
|
||||||
/// Highlight this widget, to make it look like it is hovered, even if it isn't.
|
/// Highlight this widget, to make it look like it is hovered, even if it isn't.
|
||||||
///
|
///
|
||||||
/// If you call this after the widget has been fully rendered,
|
/// If you call this after the widget has been fully rendered,
|
||||||
@@ -2877,7 +2928,7 @@ impl Context {
|
|||||||
///
|
///
|
||||||
/// This only works with the old, deprecated [`crate::menu`] API.
|
/// This only works with the old, deprecated [`crate::menu`] API.
|
||||||
#[expect(deprecated)]
|
#[expect(deprecated)]
|
||||||
#[deprecated = "Use `is_popup_open` instead"]
|
#[deprecated = "Use `any_popup_open` instead"]
|
||||||
pub fn is_context_menu_open(&self) -> bool {
|
pub fn is_context_menu_open(&self) -> bool {
|
||||||
self.data(|d| {
|
self.data(|d| {
|
||||||
d.get_temp::<crate::menu::BarState>(crate::menu::CONTEXT_MENU_ID_STR.into())
|
d.get_temp::<crate::menu::BarState>(crate::menu::CONTEXT_MENU_ID_STR.into())
|
||||||
@@ -2888,6 +2939,18 @@ impl Context {
|
|||||||
/// Is a popup or (context) menu open?
|
/// Is a popup or (context) menu open?
|
||||||
///
|
///
|
||||||
/// Will return false for [`crate::Tooltip`]s (which are technically popups as well).
|
/// Will return false for [`crate::Tooltip`]s (which are technically popups as well).
|
||||||
|
pub fn any_popup_open(&self) -> bool {
|
||||||
|
self.pass_state_mut(|fs| {
|
||||||
|
fs.layers
|
||||||
|
.values()
|
||||||
|
.any(|layer| !layer.open_popups.is_empty())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Is a popup or (context) menu open?
|
||||||
|
///
|
||||||
|
/// Will return false for [`crate::Tooltip`]s (which are technically popups as well).
|
||||||
|
#[deprecated = "Renamed to any_popup_open"]
|
||||||
pub fn is_popup_open(&self) -> bool {
|
pub fn is_popup_open(&self) -> bool {
|
||||||
self.pass_state_mut(|fs| {
|
self.pass_state_mut(|fs| {
|
||||||
fs.layers
|
fs.layers
|
||||||
@@ -3217,16 +3280,16 @@ impl Context {
|
|||||||
|
|
||||||
ui.label("Is using pointer")
|
ui.label("Is using pointer")
|
||||||
.on_hover_text("Is egui currently using the pointer actively (e.g. dragging a slider)?");
|
.on_hover_text("Is egui currently using the pointer actively (e.g. dragging a slider)?");
|
||||||
ui.monospace(self.is_using_pointer().to_string());
|
ui.monospace(self.egui_is_using_pointer().to_string());
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Wants pointer input")
|
ui.label("Wants pointer input")
|
||||||
.on_hover_text("Is egui currently interested in the location of the pointer (either because it is in use, or because it is hovering over a window).");
|
.on_hover_text("Is egui currently interested in the location of the pointer (either because it is in use, or because it is hovering over a window).");
|
||||||
ui.monospace(self.wants_pointer_input().to_string());
|
ui.monospace(self.egui_wants_pointer_input().to_string());
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Wants keyboard input").on_hover_text("Is egui currently listening for text input?");
|
ui.label("Wants keyboard input").on_hover_text("Is egui currently listening for text input?");
|
||||||
ui.monospace(self.wants_keyboard_input().to_string());
|
ui.monospace(self.egui_wants_keyboard_input().to_string());
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Keyboard focus widget").on_hover_text("Is egui currently listening for text input?");
|
ui.label("Keyboard focus widget").on_hover_text("Is egui currently listening for text input?");
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ impl Widget for DatePickerButton<'_> {
|
|||||||
|
|
||||||
// We don't want to close our popup if any other popup is open, since other popups would
|
// We don't want to close our popup if any other popup is open, since other popups would
|
||||||
// most likely be the combo boxes in the date picker.
|
// most likely be the combo boxes in the date picker.
|
||||||
let any_popup_open = ui.ctx().is_popup_open();
|
let any_popup_open = ui.any_popup_open();
|
||||||
if !button_response.clicked()
|
if !button_response.clicked()
|
||||||
&& !any_popup_open
|
&& !any_popup_open
|
||||||
&& (ui.input(|i| i.key_pressed(Key::Escape)) || area_response.clicked_elsewhere())
|
&& (ui.input(|i| i.key_pressed(Key::Escape)) || area_response.clicked_elsewhere())
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ impl Keypad {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let is_first_show = ctx.wants_keyboard_input() && state.focus != focus;
|
let is_first_show = ctx.egui_wants_keyboard_input() && state.focus != focus;
|
||||||
if is_first_show {
|
if is_first_show {
|
||||||
let y = ctx.global_style().spacing.interact_size.y * 1.25;
|
let y = ctx.global_style().spacing.interact_size.y * 1.25;
|
||||||
state.open = true;
|
state.open = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user