Skip to content

Commit

Permalink
more layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Stehfyn committed Sep 11, 2023
1 parent 639915c commit 69b84a8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl TemplateApp {
let is_open = self.settings_panel.open || ctx.memory(|mem| mem.everything_is_visible());
let mut cmd = Command::Nothing;
egui::TopBottomPanel::bottom("settings_panel")
.exact_height(self.screen_rect.height() * 0.15)
.exact_height(self.settings_panel.calc_panel_ui_height())
.resizable(false)
.show_animated(ctx, is_open, |ui| {
let mut style = (*ctx.style()).clone();
Expand Down
28 changes: 27 additions & 1 deletion src/gallery_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,32 @@ impl GalleryPanel {
}
}
}
fn calc_clear_ui_height(&mut self, ui: &egui::Ui) -> f32 {
let clear_gallery_button_height = ui
.painter()
.layout(
"Clear Gallery".to_owned(),
egui::FontId::new(self.upload_ui_font_size, egui::FontFamily::Proportional),
egui::Color32::default(),
MAX_WRAP,
)
.rect
.height();

let source_code_hyperlink_height = ui
.painter()
.layout(
"(source code)".to_owned(),
egui::FontId::new(12.0, egui::FontFamily::Proportional),
egui::Color32::default(),
MAX_WRAP,
)
.rect
.height();
2. * (clear_gallery_button_height
+ source_code_hyperlink_height
+ (ui.ctx().style().spacing.item_spacing.y * 3.))
}
fn detect_files_being_dropped(&mut self, ctx: &egui::Context) {
use egui::*;

Expand Down Expand Up @@ -451,7 +477,7 @@ impl GalleryPanel {
egui::ScrollArea::new([false, true])
.auto_shrink([false, false])
.max_width(ui.available_width())
.max_height(ui.available_height() * 0.75)
.max_height(ui.available_height() - self.calc_clear_ui_height(ui))
.drag_to_scroll(true)
.show(ui, |ui| {
egui::Grid::new("neato").show(ui, |ui| {
Expand Down
15 changes: 13 additions & 2 deletions src/settings_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,16 @@ impl SettingsPanel {

width
}
fn calc_upload_ui_button_height(&mut self) -> f32 {
fn calc_button_ui_height(&mut self) -> f32 {
// Look at the tallest button
self.button_ui_rects
.iter()
.map(|r| r.height())
.fold(f32::NEG_INFINITY, |a, b| a.max(b))
}
pub fn calc_panel_ui_height(&mut self) -> f32 {
self.calc_button_ui_height() * 7.40
}
fn puzzle_settings_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
ui.with_layout(egui::Layout::left_to_right(egui::Align::LEFT), |ui| {
let slider_width = (self.puzzle_panel_constrained_width / 2.)
Expand Down Expand Up @@ -230,7 +233,7 @@ impl SettingsPanel {
)
};
let bw = (avail_w / 2.) - ui.ctx().style().spacing.item_spacing.x;
let bh = self.calc_upload_ui_button_height() * 2.;
let bh = self.calc_button_ui_height() * 2.;
ui.add_space(offset_w);
if ui
.add_sized(
Expand Down Expand Up @@ -270,6 +273,14 @@ impl SettingsPanel {
});
}
});
ui.separator();

ui.centered(|ui| {
ui.add(egui::Hyperlink::from_label_and_url(
egui::RichText::new("(source code)").size(12.),
"https://github.com/Stehfyn/cs481/blob/main/src/settings_panel.rs",
));
});
//ui.radio_value(&mut self.run_mode, RunMode::Dfs, "DFS");
//ui.radio_value(&mut self.run_mode, RunMode::Bfs, "BFS");
}
Expand Down

0 comments on commit 69b84a8

Please sign in to comment.