Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to set the ID of the window #16

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading