1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -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:
Konkitoman
2023-08-24 07:55:56 +03:00
parent c9faa78e5b
commit 9c73c2f4b1
15 changed files with 34 additions and 47 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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| {

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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

View File

@@ -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();