Skip to content

armgit / klad

Public Imported from GitHub
0

A drawing app built for agent/human collaboration

Rust

Recent and Samples are rows that scroll sideways

Indicode BVb8b9e52ea0d6
diff --git a/Cargo.lock b/Cargo.lock
index ea19ec9..05e0cfe 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1744,7 +1744,7 @@ dependencies = [
[[package]]
name = "klad-app"
-version = "0.1.4"
+version = "0.1.12"
dependencies = [
"anyhow",
"block2 0.6.2",
@@ -1773,7 +1773,7 @@ dependencies = [
[[package]]
name = "klad-brush"
-version = "0.1.4"
+version = "0.1.12"
dependencies = [
"anyhow",
"bytemuck",
@@ -1789,7 +1789,7 @@ dependencies = [
[[package]]
name = "klad-cli"
-version = "0.1.4"
+version = "0.1.12"
dependencies = [
"anyhow",
"clap",
@@ -1815,7 +1815,7 @@ dependencies = [
[[package]]
name = "klad-core"
-version = "0.1.4"
+version = "0.1.12"
dependencies = [
"anyhow",
"half",
@@ -1827,7 +1827,7 @@ dependencies = [
[[package]]
name = "klad-render"
-version = "0.1.4"
+version = "0.1.12"
dependencies = [
"anyhow",
"bytemuck",
diff --git a/Cargo.toml b/Cargo.toml
index 0b8e52c..343e10d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*"]
[workspace.package]
-version = "0.1.4"
+version = "0.1.12"
edition = "2024"
license-file = "LICENSE"
repository = "https://github.com/klad-app/klad"
diff --git a/crates/app/src/home.rs b/crates/app/src/home.rs
index c141b2a..53ead48 100644
--- a/crates/app/src/home.rs
+++ b/crates/app/src/home.rs
@@ -710,6 +710,85 @@ mod tests {
std::fs::remove_dir_all(&dir).unwrap();
}
+ fn many(dir: &Path) -> Vec<PathBuf> {
+ (0..14)
+ .map(|i| {
+ let path = dir.join(format!("drawing {i}.klad"));
+ Bundle::blank(&path, &small(), "cli").unwrap();
+ path
+ })
+ .collect()
+ }
+
+ fn sideways(h: &mut Harness<'static, Home>, at: egui::Pos2) {
+ h.event(egui::Event::PointerMoved(at));
+ h.run_steps(2);
+ h.event(egui::Event::MouseWheel {
+ unit: egui::MouseWheelUnit::Point,
+ delta: vec2(-400.0, 0.0),
+ modifiers: Modifiers::NONE,
+ phase: egui::TouchPhase::Move,
+ source: egui::MouseWheelSource::Wheel,
+ });
+ h.run_steps(8);
+ }
+
+ fn recent_scrolls_sideways(h: &mut Harness<'static, Home>, width: f32) {
+ let heading = h.get_by_label(&format!("{} Recent", theme::icon::HISTORY)).rect();
+ let first = h.get_by_label("drawing 0").rect();
+ assert!(first.max.x < width);
+ assert!(
+ h.query_by_label("drawing 13")
+ .is_none_or(|card| card.rect().min.x > first.max.x)
+ );
+ sideways(h, egui::pos2(first.center().x, first.min.y + 20.0));
+ let after = h.get_by_label("drawing 0").rect();
+ assert!(
+ after.min.x < first.min.x - 200.0,
+ "the first card stayed at {}",
+ first.min.x
+ );
+ assert_eq!(after.min.y, first.min.y);
+ assert_eq!(
+ h.get_by_label(&format!("{} Recent", theme::icon::HISTORY)).rect(),
+ heading
+ );
+ }
+
+ #[test]
+ fn recent_drawings_are_one_row_that_scrolls_sideways() {
+ let dir = folder("scroll");
+ let made = many(&dir);
+ let shown: Vec<&Path> = made.iter().map(PathBuf::as_path).collect();
+ [vec2(1600.0, 1000.0), vec2(1000.0, 640.0)]
+ .into_iter()
+ .for_each(|size| {
+ let mut h = Harness::builder()
+ .with_size(size)
+ .build_ui_state(|ui, home: &mut Home| home.frame(ui), home(&dir, &shown));
+ h.run_steps(4);
+ recent_scrolls_sideways(&mut h, size.x);
+ });
+ std::fs::remove_dir_all(&dir).unwrap();
+ }
+
+ #[test]
+ fn recent_drawings_scroll_sideways_in_the_window_over_a_drawing() {
+ let dir = folder("scroll-over");
+ let made = many(&dir);
+ let shown: Vec<&Path> = made.iter().map(PathBuf::as_path).collect();
+ let mut first = home(&dir, &shown);
+ first.open(&egui::Context::default(), &made[0]).unwrap();
+ let mut h = Harness::builder()
+ .with_size(vec2(1600.0, 1000.0))
+ .build_ui_state(|ui, home: &mut Home| home.frame(ui), first);
+ h.run_steps(4);
+ h.key_press_modifiers(Modifiers::COMMAND, Key::N);
+ h.run_steps(6);
+ recent_scrolls_sideways(&mut h, 1600.0);
+ std::fs::remove_dir_all(&dir).unwrap();
+ }
+
#[test]
#[ignore]
fn start_pictures() {
diff --git a/crates/app/src/start.rs b/crates/app/src/start.rs
index 228b76f..8210368 100644
--- a/crates/app/src/start.rs
+++ b/crates/app/src/start.rs
@@ -205,8 +205,7 @@ impl Start {
ui.add_space(6.0);
let mut chosen = None;
let shown = self.samples.clone();
- ui.horizontal_wrapped(|ui| {
- ui.spacing_mut().item_spacing = vec2(12.0, 12.0);
+ row(ui, "samples", |ui| {
shown.iter().for_each(|sample| {
ui.vertical(|ui| {
ui.set_width(THUMB + 8.0);
@@ -417,8 +416,7 @@ impl Start {
}
let mut chosen = None;
let documents = settings.documents.clone();
- ui.horizontal_wrapped(|ui| {
- ui.spacing_mut().item_spacing = vec2(12.0, 12.0);
+ row(ui, "recent", |ui| {
documents.iter().for_each(|doc| {
ui.vertical(|ui| {
ui.set_width(THUMB + 8.0);
@@ -532,6 +530,19 @@ impl Start {
}
}
+fn row(ui: &mut egui::Ui, salt: &str, cards: impl FnOnce(&mut egui::Ui)) {
+ egui::ScrollArea::horizontal()
+ .id_salt(salt)
+ .auto_shrink([false, true])
+ .show(ui, |ui| {
+ ui.horizontal_top(|ui| {
+ ui.spacing_mut().item_spacing = vec2(12.0, 12.0);
+ cards(ui);
+ });
+ ui.add_space(14.0);
+ });
+}
+
fn preset_name(i: usize) -> String {
let (name, w, h) = PRESETS[i];
format!("{w} x {h} {name}")