From 598885865aa0051e2b99982791b50da51bd74d4e Mon Sep 17 00:00:00 2001 From: Jannis Date: Sun, 4 Feb 2024 19:43:43 +0100 Subject: [PATCH] Add function to set the ID of the window (#16) * Add function to set the window ID * Update CHANGELOG.md --- CHANGELOG.md | 1 + examples/sandbox/src/main.rs | 3 ++- src/file_dialog.rs | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ed14740..bf162748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added `FileDialog::title` to overwrite the window title [#12](https://github.com/fluxxcode/egui-file-dialog/pull/12) - Added `FileDialog::resizable` to set if the window is resizable [#15](https://github.com/fluxxcode/egui-file-dialog/pull/15) - Added `FileDialog::movable` to set if the window is movable [#15](https://github.com/fluxxcode/egui-file-dialog/pull/15) +- Added `FileDialog::id` to set the ID of the window [#16](https://github.com/fluxxcode/egui-file-dialog/pull/16) ### 🔧 Changes - Removed the version of `egui-file-dialog` in the examples [#8](https://github.com/fluxxcode/egui-file-dialog/pull/8) diff --git a/examples/sandbox/src/main.rs b/examples/sandbox/src/main.rs index b6f2dbc8..c9d74765 100644 --- a/examples/sandbox/src/main.rs +++ b/examples/sandbox/src/main.rs @@ -15,7 +15,8 @@ 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)), + .anchor(egui::Align2::CENTER_CENTER, egui::Vec2::new(0.0, 0.0)) + .id("egui_file_dialog"), selected_directory: None, selected_file: None, diff --git a/src/file_dialog.rs b/src/file_dialog.rs index 210fb8a3..ee2c6dc7 100644 --- a/src/file_dialog.rs +++ b/src/file_dialog.rs @@ -100,6 +100,8 @@ pub struct FileDialog { /// If set, the window title will be overwritten and set to the fixed value instead /// of being set dynamically. window_overwrite_title: Option, + /// The ID of the window. + window_id: Option, /// The default size of the window. window_default_size: egui::Vec2, /// The anchor of the window. @@ -155,6 +157,7 @@ impl FileDialog { window_title: String::from("Select directory"), window_overwrite_title: None, + window_id: None, window_default_size: egui::Vec2::new(650.0, 370.0), window_anchor: None, window_resizable: true, @@ -193,6 +196,12 @@ impl FileDialog { self } + /// Sets the ID of the window. + pub fn id(mut self, id: impl Into) -> Self { + self.window_id = Some(id.into()); + self + } + /// Sets the default size of the window. pub fn default_size(mut self, size: impl Into) -> Self { self.window_default_size = size.into(); @@ -375,6 +384,10 @@ impl FileDialog { .movable(self.window_movable) .collapsible(false); + if let Some(id) = self.window_id { + window = window.id(id); + } + if let Some((anchor, offset)) = self.window_anchor { window = window.anchor(anchor, offset); }