summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/image.rs51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/image.rs b/src/image.rs
index 2aea600..76e86ce 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -15,6 +15,7 @@ type Offset = (u32, u32); // x, y or width, height
const COMPONENT_TEXT_PADDING: u32 = 1 * RESOLUTION_MULTIPLIER;
const TEXT_SCALE: f32 = 12.0 * RESOLUTION_MULTIPLIER as f32;
+const TEXT_LEN_WRAP: usize = 10;
// TODO: LENGTH based on where to where
const DIRECTION_LINE_THICKNESS: u32 = 2 * RESOLUTION_MULTIPLIER;
@@ -56,6 +57,17 @@ mod colors {
]);
}
+fn wrap_str(s: &str) -> Vec<String> {
+ s.chars()
+ .collect::<Vec<_>>()
+ .chunks(TEXT_LEN_WRAP)
+ .map(|c| {
+ c.iter()
+ .collect()
+ })
+ .collect()
+}
+
// TODO: store as singleton
fn get_font() -> Result<FontArc, io::Error> {
let mut db = Database::new();
@@ -106,27 +118,32 @@ fn ext(img: &mut DynamicImage, (curw, curh): &mut Offset, (extw, exth): &mut Off
// TODO: make draw_rect func
fn draw_process(img: &mut DynamicImage, txt: &str, (curw, curh): &mut Offset) -> Offset {
*curw = curw
- .checked_sub(TEXT_SCALE as u32 / 2)
+ .checked_sub(TEXT_SCALE as u32 * COMPONENT_TEXT_PADDING / 2)
.unwrap_or(0);
- let w = TEXT_SCALE as u32 + COMPONENT_TEXT_PADDING * 2;
- let h = w;
+ let txt = wrap_str(txt);
+ let w = (TEXT_SCALE as u32 / 5 * TEXT_LEN_WRAP as u32) + (2 * COMPONENT_TEXT_PADDING);
+ let h = TEXT_SCALE as u32 / 2 * txt.len() as u32 + (2 * COMPONENT_TEXT_PADDING);
ext(img, &mut (*curw, *curh), &mut (w, h));
draw_filled_rect_mut(img, Rect::at(*curw as i32, *curh as i32).of_size(w, h), colors::PROCESS);
- draw_text_mut(
- img,
- colors::FG,
- (*curw + COMPONENT_TEXT_PADDING)
- .try_into()
- .unwrap(),
- (*curh + COMPONENT_TEXT_PADDING)
- .try_into()
- .unwrap(),
- PxScale::from(TEXT_SCALE / 2.0),
- &get_font().unwrap(),
- txt,
- );
+ // TODO: move to draw_text()
+ for s in txt {
+ draw_text_mut(
+ img,
+ colors::FG,
+ (*curw + COMPONENT_TEXT_PADDING)
+ .try_into()
+ .unwrap(),
+ (*curh + COMPONENT_TEXT_PADDING)
+ .try_into()
+ .unwrap(),
+ PxScale::from(TEXT_SCALE / 2_f32),
+ &get_font().unwrap(),
+ s.as_str(),
+ );
+ *curh += TEXT_SCALE as u32 / 2;
+ }
*curw += w / 2;
- *curh += h;
+ *curh += 2 * COMPONENT_TEXT_PADDING;
(*curw, *curh)
}