summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-08 16:53:39 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-08 16:53:39 +0800
commita5741aeca683e39b01f667ad795ce87e9475fa41 (patch)
treed4292eca733e351e020e0520f3c8bb3897f5c02a /src
parent292257a5f0997e24fb8e6e08b4dccdd439b81a97 (diff)
internal(image): all draw_.. return how much it drawn/extended
image(draw_process)!: only take a source direction
Diffstat (limited to 'src')
-rw-r--r--src/image.rs82
1 files changed, 31 insertions, 51 deletions
diff --git a/src/image.rs b/src/image.rs
index ce22b90..9522364 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -29,7 +29,7 @@ struct Offset {
center: u32,
}
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
struct NCOffset {
x: u32,
y: u32,
@@ -152,7 +152,7 @@ impl FlowChart {
// TODO: make draw_rect func
// TODO: Accept all directions
- fn draw_process(&mut self, txt: &str, config: ComponentConfig<HDirection, HDirection>) {
+ fn draw_process(&mut self, txt: &str, src_dir: VDirection) -> NCOffset {
let curh = &mut self
.offset
.y;
@@ -167,7 +167,7 @@ impl FlowChart {
let (text_w, _) = text_size(pxscale, &self.font, wrapped[0]);
let w = text_w + (2 * Self::COMPONENT_TEXT_PADDING);
let h = Self::TEXT_SCALE as u32 / 2 * wrapped.len() as u32 + (2 * Self::COMPONENT_TEXT_PADDING); // text_size's height is weird and incorrect
- if config.dst_direction == HDirection::Up {
+ if src_dir == VDirection::Down {
*curh = curh
.checked_sub(h)
.unwrap_or(0);
@@ -225,9 +225,13 @@ impl FlowChart {
}
self.offset
.y += 2 * Self::COMPONENT_TEXT_PADDING;
+ NCOffset {
+ x: w,
+ y: h,
+ }
}
- fn draw_direction(&mut self, src: Option<&NCOffset>, dst: Option<&NCOffset>) {
+ fn draw_direction(&mut self, src: Option<&NCOffset>, dst: Option<&NCOffset>) -> NCOffset {
let (orih, c) = (
self.offset
.y,
@@ -335,6 +339,10 @@ impl FlowChart {
.center = dstx as u32;
self.offset
.y = dsty as u32;
+ NCOffset {
+ x: ((maxx - c as i32).max(0) as u32),
+ y: ((maxy - orih as i32).max(0) as u32),
+ }
}
fn build(&mut self, ast: &[DepthExpr]) {
@@ -350,60 +358,32 @@ impl FlowChart {
// DepthExpr::Process(_) => todo!(),
// }
// }
- self.draw_process(
- "abcdefghijklmnospa",
- ComponentConfig {
- ori_direction: HDirection::Down,
- dst_direction: HDirection::Down,
- },
- );
+ self.draw_process("abcdefghijklmnospa", VDirection::Up);
self.draw_direction(None, None);
- self.draw_process(
- "abc",
- ComponentConfig {
- ori_direction: HDirection::Down,
- dst_direction: HDirection::Down,
- },
- );
+ self.draw_process("abc", VDirection::Up);
self.draw_direction(None, None);
- self.draw_process(
- "a",
- ComponentConfig {
- ori_direction: HDirection::Down,
- dst_direction: HDirection::Down,
- },
- );
+ self.draw_process("a", VDirection::Up);
let offset = self.offset;
self.draw_direction(None, None);
- self.draw_process(
- "a",
- ComponentConfig {
- ori_direction: HDirection::Down,
- dst_direction: HDirection::Down,
- },
- );
+ self.draw_process("a", VDirection::Up);
self.draw_direction(None, None);
- self.draw_process(
- "a",
- ComponentConfig {
- ori_direction: HDirection::Down,
- dst_direction: HDirection::Down,
- },
- );
+ let a = self.draw_process("a", VDirection::Up);
self.draw_direction(
- None,
+ Some(&NCOffset {
+ x: self
+ .offset
+ .center,
+ y: self
+ .offset
+ .y
+ - a.y,
+ }),
Some(&NCOffset {
x: offset.x + 100,
y: offset.y,
}),
);
- self.draw_process(
- "a",
- ComponentConfig {
- ori_direction: HDirection::Down,
- dst_direction: HDirection::Up,
- },
- );
+ self.draw_process("a", VDirection::Down);
}
}
@@ -414,14 +394,14 @@ enum VHDirection {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum HDirection {
- Up,
- Down,
+ Left,
+ Right,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum VDirection {
- Left,
- Right,
+ Up,
+ Down,
}
trait Direction: Copy + Eq + core::fmt::Debug {}