Skip to content

Commit

Permalink
better width guess previews
Browse files Browse the repository at this point in the history
  • Loading branch information
knzai committed Aug 6, 2024
1 parent d236f03 commit c656844
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ImageType {
pub fn factors(num: usize, upper: usize) -> Vec<i64> {
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()
}
}
27 changes: 10 additions & 17 deletions src/wasm/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ pub struct Props {

pub struct ImageComponent {
width: usize,
height: usize,
}

pub enum Msg {
Width(Event),
Height(Event),
}

impl ImageComponent {
Expand All @@ -36,7 +34,7 @@ impl ImageComponent {
let palette = palette_from_abbr("cga0");
let mut bytes: Vec<u8> = 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))
Expand All @@ -54,13 +52,13 @@ impl ImageComponent {
let palette = palette_from_abbr("cga0");
let mut bytes: Vec<u8> = 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! {
<span>
{p.width()}
<div class="preview-tile">
<h3>{p.width()}</h3>
<img src={ src } />
</span>
</div>
}
})
.collect()
Expand All @@ -75,7 +73,6 @@ impl Component for ImageComponent {
fn create(_ctx: &Context<Self>) -> Self {
Self {
width: 320,
height: 200,
}
}

Expand All @@ -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
}
Expand All @@ -101,19 +94,19 @@ impl Component for ImageComponent {

html! {
<>
<div class="preview-tile ">
<div class="preview-tile">
<div class=".preview-media">
<p class="preview-name">{ file.name.to_string() }</p>
<img src={ self.src(file) } />
</div>
<form onsubmit={noop}>
<label for="width">{"[Tile] Width"}</label>
<label for="width">{"Width"}</label>
<input name="width" type="number" value={self.width.to_string()} onchange={ctx.link().callback(Msg::Width)} />
<label for="height">{"[Tile] Height"}</label>
<input name="height" type="number" value={self.height.to_string()} onchange={ctx.link().callback(Msg::Height)} />
</form>
</div>
{self.previews(file)}
<div class="preview-row">
{self.previews(file)}
</div>
</>
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Component for App {
html! {
<div id="wrapper">
<h1>{ "Process your CGA/EGAs" }</h1>
<FileInput accept="image/png,.bin,.cga,.ega" onload={ctx.link().callback( Msg::Loaded )} children={None}/>
<FileInput accept=".bin,.cga,.ega,.cega" onload={ctx.link().callback( Msg::Loaded )} children={None}/>
<div id="preview-area">{{ images }}</div>
</div>
}
Expand Down
13 changes: 13 additions & 0 deletions src/wasm/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file modified test.cga
Binary file not shown.

0 comments on commit c656844

Please sign in to comment.