Skip to content

Commit

Permalink
Use _px suffix for things in pixel units
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 12, 2023
1 parent a3c7bdd commit 5892d05
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl State {
None
};

let inner_pos = if getting_info {
let inner_pos_px = if getting_info {
window
.inner_position()
.map(|pos| Pos2::new(pos.x as f32, pos.y as f32))
Expand All @@ -218,7 +218,7 @@ impl State {
None
};

let outer_pos = if getting_info {
let outer_pos_px = if getting_info {
window
.outer_position()
.map(|pos| Pos2::new(pos.x as f32, pos.y as f32))
Expand All @@ -227,30 +227,30 @@ impl State {
None
};

let inner_size = if getting_info {
let inner_size_px = if getting_info {
let size = window.inner_size();
Some(Vec2::new(size.width as f32, size.height as f32))
} else {
None
};

let outer_size = if getting_info {
let outer_size_px = if getting_info {
let size = window.outer_size();
Some(Vec2::new(size.width as f32, size.height as f32))
} else {
None
};

self.egui_input.viewport.id_pair = id_pair;
self.egui_input.viewport.inner_rect =
if let (Some(pos), Some(size)) = (inner_pos, inner_size) {
self.egui_input.viewport.inner_rect_px =
if let (Some(pos), Some(size)) = (inner_pos_px, inner_size_px) {
Some(Rect::from_min_size(pos, size))
} else {
None
};

self.egui_input.viewport.outer_rect =
if let (Some(pos), Some(size)) = (outer_pos, outer_size) {
self.egui_input.viewport.outer_rect_px =
if let (Some(pos), Some(size)) = (outer_pos_px, outer_size_px) {
Some(Rect::from_min_size(pos, size))
} else {
None
Expand Down
12 changes: 6 additions & 6 deletions crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ pub struct ViewportInfo {

/// Viewport inner position and size, only the drowable area
/// unit = physical pixels
pub inner_rect: Option<Rect>,
pub inner_rect_px: Option<Rect>,

/// Viewport outer position and size, drowable area + decorations
/// unit = physical pixels
pub outer_rect: Option<Rect>,
pub outer_rect_px: Option<Rect>,

/// Viewport should close?
pub close_requested: bool,
Expand All @@ -165,13 +165,13 @@ impl ViewportInfo {
pub fn ui(&self, ui: &mut crate::Ui) {
let Self {
id_pair,
inner_rect,
outer_rect,
inner_rect_px,
outer_rect_px,
close_requested,
} = self;
ui.label(format!("id_pair: {id_pair:?}"));
ui.label(format!("inner_rect: {inner_rect:?}"));
ui.label(format!("outer_rect: {outer_rect:?}"));
ui.label(format!("inner_rect_px: {inner_rect_px:?}"));
ui.label(format!("outer_rect_px: {outer_rect_px:?}"));
ui.label(format!("close_requested: {close_requested:?}"));
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/test_viewports/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ fn generic_ui(ui: &mut egui::Ui, children: &[Arc<RwLock<ViewportState>>]) {

ui.add_space(8.0);

if let Some(inner_rect) = ctx.input(|i| i.raw.viewport.inner_rect) {
if let Some(inner_rect) = ctx.input(|i| i.raw.viewport.inner_rect_px) {
ui.label(format!(
"Inner Rect: Pos: {:?}, Size: {:?}",
inner_rect.min,
inner_rect.size()
));
}
if let Some(outer_rect) = ctx.input(|i| i.raw.viewport.outer_rect) {
if let Some(outer_rect) = ctx.input(|i| i.raw.viewport.outer_rect_px) {
ui.label(format!(
"Outer Rect: Pos: {:?}, Size: {:?}",
outer_rect.min,
Expand Down

0 comments on commit 5892d05

Please sign in to comment.