From 4e6d47792ba4fd5584b238bd7aaf8bf4f4230c90 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 30 Sep 2025 18:40:03 +0800 Subject: feat(image, draw_process): allow custom direction --- src/image.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src') 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 = 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 } -- cgit v1.2.3