From c656844c01f2de5dedb0bed319e5d6b996fcf6ff Mon Sep 17 00:00:00 2001 From: Kenzi Connor Date: Mon, 5 Aug 2024 18:47:57 -0700 Subject: [PATCH] better width guess previews --- src/lib.rs | 2 +- src/wasm/image.rs | 27 ++++++++++----------------- src/wasm/main.rs | 2 +- src/wasm/styles.css | 13 +++++++++++++ test.cga | Bin 3328 -> 3328 bytes 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 646edbc..eb790f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ impl ImageType { pub fn factors(num: usize, upper: usize) -> Vec { factor(num.try_into().unwrap()) .into_iter() - .filter(|&x| x >= 4 && x <= upper.try_into().unwrap()) + .filter(|&x| x > 4 && x <= upper.try_into().unwrap()) .collect() } } diff --git a/src/wasm/image.rs b/src/wasm/image.rs index 654eb1d..50b7698 100644 --- a/src/wasm/image.rs +++ b/src/wasm/image.rs @@ -17,12 +17,10 @@ pub struct Props { pub struct ImageComponent { width: usize, - height: usize, } pub enum Msg { Width(Event), - Height(Event), } impl ImageComponent { @@ -36,7 +34,7 @@ impl ImageComponent { let palette = palette_from_abbr("cga0"); let mut bytes: Vec = Vec::new(); - let _ = png::write_to(&mut bytes, tile(image.data(), self.height), palette.clone()); + let _ = png::write_to(&mut bytes, image.data(), palette.clone()); bytes }; format!("data:application/png;base64,{}", STANDARD.encode(data)) @@ -54,13 +52,13 @@ impl ImageComponent { let palette = palette_from_abbr("cga0"); let mut bytes: Vec = Vec::new(); - let _ = png::write_to(&mut bytes, tile(p.data(), self.height), palette.clone()); + let _ = png::write_to(&mut bytes, p.data(), palette.clone()); let src = format!("data:application/png;base64,{}", STANDARD.encode(bytes)); html! { - - {p.width()} +
+

{p.width()}

- +
} }) .collect() @@ -75,7 +73,6 @@ impl Component for ImageComponent { fn create(_ctx: &Context) -> Self { Self { width: 320, - height: 200, } } @@ -85,10 +82,6 @@ impl Component for ImageComponent { let input: HtmlInputElement = e.target_unchecked_into(); self.width = input.value().parse().expect("fail to parse width"); } - Msg::Height(e) => { - let input: HtmlInputElement = e.target_unchecked_into(); - self.height = input.value().parse().expect("fail to parse width"); - } } true } @@ -101,19 +94,19 @@ impl Component for ImageComponent { html! { <> -
+

{ file.name.to_string() }

- + - -
- {self.previews(file)} +
+ {self.previews(file)} +
} } diff --git a/src/wasm/main.rs b/src/wasm/main.rs index de656de..3b42fdb 100644 --- a/src/wasm/main.rs +++ b/src/wasm/main.rs @@ -40,7 +40,7 @@ impl Component for App { html! {

{ "Process your CGA/EGAs" }

- +
{{ images }}
} diff --git a/src/wasm/styles.css b/src/wasm/styles.css index 599f0a1..7b836f6 100644 --- a/src/wasm/styles.css +++ b/src/wasm/styles.css @@ -60,6 +60,19 @@ label { background: #313737; border-radius: 1rem; } +.preview-row { + display: flex; + flex-direction: row; + padding: 2rem; + margin: 1rem; + background: #313737; + border-radius: 1rem; +} +.preview-row .preview-tile { + background: #111717; + border-radius: 1rem; +} + .preview-media { flex: 1; diff --git a/test.cga b/test.cga index 1b1c291e3726fb3ed8e5682d5b5455b7de519532..bb7b2088c7ed956e67688c3ff3702f0d3de70416 100644 GIT binary patch literal 3328 zcmbVOL5S5x82*z<)-)YAkNO@3X)(xBUUN!oOQD7)BHpu-Ko9lqaSts$iGxMzaSw$; zPf_-ejXii*Fm;7q78QEvrNw(ICG9Q<5=_5;lK1vm-BtTPzRb)&^ZjpT{(t_N69hT2 z_gScF<;&VM;$apgTp0Y(l4vzo`$}T|NSTIKla;B#rDXOVPb?*&yDBTqfQLoF(OwH z1qGKOnG}kx&qEQP4aNPW6+1~o_b}#DjG1Cg0Y3p|5kUF8cu>VPQP&`>pH#Q#Np%~0 z+5xSs#r?3REe7Td=kG5qy1W`6@TmI(xP6O0`|A;z(kJt{PoxwkjR6o|#UX^O082y* zKwInkF~Rjpx!0@0tg4b}bK#jRD}PA9FI5$&6_uG-q`D1s2K^?_<-o0kBE-kB|5hIJT6=y`ucY=9zRSD zJ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