Skip to content

Commit

Permalink
[#42] Add text
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed Sep 23, 2023
1 parent 7f21859 commit 7b8b89e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion rpg_tools_rendering/examples/utils/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ pub fn render_2_sets<T, S>(
);
let mut svg_builder = SvgBuilder::new(svg_size);
let mut start = Point2d::default();
let text_size = size.height() / 20;
let text_size = size.height() / 15;
let text_options = TextOptions::new(WebColor::from_color(Color::Black), text_size);
let column_text_offset = Point2d::new((size.width() / 2) as i32, text_size as i32);
let column_orientation = Orientation::default();
let row_orientation = Orientation::from_degree(270.0);

for (row_name, row) in rows.iter() {
start.x = 0;
Expand All @@ -67,6 +68,9 @@ pub fn render_2_sets<T, S>(
start.x += size.width() as i32;
}

let text_center = Point2d::new(text_size as i32, start.y + size.height() as i32 / 2);
svg_builder.render_text(row_name, &text_center, row_orientation, &text_options);

start.y += (size.height() * row_size) as i32;
}

Expand Down
5 changes: 3 additions & 2 deletions rpg_tools_rendering/src/renderer/svg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ impl Renderer for SvgBuilder {
options: &TextOptions,
) {
self.lines.push(format!(
" <text x=\"{}\" y=\"{}\" transform=\"rotate({})\" fill=\"{}\" font-size=\"{}px\" text-anchor=\"middle\">{}</text>",
center.x, center.y, orientation.to_degree(), options.color, options.size, text
" <text x=\"{}\" y=\"{}\" transform=\"rotate({},{},{})\" fill=\"{}\" font-size=\"{}px\" text-anchor=\"middle\">{}</text>",
center.x, center.y, orientation.to_degree(),center.x, center.y,
options.color, options.size, text
));
}
}
Expand Down

0 comments on commit 7b8b89e

Please sign in to comment.