Skip to content

Commit

Permalink
Implements an option to keep the file dialog above all other windows. (
Browse files Browse the repository at this point in the history
…#43)

* Implemented a keep_on_top flag that always render the FileDialog at the top of other windows.

* Fixed indentation.

* Fixed indentation.
  • Loading branch information
GuillaumeSchmid authored Mar 19, 2024
1 parent e11589a commit bd4b55c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub struct FileDialog {
new_folder: bool,
multi_select_enabled: bool,
range_start: Option<usize>,
keep_on_top: bool,

/// Show drive letters on Windows.
#[cfg(windows)]
Expand Down Expand Up @@ -99,8 +100,8 @@ impl Debug for FileDialog {
.field("rename", &self.rename)
.field("new_folder", &self.new_folder)
.field("multi_select", &self.multi_select_enabled)
.field("range_start", &self.range_start);

.field("range_start", &self.range_start)
.field("keep_on_top", &self.keep_on_top);
// Closures don't implement std::fmt::Debug.
// .field("shown_files_filter", &self.shown_files_filter)
// .field("filename_filter", &self.filename_filter)
Expand Down Expand Up @@ -179,6 +180,7 @@ impl FileDialog {
show_hidden: false,
multi_select_enabled: false,
range_start: None,
keep_on_top: false,
}
}

Expand Down Expand Up @@ -269,6 +271,11 @@ impl FileDialog {
self
}

pub fn keep_on_top(mut self, keep_on_top: bool) -> Self {
self.keep_on_top = keep_on_top;
self
}

/// Get the dialog type.
pub fn dialog_type(&self) -> DialogType {
self.dialog_type
Expand Down Expand Up @@ -462,7 +469,12 @@ impl FileDialog {
window = window.current_pos(current_pos);
}

window.show(ctx, |ui| self.ui_in_window(ui));
window.show(ctx, |ui| {
if self.keep_on_top {
ui.ctx().move_to_top(ui.layer_id());
}
self.ui_in_window(ui)
});
}

fn ui_in_window(&mut self, ui: &mut Ui) {
Expand Down

0 comments on commit bd4b55c

Please sign in to comment.