Skip to content

Commit

Permalink
Add functions to set window position
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxcode committed Feb 4, 2024
1 parent 5988858 commit e90d108
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 1 addition & 3 deletions examples/sandbox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ struct MyApp {
impl MyApp {
pub fn new(_cc: &eframe::CreationContext) -> Self {
Self {
file_dialog: FileDialog::new()
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::new(0.0, 0.0))
.id("egui_file_dialog"),
file_dialog: FileDialog::new().id("egui_file_dialog"),

selected_directory: None,
selected_file: None,
Expand Down
26 changes: 26 additions & 0 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ pub struct FileDialog {
window_overwrite_title: Option<String>,
/// The ID of the window.
window_id: Option<egui::Id>,
/// The default position of the window.
window_default_pos: Option<egui::Pos2>,
/// Sets the window position and prevents it from being dragged around.
window_fixed_pos: Option<egui::Pos2>,
/// The default size of the window.
window_default_size: egui::Vec2,
/// The anchor of the window.
Expand Down Expand Up @@ -158,6 +162,8 @@ impl FileDialog {
window_title: String::from("Select directory"),
window_overwrite_title: None,
window_id: None,
window_default_pos: None,
window_fixed_pos: None,
window_default_size: egui::Vec2::new(650.0, 370.0),
window_anchor: None,
window_resizable: true,
Expand Down Expand Up @@ -202,6 +208,18 @@ impl FileDialog {
self
}

/// Sets the default position of the window.
pub fn default_pos(mut self, default_pos: impl Into<egui::Pos2>) -> Self {
self.window_default_pos = Some(default_pos.into());
self
}

/// Sets the window position and prevents it from being dragged around.
pub fn fixed_pos(mut self, pos: impl Into<egui::Pos2>) -> Self {
self.window_fixed_pos = Some(pos.into());
self
}

/// Sets the default size of the window.
pub fn default_size(mut self, size: impl Into<egui::Vec2>) -> Self {
self.window_default_size = size.into();
Expand Down Expand Up @@ -388,6 +406,14 @@ impl FileDialog {
window = window.id(id);
}

if let Some(pos) = self.window_default_pos {
window = window.default_pos(pos);
}

if let Some(pos) = self.window_fixed_pos {
window = window.fixed_pos(pos);
}

if let Some((anchor, offset)) = self.window_anchor {
window = window.anchor(anchor, offset);
}
Expand Down

0 comments on commit e90d108

Please sign in to comment.