summaryrefslogtreecommitdiff
path: root/src/image.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-30 18:40:03 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-30 19:08:31 +0800
commit99e68a5a446625cc52a92b482bcd0719464fb559 (patch)
tree296a5d45137c3a688231126f0ba07f84eb5c1112 /src/image.rs
parent53d33c1a8e988b73ef13d1c6a253acc0b379fd3a (diff)
feat(image, draw_process): allow custom direction
Diffstat (limited to 'src/image.rs')
-rw-r--r--src/image.rs30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/image.rs b/src/image.rs
index 5981879..537beee 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -29,6 +29,17 @@ const RESOLUTION_MULTIPLIER: u32 = 5;
offset based mutation model, to avoid overflowing on previous image
*/
+#[derive(PartialEq)]
+enum HDirection {
+ Up,
+ Down,
+}
+
+enum VDirection {
+ Left,
+ Right,
+}
+
mod colors {
use image::Rgba;
pub const STARSTOP: Rgba<u8> = Rgba([
@@ -109,7 +120,7 @@ fn ext(img: &mut DynamicImage, (curw, curh): &mut NCOffset, (extw, exth): &mut N
}
// TODO: make draw_rect func
-fn draw_process(img: &mut DynamicImage, txt: &str, (curw, curh, c): &mut Offset) {
+fn draw_process(img: &mut DynamicImage, txt: &str, (curw, curh, c): &mut Offset, dir: HDirection) {
let wrapped = wrap_str(txt);
let pxscale = PxScale::from(TEXT_SCALE / 2_f32);
@@ -117,6 +128,9 @@ fn draw_process(img: &mut DynamicImage, txt: &str, (curw, curh, c): &mut Offset)
let (text_w, _) = text_size(pxscale, font, wrapped[0].as_str());
let w = text_w + (2 * COMPONENT_TEXT_PADDING);
let h = TEXT_SCALE as u32 / 2 * wrapped.len() as u32 + (2 * COMPONENT_TEXT_PADDING); // text_size's height is weird and incorrect
+ if dir == HDirection::Up {
+ *curh -= h;
+ }
ext(img, &mut (*c, *curh), &mut (w, h));
let cw = c
.checked_sub(w / 2)
@@ -219,18 +233,18 @@ fn build(ast: &[DepthExpr]) -> DynamicImage {
let mut img = DynamicImage::new(0, 0, ColorType::Rgba8);
// TODO: move to mutable singleton
let mut offset: Offset = (0, 0, 0);
- draw_process(&mut img, "abcdefghijklmnop", &mut offset);
+ draw_process(&mut img, "abcdefghijklmnop", &mut offset, HDirection::Down);
draw_direction(&mut img, &mut offset, None);
- draw_process(&mut img, "a", &mut offset);
+ draw_process(&mut img, "a", &mut offset, HDirection::Down);
draw_direction(&mut img, &mut offset, None);
- draw_process(&mut img, "a", &mut offset);
+ draw_process(&mut img, "a", &mut offset, HDirection::Down);
let (a, b, c) = offset.clone();
draw_direction(&mut img, &mut offset, None);
- draw_process(&mut img, "a", &mut offset);
+ draw_process(&mut img, "a", &mut offset, HDirection::Down);
draw_direction(&mut img, &mut offset, None);
- draw_process(&mut img, "a", &mut offset);
- draw_direction(&mut img, &mut offset, Some(&(a, b)));
- draw_process(&mut img, "a", &mut offset);
+ draw_process(&mut img, "a", &mut offset, HDirection::Down);
+ draw_direction(&mut img, &mut offset, Some(&(a + 100, b)));
+ draw_process(&mut img, "a", &mut offset, HDirection::Up);
img
}