Skip to content

Commit

Permalink
Add function to set the ID of the window (#16)
Browse files Browse the repository at this point in the history
* Add function to set the window ID

* Update CHANGELOG.md
  • Loading branch information
fluxxcode authored Feb 4, 2024
1 parent f8548cb commit 5988858
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion examples/sandbox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// The ID of the window.
window_id: Option<egui::Id>,
/// The default size of the window.
window_default_size: egui::Vec2,
/// The anchor of the window.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -193,6 +196,12 @@ impl FileDialog {
self
}

/// Sets the ID of the window.
pub fn id(mut self, id: impl Into<egui::Id>) -> Self {
self.window_id = Some(id.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 @@ -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);
}
Expand Down

0 comments on commit 5988858

Please sign in to comment.