Skip to content

Commit 96335d5

Browse files
authored
added epi::Frame::set_window_pos (#1505)
this allows setting the position of window at runtime
1 parent 2b861f8 commit 96335d5

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

egui-winit/src/epi.rs

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub fn handle_app_output(
9696
window_title,
9797
decorated,
9898
drag_window,
99+
window_pos,
99100
} = app_output;
100101

101102
if let Some(decorated) = decorated {
@@ -116,6 +117,13 @@ pub fn handle_app_output(
116117
window.set_title(&window_title);
117118
}
118119

120+
if let Some(window_pos) = window_pos {
121+
window.set_outer_position(winit::dpi::PhysicalPosition {
122+
x: window_pos.x as f64,
123+
y: window_pos.y as f64,
124+
});
125+
}
126+
119127
if drag_window {
120128
let _ = window.drag_window();
121129
}

egui_web/src/backend.rs

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ impl AppRunner {
268268
window_title: _, // TODO: change title of window
269269
decorated: _, // Can't toggle decorations
270270
drag_window: _, // Can't be dragged
271+
window_pos: _, // Can't set position of a web page
271272
} = app_output;
272273
}
273274

epi/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ impl Frame {
323323
self.output.decorated = Some(decorated);
324324
}
325325

326+
/// set the position of the outer window
327+
pub fn set_window_pos(&mut self, pos: egui::Pos2) {
328+
self.output.window_pos = Some(pos);
329+
}
330+
326331
/// When called, the native window will follow the
327332
/// movement of the cursor while the primary mouse button is down.
328333
///
@@ -503,5 +508,8 @@ pub mod backend {
503508

504509
/// Set to true to drag window while primary mouse button is down.
505510
pub drag_window: bool,
511+
512+
/// Set to some position to move the outer window (e.g. glium window) to this position
513+
pub window_pos: Option<egui::Pos2>,
506514
}
507515
}

0 commit comments

Comments
 (0)