mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 15:13:12 -04:00
Revert "Now in screen_rect min is the viewport position and max is the viewport size"
This reverts commit 4bbdab1788.
This commit is contained in:
@@ -16,7 +16,7 @@ pub use accesskit_winit;
|
||||
pub use egui;
|
||||
#[cfg(feature = "accesskit")]
|
||||
use egui::accesskit;
|
||||
use egui::{mutex::RwLock, Pos2, ViewportBuilder, ViewportCommand, ViewportId};
|
||||
use egui::{mutex::RwLock, ViewportBuilder, ViewportCommand, ViewportId};
|
||||
pub use winit;
|
||||
|
||||
pub mod clipboard;
|
||||
@@ -176,16 +176,16 @@ impl State {
|
||||
// This solves an issue where egui window positions would be changed when minimizing on Windows.
|
||||
let screen_size_in_pixels = screen_size_in_pixels(window);
|
||||
let screen_size_in_points = screen_size_in_pixels / pixels_per_point;
|
||||
self.egui_input.screen_rect = if !window.is_minimized().unwrap_or_else(|| {
|
||||
|
||||
let getting_info = !window.is_minimized().unwrap_or_else(|| {
|
||||
eprintln!("Cannot determine the Viewport/native window minimized state");
|
||||
true
|
||||
}) {
|
||||
Some(egui::Rect::from_min_max(
|
||||
window
|
||||
.outer_position()
|
||||
.map(|pos| Pos2::new(pos.x as f32, pos.y as f32))
|
||||
.unwrap_or(Pos2::ZERO),
|
||||
screen_size_in_points.to_pos2(),
|
||||
});
|
||||
|
||||
self.egui_input.screen_rect = if getting_info {
|
||||
Some(egui::Rect::from_min_size(
|
||||
egui::Pos2::ZERO,
|
||||
screen_size_in_points,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -376,7 +376,7 @@ impl Prepared {
|
||||
}
|
||||
|
||||
pub(crate) fn content_ui(&self, ctx: &Context) -> Ui {
|
||||
let screen_rect = Rect::from_min_max(Pos2::ZERO, ctx.screen_rect().max);
|
||||
let screen_rect = ctx.screen_rect();
|
||||
|
||||
let bounds = if let Some(bounds) = self.drag_bounds {
|
||||
bounds.intersect(screen_rect) // protect against infinite bounds
|
||||
|
||||
@@ -335,7 +335,7 @@ impl SidePanel {
|
||||
let layer_id = LayerId::background();
|
||||
let side = self.side;
|
||||
let available_rect = ctx.available_rect();
|
||||
let clip_rect = Rect::from_min_max(Pos2::ZERO, ctx.screen_rect().max);
|
||||
let clip_rect = ctx.screen_rect();
|
||||
let mut panel_ui = Ui::new(ctx.clone(), layer_id, self.id, available_rect, clip_rect);
|
||||
|
||||
let inner_response = self.show_inside_dyn(&mut panel_ui, add_contents);
|
||||
@@ -790,7 +790,7 @@ impl TopBottomPanel {
|
||||
let available_rect = ctx.available_rect();
|
||||
let side = self.side;
|
||||
|
||||
let clip_rect = Rect::from_min_max(Pos2::ZERO, ctx.screen_rect().max);
|
||||
let clip_rect = ctx.screen_rect();
|
||||
let mut panel_ui = Ui::new(ctx.clone(), layer_id, self.id, available_rect, clip_rect);
|
||||
|
||||
let inner_response = self.show_inside_dyn(&mut panel_ui, add_contents);
|
||||
@@ -1047,7 +1047,7 @@ impl CentralPanel {
|
||||
let layer_id = LayerId::background();
|
||||
let id = Id::new("central_panel");
|
||||
|
||||
let clip_rect = Rect::from_min_max(Pos2::ZERO, ctx.screen_rect().max);
|
||||
let clip_rect = ctx.screen_rect();
|
||||
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, available_rect, clip_rect);
|
||||
|
||||
let inner_response = self.show_inside_dyn(&mut panel_ui, add_contents);
|
||||
|
||||
@@ -206,7 +206,7 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
|
||||
}
|
||||
}
|
||||
|
||||
let position = position.at_least(Pos2::ZERO);
|
||||
let position = position.at_least(ctx.screen_rect().min);
|
||||
|
||||
let area_id = frame_state.common_id.with(frame_state.count);
|
||||
|
||||
@@ -262,7 +262,7 @@ fn show_tooltip_area_dyn<'c, R>(
|
||||
.fixed_pos(window_pos)
|
||||
.constrain(true)
|
||||
.interactable(false)
|
||||
.drag_bounds(Rect::from_min_max(Pos2::ZERO, ctx.screen_rect().max))
|
||||
.drag_bounds(ctx.screen_rect())
|
||||
.show(ctx, |ui| {
|
||||
Frame::popup(&ctx.style())
|
||||
.show(ui, |ui| {
|
||||
|
||||
@@ -183,7 +183,7 @@ impl Resize {
|
||||
.at_least(self.min_size)
|
||||
.at_most(self.max_size)
|
||||
.at_most(
|
||||
ui.ctx().screen_rect().max.to_vec2() - ui.spacing().window_margin.sum(), // hack for windows
|
||||
ui.ctx().screen_rect().size() - ui.spacing().window_margin.sum(), // hack for windows
|
||||
);
|
||||
|
||||
State {
|
||||
|
||||
@@ -436,7 +436,7 @@ impl<'open> Window<'open> {
|
||||
let mut resize = resize.id(resize_id);
|
||||
|
||||
let mut area = area.begin(ctx);
|
||||
let win_size = ctx.screen_rect().max.to_vec2();
|
||||
let win_size = ctx.input(|i| i.screen_rect.size());
|
||||
area.state_mut().set_left_top_pos(Pos2::ZERO);
|
||||
area.state_mut().size = win_size;
|
||||
let title_content_spacing = 2.0 * ctx.style().spacing.item_spacing.y;
|
||||
@@ -893,7 +893,7 @@ impl<'open> Window<'open> {
|
||||
let mut resize = resize.id(resize_id);
|
||||
|
||||
let mut area = area.begin(ctx);
|
||||
let win_size = ctx.screen_rect().max.to_vec2();
|
||||
let win_size = ctx.input(|i| i.screen_rect.size());
|
||||
area.state_mut().set_left_top_pos(Pos2::ZERO);
|
||||
area.state_mut().size = win_size;
|
||||
let title_content_spacing = 2.0 * ctx.style().spacing.item_spacing.y;
|
||||
|
||||
@@ -272,7 +272,7 @@ impl ContextImpl {
|
||||
let input = self.input.entry(viewport_id).or_default();
|
||||
// This is a bit hacky, but is required to avoid jitter:
|
||||
let ratio = input.pixels_per_point / new_pixels_per_point;
|
||||
let mut rect = Rect::from_min_max(Pos2::default(), input.screen_rect.max);
|
||||
let mut rect = input.screen_rect;
|
||||
rect.min = (ratio * rect.min.to_vec2()).to_pos2();
|
||||
rect.max = (ratio * rect.max.to_vec2()).to_pos2();
|
||||
new_raw_input.screen_rect = Some(rect);
|
||||
@@ -305,7 +305,7 @@ impl ContextImpl {
|
||||
|
||||
// Ensure we register the background area so panels and background ui can catch clicks:
|
||||
let input = self.input.get(&viewport_id).unwrap();
|
||||
let screen_rect = Rect::from_min_max(Pos2::ZERO, input.screen_rect().max);
|
||||
let screen_rect = input.screen_rect();
|
||||
self.memory.areas.set_state(
|
||||
LayerId::background(),
|
||||
containers::area::State {
|
||||
@@ -1059,7 +1059,7 @@ impl Context {
|
||||
|
||||
/// Get a full-screen painter for a new or existing layer
|
||||
pub fn layer_painter(&self, layer_id: LayerId) -> Painter {
|
||||
let screen_rect = Rect::from_min_max(Pos2::ZERO, self.screen_rect().max);
|
||||
let screen_rect = self.screen_rect();
|
||||
Painter::new(self.clone(), layer_id, screen_rect)
|
||||
}
|
||||
|
||||
@@ -1384,12 +1384,12 @@ impl Context {
|
||||
if window.width() > area.width() {
|
||||
// Allow overlapping side bars.
|
||||
// This is important for small screens, e.g. mobiles running the web demo.
|
||||
let screen_rect = Rect::from_min_max(Pos2::ZERO, self.screen_rect().max);
|
||||
let screen_rect = self.screen_rect();
|
||||
(area.min.x, area.max.x) = (screen_rect.min.x, screen_rect.max.x);
|
||||
}
|
||||
if window.height() > area.height() {
|
||||
// Allow overlapping top/bottom bars:
|
||||
let screen_rect = Rect::from_min_max(Pos2::ZERO, self.screen_rect().max);
|
||||
let screen_rect = self.screen_rect();
|
||||
(area.min.y, area.max.y) = (screen_rect.min.y, screen_rect.max.y);
|
||||
}
|
||||
|
||||
@@ -1599,8 +1599,7 @@ impl Context {
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/// Position and size of the current viewport.
|
||||
/// min is the position, max is the size
|
||||
/// Position and size of the egui area.
|
||||
pub fn screen_rect(&self) -> Rect {
|
||||
self.input(|i| i.screen_rect())
|
||||
}
|
||||
@@ -1973,7 +1972,7 @@ impl Context {
|
||||
size *= (max_preview_size.y / size.y).min(1.0);
|
||||
ui.image(texture_id, size).on_hover_ui(|ui| {
|
||||
// show larger on hover
|
||||
let max_size = 0.5 * ui.ctx().screen_rect().max.to_vec2();
|
||||
let max_size = 0.5 * ui.ctx().screen_rect().size();
|
||||
let mut size = vec2(w as f32, h as f32);
|
||||
size *= max_size.x / size.x.max(max_size.x);
|
||||
size *= max_size.y / size.y.max(max_size.y);
|
||||
|
||||
@@ -91,8 +91,8 @@ impl FrameState {
|
||||
} = self;
|
||||
|
||||
used_ids.clear();
|
||||
*available_rect = Rect::from_min_max(Pos2::ZERO, input.screen_rect().max);
|
||||
*unused_rect = Rect::from_min_max(Pos2::ZERO, input.screen_rect().max);
|
||||
*available_rect = input.screen_rect();
|
||||
*unused_rect = input.screen_rect();
|
||||
*used_by_panels = Rect::NOTHING;
|
||||
*tooltip_state = None;
|
||||
*scroll_delta = input.scroll_delta;
|
||||
|
||||
@@ -229,8 +229,6 @@ impl InputState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Position and size of the current viewport.
|
||||
/// min is the position, max is the size
|
||||
#[inline(always)]
|
||||
pub fn screen_rect(&self) -> Rect {
|
||||
self.screen_rect
|
||||
|
||||
@@ -150,7 +150,7 @@ pub(crate) fn menu_ui<'c, R>(
|
||||
.constrain(true)
|
||||
.fixed_pos(pos)
|
||||
.interactable(true)
|
||||
.drag_bounds(Rect::from_min_max(Pos2::ZERO, ctx.screen_rect().max));
|
||||
.drag_bounds(ctx.screen_rect());
|
||||
|
||||
area.show(ctx, |ui| {
|
||||
set_menu_style(ui.style_mut());
|
||||
@@ -330,8 +330,7 @@ impl MenuRoot {
|
||||
let mut pos = response.rect.left_bottom();
|
||||
if let Some(root) = root.inner.as_mut() {
|
||||
let menu_rect = root.menu_state.read().rect;
|
||||
let screen_rect =
|
||||
Rect::from_min_max(Pos2::ZERO, response.ctx.input(|i| i.screen_rect.max));
|
||||
let screen_rect = response.ctx.input(|i| i.screen_rect);
|
||||
|
||||
if pos.y + menu_rect.height() > screen_rect.max.y {
|
||||
pos.y = screen_rect.max.y - menu_rect.height() - response.rect.height();
|
||||
|
||||
@@ -479,7 +479,7 @@ impl WrapApp {
|
||||
let painter =
|
||||
ctx.layer_painter(LayerId::new(Order::Foreground, Id::new("file_drop_target")));
|
||||
|
||||
let screen_rect = Rect::from_min_max(Pos2::ZERO, ctx.screen_rect().max);
|
||||
let screen_rect = ctx.screen_rect();
|
||||
painter.rect_filled(screen_rect, 0.0, Color32::from_black_alpha(192));
|
||||
painter.text(
|
||||
screen_rect.center(),
|
||||
|
||||
@@ -179,7 +179,7 @@ impl DemoWindows {
|
||||
|
||||
fn mobile_ui(&mut self, ctx: &Context) {
|
||||
if self.about_is_open {
|
||||
let screen_size = ctx.screen_rect().max.to_vec2();
|
||||
let screen_size = ctx.input(|i| i.screen_rect.size());
|
||||
let default_width = (screen_size.x - 20.0).min(400.0);
|
||||
|
||||
let mut close = false;
|
||||
|
||||
@@ -116,6 +116,6 @@ fn test_egui_zero_window_size() {
|
||||
/// Detect narrow screens. This is used to show a simpler UI on mobile devices,
|
||||
/// especially for the web demo at <https://egui.rs>.
|
||||
pub fn is_mobile(ctx: &egui::Context) -> bool {
|
||||
let screen_size = ctx.screen_rect().max;
|
||||
let screen_size = ctx.screen_rect().size();
|
||||
screen_size.x < 550.0
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ fn preview_files_being_dropped(ctx: &egui::Context) {
|
||||
let painter =
|
||||
ctx.layer_painter(LayerId::new(Order::Foreground, Id::new("file_drop_target")));
|
||||
|
||||
let screen_rect = Rect::from_min_max(Pos2::ZERO, ctx.screen_rect().max);
|
||||
let screen_rect = ctx.screen_rect();
|
||||
painter.rect_filled(screen_rect, 0.0, Color32::from_black_alpha(192));
|
||||
painter.text(
|
||||
screen_rect.center(),
|
||||
|
||||
@@ -51,8 +51,6 @@ impl eframe::App for App {
|
||||
"Current Parent Viewport Id: {}",
|
||||
ctx.get_viewport_id()
|
||||
));
|
||||
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
|
||||
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
|
||||
ui.label("Look at the \"Frame: \" will tell you, what viewport is rendering!");
|
||||
{
|
||||
let mut force_embedding = ctx.force_embedding();
|
||||
@@ -335,8 +333,6 @@ impl eframe::App for App {
|
||||
"Current Parent Viewport Id: {}",
|
||||
ctx.get_viewport_id()
|
||||
));
|
||||
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
|
||||
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
|
||||
ui.label(format!("Count: {state}"));
|
||||
if ui.button("Add").clicked() {
|
||||
*state += 1;
|
||||
@@ -350,13 +346,8 @@ impl eframe::App for App {
|
||||
.default_embedded(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.label(format!("Frame: {}", ui.ctx().frame_nr()));
|
||||
ui.label(format!("Frame: {}", ctx.frame_nr()));
|
||||
ui.label(format!("Current Viewport Id: {}", ctx.get_viewport_id()));
|
||||
ui.label(format!(
|
||||
"Current Parent Viewport Id: {}",
|
||||
ctx.get_viewport_id()
|
||||
));
|
||||
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
|
||||
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
|
||||
ui.label(format!("Count: {}", self.sync_window_state));
|
||||
if ui.button("Add").clicked() {
|
||||
self.sync_window_state += 1;
|
||||
|
||||
Reference in New Issue
Block a user