Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ui-egui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ impl LightcraftApp {
// then draws with the new visuals. `ui` keeps its own call for a settings change made by
// a command during the same pass; it is a no-op when the theme already matches.
self.sync_theme(ctx);
panels::left::follow_shown(self, ctx);
self.logic_background(ctx);
self.perf.logic_ms = monotonic_ms() - t0;
}
Expand Down
10 changes: 10 additions & 0 deletions crates/ui-egui/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequest
Ok(s) => s,
Err(e) => return err(e),
};
// and so are the rows of its trees, which a settings file's are read past
let trees = match p.get("sidebarTrees").map(crate::tree_state::TreeState::parse).transpose() {
Ok(t) => t,
Err(e) => return err(format!("ui.set: {e}")),
};
let mut v = serde_json::to_value(&app.ui).unwrap_or_default();
lightcraft_develop::presets::deep_merge(&mut v, p);
match serde_json::from_value::<crate::UiState>(v) {
Expand All @@ -385,6 +390,11 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequest
if let Some(sidebar) = sidebar {
u.sidebar = sidebar;
}
if let Some(trees) = trees {
u.sidebar_trees = trees;
}
// (rows open for the session are not in what was written and read again)
u.sidebar_trees.carry_shown(&app.ui.sidebar_trees);
// `collapsedSidebar`, as scripts from before `sidebar` set it: the folded sections
if let Some(ids) = p.get("collapsedSidebar").and_then(Value::as_array) {
use crate::sidebar::SidebarSection;
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod state;
pub mod sync;
pub mod tasks;
pub mod theme;
pub mod tree_state;
pub mod widgets;
pub mod window_place;

Expand Down
13 changes: 9 additions & 4 deletions crates/ui-egui/src/panels/left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::LightcraftApp;
use crate::icons::{Icon, paint};
use crate::sidebar::SidebarSection;
use crate::theme::Tokens;
use crate::tree_state::{Branch, TreeState};
use crate::widgets::{icon_button, register};

mod albums;
Expand All @@ -23,14 +24,15 @@ pub use albums::{album_drag_feedback, auto_scroll_speed};
use albums::{albums_rows, drag_auto_scroll};
pub(crate) use dates::browse_all_photos;
use dates::date_rows;
pub(crate) use folders::follow_shown;
pub(crate) use folders::{folder_row_of, move_photos, moved_text};
use folders::{folder_rows, reveal_chosen};
use keywords::keyword_rows;
pub(crate) use local::{fs_cached, fs_cached_running, same_folder};
use local::{local_now, local_rows};
#[cfg(test)]
pub(crate) use rows::{INDENT_STEP, MIN_INDENT_STEP};
use rows::{LIBFOLDER_REVEALED, Row, SCROLL_TO_ROW, set_tree_open};
use rows::{LIBFOLDER_REVEALED, Row, SCROLL_TO_ROW};
pub(crate) use rows::{content_width, indent_step, step_for};
pub(crate) use sections::PlacedSection;
pub use sections::section_drag_feedback;
Expand All @@ -43,6 +45,8 @@ use sections::{SECTION_GAP, missing_count, pinned_header, section, section_drag,
pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
let t = Tokens::get(ui.ctx());
let frame = egui::Frame::NONE.fill(t.chrome).stroke(egui::Stroke::new(1.0, t.divider));
// (a library opened since the frame began is known before its rows are shown)
follow_shown(app, ui.ctx());
frame.show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 0.0;
// the title offers the sections' menu too: where hidden sections come back from
Expand Down Expand Up @@ -129,14 +133,15 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
above.push('|');
}
above.push_str(name);
set_tree_open(ui, egui::Id::unique(("kw-open", above.to_lowercase())), true);
app.ui.sidebar_trees.show(&Branch::keyword(&above));
}
// …and the sidebar scrolls to it
ui.data_mut(|d| d.insert_temp(egui::Id::unique(SCROLL_TO_ROW), format!("keyword:{path}").to_lowercase()));
}
// the folder Show in Folders went to: Folders is shown and opened, and so are the
// folders above it, also when it was already the one shown and one was folded by hand…
if let Some(path) = app.ui.reveal_folder.take() {
let reveal_folder = app.ui.reveal_folder.take();
if let Some(path) = &reveal_folder {
app.ui.sidebar.reveal(SidebarSection::Folders);
ui.data_mut(|d| d.remove::<Option<String>>(egui::Id::unique(LIBFOLDER_REVEALED)));
// …and the sidebar scrolls to it
Expand All @@ -163,7 +168,7 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
SidebarSection::Folders => {
let tree = app.caches.folder_tree(&app.session.catalog);
section(app, ui, s, tree.len(), |app, ui| {
reveal_chosen(app, ui, &tree);
reveal_chosen(app, ui, &tree, reveal_folder.is_some());
folder_rows(app, ui, &tree, 0.0);
})
}
Expand Down
16 changes: 8 additions & 8 deletions crates/ui-egui/src/panels/left/albums.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::folders::{folder_menu, is_within};
use super::rows::{INDENT_STEP, Row, indent_x, set_tree_open, tree_open, tree_toggle};
use super::{Album, AlbumId, Align2, Icon, LibrarySource, LightcraftApp, Rect, Sense, Tokens, json, pos2, register, vec2};
use super::rows::{INDENT_STEP, Row, indent_x, tree_toggle};
use super::{Album, AlbumId, Align2, Branch, Icon, LibrarySource, LightcraftApp, Rect, Sense, Tokens, json, pos2, register, vec2};

/// Albums: the tree of albums and the folders they are sorted into. `reveal`: an album just made,
/// whose folders open down to it.
Expand Down Expand Up @@ -28,11 +28,11 @@ fn albums_tree(app: &mut LightcraftApp, ui: &mut egui::Ui, all: &AlbumKids, pare
let Some(kids) = all.get(&parent) else { return };
for a in kids {
if a.folder {
let open_id = egui::Id::unique(("folder-open", a.id.0));
let mut open = tree_open(ui, open_id, true);
let branch = Branch::album(a.id.0);
let mut open = app.ui.sidebar_trees.is_open(&branch);
if open_to.contains(&a.id) && !open {
open = true;
set_tree_open(ui, open_id, true);
app.ui.sidebar_trees.show(&branch);
}
let resp = Row::new(&format!("folder:{}", a.id.0), Icon::Folder, &a.name).indent(indent).sense(Sense::click_and_drag()).show(app, ui);
// a folder is no source, so its row folds it too; the triangle is the same click, aimed
Expand All @@ -41,20 +41,20 @@ fn albums_tree(app: &mut LightcraftApp, ui: &mut egui::Ui, all: &AlbumKids, pare
app.ui.dragging_album = Some(a.id.0);
}
if album_drag_over(app, ui, &resp, a, has_children.then_some(&mut open), indent) {
set_tree_open(ui, open_id, true);
app.ui.sidebar_trees.show(&branch);
}
// what this frame draws; a click shows from the next one
let draw_open = open;
let mut toggled = false;
if has_children {
let tri = tree_toggle(ui, &resp, indent, open_id, &mut open, format!("albumToggle:{}", a.id.0));
let tri = tree_toggle(ui, &mut app.ui.sidebar_trees, &resp, indent, &branch, &mut open, format!("albumToggle:{}", a.id.0));
toggled = tri.clicked();
// the triangle sits on the row and takes its clicks: the menu opens from it too
folder_menu(app, &tri, a);
}
// one click, one toggle: the triangle's is not the row's as well
if resp.clicked() && !toggled {
set_tree_open(ui, open_id, !open);
app.ui.sidebar_trees.set(&branch, !open);
}
folder_menu(app, &resp, a);
if draw_open {
Expand Down
10 changes: 5 additions & 5 deletions crates/ui-egui/src/panels/left/dates.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::rows::{INDENT_STEP, Row, tree_open, tree_toggle};
use super::{Icon, LibrarySource, LightcraftApp, json};
use super::rows::{INDENT_STEP, Row, tree_toggle};
use super::{Branch, Icon, LibrarySource, LightcraftApp, json};

/// By Date: year → month → day; a click filters by that prefix, the triangle opens a level.
pub(super) fn date_rows(app: &mut LightcraftApp, ui: &mut egui::Ui) {
Expand All @@ -21,12 +21,12 @@ pub(super) fn date_rows(app: &mut LightcraftApp, ui: &mut egui::Ui) {

/// One By Date row (`key`: `YYYY`, `YYYY-MM` or `YYYY-MM-DD`); returns whether it is open.
fn date_row(app: &mut LightcraftApp, ui: &mut egui::Ui, key: &str, label: &str, count: usize, indent: f32) -> bool {
let open_id = egui::Id::unique(("date-open", key.to_string()));
let mut open = tree_open(ui, open_id, false);
let branch = Branch::date(key);
let mut open = app.ui.sidebar_trees.is_open(&branch);
let sel = app.session.filter.date.as_deref() == Some(key);
let resp = Row::new(&format!("date:{key}"), Icon::Clock, label).count(Some(count)).selected(sel).indent(indent).show(app, ui);
if key.len() < 10 {
tree_toggle(ui, &resp, indent, open_id, &mut open, format!("dateToggle:{key}"));
tree_toggle(ui, &mut app.ui.sidebar_trees, &resp, indent, &branch, &mut open, format!("dateToggle:{key}"));
}
if resp.clicked() {
let v = if sel { serde_json::Value::Null } else { json!(key) };
Expand Down
Loading
Loading