Skip to content

Commit

Permalink
gallery slider and user flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Stehfyn committed Sep 10, 2023
1 parent b18cb91 commit 639915c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ impl eframe::App for TemplateApp {
.clicked()
{
self.gallery_panel.open = !self.gallery_panel.open;
#[cfg(target_arch = "wasm32")]
if isIOS() || isMobile() {
if self.gallery_panel.open {
self.puzzle_panel.open = false;
self.settings_panel.open = false;
self.about_panel.open = false;
} else {
self.puzzle_panel.open = true;
self.settings_panel.open = true;
}
}
}
if ui
.add_sized(
Expand All @@ -194,6 +205,7 @@ impl eframe::App for TemplateApp {
.clicked()
{
self.puzzle_panel.open = true;
self.settings_panel.open = true;
self.gallery_panel.open = false;
self.about_panel.open = false;
}
Expand Down
33 changes: 31 additions & 2 deletions src/gallery_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ pub struct GalleryPanel {
random_label: String,
#[cfg_attr(feature = "serde", serde(skip))]
gallery_img_width: f32,
#[cfg_attr(feature = "serde", serde(skip))]
gallery_img_width_min: f32,
#[cfg_attr(feature = "serde", serde(skip))]
gallery_img_width_max: f32,
#[cfg_attr(feature = "serde", serde(skip))]
init_slider_bounds: bool,
}

impl Default for GalleryPanel {
Expand All @@ -121,6 +127,9 @@ impl Default for GalleryPanel {
upload_label: "Upload Image".to_owned(),
random_label: "Random Image".to_owned(),
gallery_img_width: 146.,
gallery_img_width_min: 146.,
gallery_img_width_max: 146.,
init_slider_bounds: false,
}
}
}
Expand Down Expand Up @@ -405,7 +414,10 @@ impl GalleryPanel {
ui.add(
egui::Slider::new(
&mut self.gallery_img_width,
std::ops::RangeInclusive::new(50., 400.),
std::ops::RangeInclusive::new(
self.gallery_img_width_min,
self.gallery_img_width_max,
),
)
.show_value(false)
.trailing_fill(true),
Expand All @@ -419,7 +431,23 @@ impl GalleryPanel {
- (ui.ctx().style().spacing.item_spacing.x * 2.)
- ui.ctx().style().spacing.scroll_bar_width;
let mut bid = ui.next_auto_id();

let w_for_3 = (ui.available_width() / 3.)
- ui.ctx().style().spacing.button_padding.x
- ui.ctx().style().spacing.item_spacing.x
- ui.ctx().style().spacing.window_margin.right;
//- ui.ctx().style().spacing.;
self.gallery_img_width_min = w_for_3;
let w_for_1 = ui.available_width()
- ui.ctx().style().spacing.button_padding.x
- ui.ctx().style().spacing.item_spacing.x
- ui.ctx().style().spacing.item_spacing.x
- ui.ctx().style().spacing.scroll_bar_width
- ui.ctx().style().spacing.window_margin.right;
self.gallery_img_width_max = w_for_1;
if !self.init_slider_bounds {
self.gallery_img_width = self.gallery_img_width_min;
self.init_slider_bounds = true;
}
egui::ScrollArea::new([false, true])
.auto_shrink([false, false])
.max_width(ui.available_width())
Expand All @@ -428,6 +456,7 @@ impl GalleryPanel {
.show(ui, |ui| {
egui::Grid::new("neato").show(ui, |ui| {
let mut row_w_accum = 0.;

for (i, img) in self.img.iter_mut().enumerate() {
if let Some((texture_id, size)) = texture_ids_and_sizes.get(i) {
let _bid = ui.next_auto_id();
Expand Down

0 comments on commit 639915c

Please sign in to comment.