Compare commits

...

2 Commits

View File

@ -7,7 +7,7 @@ mod roll;
mod roll_view;
use edit_films::EditFilmsWindow;
use eframe::egui::{self, menu, Button, Label, Response, Sense};
use eframe::egui::{self, menu, widgets, Button, Label, Response, Sense};
use film::{Film, FilmKey};
use new_roll::NewRollWindow;
use roll::Roll;
@ -41,7 +41,6 @@ struct MyApp {
roll_views: Vec<RollViewWindow>,
new_roll_window: Option<NewRollWindow>,
edit_films_window: Option<EditFilmsWindow>,
film_rows_popup_location: Option<Response>,
}
impl MyApp {
@ -56,7 +55,6 @@ impl MyApp {
roll_views: Vec::new(),
new_roll_window: None,
edit_films_window: None,
film_rows_popup_location: None,
}
}
}
@ -83,75 +81,47 @@ impl eframe::App for MyApp {
ui.heading("Film Manager");
egui::Grid::new("roll_table")
.striped(true)
.num_columns(4)
.num_columns(6)
.show(ui, |ui| {
ui.heading("ID");
ui.heading("ID");
ui.heading("Name");
ui.heading("Date");
ui.heading("Exposures");
ui.heading("Film");
ui.heading("Shot at");
ui.end_row();
for (i, roll) in self.state.rolls.iter().enumerate() {
let id_label = ui.add(Label::new(&roll.id).sense(Sense::click()));
let name_label = ui.add(Label::new(&roll.name).sense(Sense::click()));
let date_label = ui.add(
let mut widget_resps = Vec::new();
widget_resps.push(ui.add(Label::new(&roll.id).sense(Sense::click())));
widget_resps.push(ui.add(Label::new(&roll.name).sense(Sense::click())));
widget_resps.push(ui.add(
Label::new(&roll.date.format("%Y-%m-%d").to_string())
.sense(Sense::click()),
);
let exps_label = ui.add(
));
widget_resps.push(ui.add(
Label::new(&roll.exposures.len().to_string()).sense(Sense::click()),
);
let clicked = id_label.clicked()
|| name_label.clicked()
|| date_label.clicked()
|| exps_label.clicked();
let old_film_rows_popup_location = self.film_rows_popup_location.clone();
let secondary_clicked = if id_label.secondary_clicked() {
self.film_rows_popup_location = Some(id_label.clone());
true
} else if name_label.secondary_clicked() {
self.film_rows_popup_location = Some(name_label.clone());
true
} else if date_label.secondary_clicked() {
self.film_rows_popup_location = Some(date_label.clone());
true
} else if exps_label.secondary_clicked() {
self.film_rows_popup_location = Some(exps_label.clone());
true
));
widget_resps.push(ui.add(
Label::new(&self.state.films[roll.film].name).sense(Sense::click()),
));
let shot_at_text = if let Some(shot_at) = roll.shot_at {
format!("{} ISO", shot_at)
} else {
false
format!("{} ISO (box speed)", &self.state.films[roll.film].iso)
};
let hovered = id_label.hovered()
|| name_label.hovered()
|| date_label.hovered()
|| exps_label.hovered();
if hovered {
id_label.highlight();
name_label.highlight();
date_label.highlight();
exps_label.highlight();
}
if clicked && !self.roll_views.iter().any(|view| view.roll() == i) {
widget_resps.push(ui.add(Label::new(shot_at_text).sense(Sense::click())));
if widget_resps.iter().any(|resp| resp.clicked())
&& !self.roll_views.iter().any(|view| view.roll() == i)
{
self.roll_views.push(RollViewWindow::new(i));
}
let popup_id = ui.make_persistent_id("roll_context_menu");
if secondary_clicked {
if self.film_rows_popup_location.is_some()
&& self.film_rows_popup_location.as_ref().map(|resp| resp.id)
== old_film_rows_popup_location.as_ref().map(|resp| resp.id)
{
ui.memory_mut(|mem| mem.close_popup());
} else {
ui.memory_mut(|mem| mem.open_popup(popup_id));
let hovered = widget_resps.iter().any(|resp| resp.hovered());
for widget_resp in widget_resps {
if hovered {
widget_resp.highlight();
}
}
if let Some(film_rows_popup_location) = &self.film_rows_popup_location {
egui::popup_below_widget(
ui,
popup_id,
&film_rows_popup_location,
|_ui| {},
);
}
ui.end_row();
}
});