Skip to content

Commit c656844

Browse files
committed
better width guess previews
1 parent d236f03 commit c656844

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl ImageType {
7272
pub fn factors(num: usize, upper: usize) -> Vec<i64> {
7373
factor(num.try_into().unwrap())
7474
.into_iter()
75-
.filter(|&x| x >= 4 && x <= upper.try_into().unwrap())
75+
.filter(|&x| x > 4 && x <= upper.try_into().unwrap())
7676
.collect()
7777
}
7878
}

src/wasm/image.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ pub struct Props {
1717

1818
pub struct ImageComponent {
1919
width: usize,
20-
height: usize,
2120
}
2221

2322
pub enum Msg {
2423
Width(Event),
25-
Height(Event),
2624
}
2725

2826
impl ImageComponent {
@@ -36,7 +34,7 @@ impl ImageComponent {
3634
let palette = palette_from_abbr("cga0");
3735
let mut bytes: Vec<u8> = Vec::new();
3836

39-
let _ = png::write_to(&mut bytes, tile(image.data(), self.height), palette.clone());
37+
let _ = png::write_to(&mut bytes, image.data(), palette.clone());
4038
bytes
4139
};
4240
format!("data:application/png;base64,{}", STANDARD.encode(data))
@@ -54,13 +52,13 @@ impl ImageComponent {
5452
let palette = palette_from_abbr("cga0");
5553
let mut bytes: Vec<u8> = Vec::new();
5654

57-
let _ = png::write_to(&mut bytes, tile(p.data(), self.height), palette.clone());
55+
let _ = png::write_to(&mut bytes, p.data(), palette.clone());
5856
let src = format!("data:application/png;base64,{}", STANDARD.encode(bytes));
5957
html! {
60-
<span>
61-
{p.width()}
58+
<div class="preview-tile">
59+
<h3>{p.width()}</h3>
6260
<img src={ src } />
63-
</span>
61+
</div>
6462
}
6563
})
6664
.collect()
@@ -75,7 +73,6 @@ impl Component for ImageComponent {
7573
fn create(_ctx: &Context<Self>) -> Self {
7674
Self {
7775
width: 320,
78-
height: 200,
7976
}
8077
}
8178

@@ -85,10 +82,6 @@ impl Component for ImageComponent {
8582
let input: HtmlInputElement = e.target_unchecked_into();
8683
self.width = input.value().parse().expect("fail to parse width");
8784
}
88-
Msg::Height(e) => {
89-
let input: HtmlInputElement = e.target_unchecked_into();
90-
self.height = input.value().parse().expect("fail to parse width");
91-
}
9285
}
9386
true
9487
}
@@ -101,19 +94,19 @@ impl Component for ImageComponent {
10194

10295
html! {
10396
<>
104-
<div class="preview-tile ">
97+
<div class="preview-tile">
10598
<div class=".preview-media">
10699
<p class="preview-name">{ file.name.to_string() }</p>
107100
<img src={ self.src(file) } />
108101
</div>
109102
<form onsubmit={noop}>
110-
<label for="width">{"[Tile] Width"}</label>
103+
<label for="width">{"Width"}</label>
111104
<input name="width" type="number" value={self.width.to_string()} onchange={ctx.link().callback(Msg::Width)} />
112-
<label for="height">{"[Tile] Height"}</label>
113-
<input name="height" type="number" value={self.height.to_string()} onchange={ctx.link().callback(Msg::Height)} />
114105
</form>
115106
</div>
116-
{self.previews(file)}
107+
<div class="preview-row">
108+
{self.previews(file)}
109+
</div>
117110
</>
118111
}
119112
}

src/wasm/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Component for App {
4040
html! {
4141
<div id="wrapper">
4242
<h1>{ "Process your CGA/EGAs" }</h1>
43-
<FileInput accept="image/png,.bin,.cga,.ega" onload={ctx.link().callback( Msg::Loaded )} children={None}/>
43+
<FileInput accept=".bin,.cga,.ega,.cega" onload={ctx.link().callback( Msg::Loaded )} children={None}/>
4444
<div id="preview-area">{{ images }}</div>
4545
</div>
4646
}

src/wasm/styles.css

+13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ label {
6060
background: #313737;
6161
border-radius: 1rem;
6262
}
63+
.preview-row {
64+
display: flex;
65+
flex-direction: row;
66+
padding: 2rem;
67+
margin: 1rem;
68+
background: #313737;
69+
border-radius: 1rem;
70+
}
71+
.preview-row .preview-tile {
72+
background: #111717;
73+
border-radius: 1rem;
74+
}
75+
6376

6477
.preview-media {
6578
flex: 1;

test.cga

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)