Add text alignment
This commit is contained in:
parent
5438f09820
commit
e06ce690cb
14
src/font.rs
14
src/font.rs
@ -64,7 +64,19 @@ impl<'a> FontRenderer<'a> {
|
|||||||
v_align: VerticalAlignment,
|
v_align: VerticalAlignment,
|
||||||
) {
|
) {
|
||||||
let data = self.prepare(text.into());
|
let data = self.prepare(text.into());
|
||||||
self.raw_render(display, data, position);
|
|
||||||
|
let x = match h_align {
|
||||||
|
HorizontalAlignment::RightToLeft => position.x - data.pixel_width as i16,
|
||||||
|
HorizontalAlignment::Center => position.x - (data.pixel_width as i16 / 2),
|
||||||
|
HorizontalAlignment::LeftToRight => position.x,
|
||||||
|
};
|
||||||
|
let y = match v_align {
|
||||||
|
VerticalAlignment::BottomToTop => position.y - self.height as i16,
|
||||||
|
VerticalAlignment::Center => position.y - (self.height as i16 / 2),
|
||||||
|
VerticalAlignment::TopToBottom => position.y,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.raw_render(display, data, Position { x, y });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepare(&self, text: String) -> RawRenderData<'a> {
|
pub fn prepare(&self, text: String) -> RawRenderData<'a> {
|
||||||
|
|||||||
@ -114,9 +114,9 @@ fn main() -> ! {
|
|||||||
font_renderer.render(
|
font_renderer.render(
|
||||||
&mut display,
|
&mut display,
|
||||||
"Hello World!",
|
"Hello World!",
|
||||||
Position::new(0, 0),
|
Position::new(120, 120),
|
||||||
HorizontalAlignment::LeftToRight,
|
HorizontalAlignment::Center,
|
||||||
VerticalAlignment::TopToBottom,
|
VerticalAlignment::Center,
|
||||||
);
|
);
|
||||||
|
|
||||||
let sim_rst = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default());
|
let sim_rst = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user