Show film rolls in a table
This commit is contained in:
parent
ae1dd2b771
commit
3ff8bc276b
89
src/main.rs
89
src/main.rs
@ -7,7 +7,7 @@ mod roll;
|
||||
mod roll_view;
|
||||
|
||||
use edit_films::EditFilmsWindow;
|
||||
use eframe::egui::{self, menu, Button};
|
||||
use eframe::egui::{self, menu, Button, Label, Response, Sense};
|
||||
use film::{Film, FilmKey};
|
||||
use new_roll::NewRollWindow;
|
||||
use roll::Roll;
|
||||
@ -41,6 +41,7 @@ struct MyApp {
|
||||
roll_views: Vec<RollViewWindow>,
|
||||
new_roll_window: Option<NewRollWindow>,
|
||||
edit_films_window: Option<EditFilmsWindow>,
|
||||
film_rows_popup_location: Option<Response>,
|
||||
}
|
||||
|
||||
impl MyApp {
|
||||
@ -55,6 +56,7 @@ impl MyApp {
|
||||
roll_views: Vec::new(),
|
||||
new_roll_window: None,
|
||||
edit_films_window: None,
|
||||
film_rows_popup_location: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,17 +81,80 @@ impl eframe::App for MyApp {
|
||||
});
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Film Manager");
|
||||
ui.label("Rolls:");
|
||||
for (i, roll) in self.state.rolls.iter().enumerate() {
|
||||
let has_view = self.roll_views.iter().any(|view| view.roll() == i);
|
||||
if ui
|
||||
.add_enabled(!has_view, Button::new(roll.short_str()))
|
||||
.clicked()
|
||||
&& !has_view
|
||||
{
|
||||
self.roll_views.push(RollViewWindow::new(i));
|
||||
}
|
||||
}
|
||||
egui::Grid::new("roll_table")
|
||||
.striped(true)
|
||||
.num_columns(4)
|
||||
.show(ui, |ui| {
|
||||
ui.heading("ID");
|
||||
ui.heading("Name");
|
||||
ui.heading("Date");
|
||||
ui.heading("Exposures");
|
||||
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(
|
||||
Label::new(&roll.date.format("%Y-%m-%d").to_string())
|
||||
.sense(Sense::click()),
|
||||
);
|
||||
let exps_label = 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
|
||||
} else {
|
||||
false
|
||||
};
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
});
|
||||
if ui
|
||||
.add_enabled(self.new_roll_window.is_none(), egui::Button::new("Add"))
|
||||
.clicked()
|
||||
|
Loading…
Reference in New Issue
Block a user