From c7ee2b393a369325b3578557e045f2ff94ceab8f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 22 Jun 2019 12:51:06 +0200 Subject: =?UTF-8?q?Fix=20top-left=20text=20alignment=20=F0=9F=93=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/boxed.rs | 6 +++--- src/layout/flex.rs | 4 ++-- src/layout/mod.rs | 16 ++++++++-------- src/layout/text.rs | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/layout') diff --git a/src/layout/boxed.rs b/src/layout/boxed.rs index e712f650..15af278a 100644 --- a/src/layout/boxed.rs +++ b/src/layout/boxed.rs @@ -1,6 +1,6 @@ //! Block-style layouting of boxes. -use crate::doc::{Document, Page, TextAction}; +use crate::doc::{Document, Page, LayoutAction}; use crate::font::Font; use crate::size::{Size, Size2D}; use super::{ActionList, LayoutSpace, LayoutResult, LayoutError}; @@ -12,7 +12,7 @@ pub struct BoxLayout { /// The size of the box. pub dimensions: Size2D, /// The actions composing this layout. - pub actions: Vec, + pub actions: Vec, } impl BoxLayout { @@ -90,7 +90,7 @@ impl BoxLayouter { pub fn add_box_absolute(&mut self, position: Size2D, layout: BoxLayout) { // Move all actions into this layout and translate absolute positions. self.actions.reset_origin(); - self.actions.add(TextAction::MoveAbsolute(position)); + self.actions.add(LayoutAction::MoveAbsolute(position)); self.actions.set_origin(position); self.actions.extend(layout.actions); } diff --git a/src/layout/flex.rs b/src/layout/flex.rs index f966eae2..730b876e 100644 --- a/src/layout/flex.rs +++ b/src/layout/flex.rs @@ -1,6 +1,6 @@ //! Flexible and lazy layouting of boxes. -use crate::doc::TextAction; +use crate::doc::LayoutAction; use crate::size::{Size, Size2D}; use super::{BoxLayout, ActionList, LayoutSpace, LayoutResult, LayoutError}; @@ -157,7 +157,7 @@ impl FlexFinisher { fn append(&mut self, layout: BoxLayout) { // Move all actions into this layout and translate absolute positions. self.actions.reset_origin(); - self.actions.add(TextAction::MoveAbsolute(self.cursor)); + self.actions.add(LayoutAction::MoveAbsolute(self.cursor)); self.actions.set_origin(self.cursor); self.actions.extend(layout.actions); diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 40948a13..b678ab2b 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1,6 +1,6 @@ //! The layouting engine. -use crate::doc::TextAction; +use crate::doc::LayoutAction; use crate::font::{FontLoader, FontError}; use crate::size::{Size, Size2D, SizeBox}; use crate::syntax::{SyntaxTree, Node}; @@ -86,7 +86,7 @@ impl<'a, 'p> Layouter<'a, 'p> { padding: SizeBox::zero(), shrink_to_fit: true, }, - flex_spacing: (ctx.style.line_spacing - 1.0) * Size::points(ctx.style.font_size), + flex_spacing: (ctx.style.line_spacing - 1.0) * Size::pt(ctx.style.font_size), }; // The mutable context for layouting single pieces of text. @@ -192,7 +192,7 @@ impl<'a, 'p> Layouter<'a, 'p> { /// Add the spacing between two paragraphs. fn add_paragraph_spacing(&mut self) -> LayoutResult<()> { - let size = Size::points(self.text_ctx.style.font_size) + let size = Size::pt(self.text_ctx.style.font_size) * (self.text_ctx.style.line_spacing * self.text_ctx.style.paragraph_spacing - 1.0); self.box_layouter.add_space(size) } @@ -201,7 +201,7 @@ impl<'a, 'p> Layouter<'a, 'p> { /// Manipulates and optimizes a list of actions. #[derive(Debug, Clone)] pub struct ActionList { - actions: Vec, + actions: Vec, origin: Size2D, active_font: (usize, f32), } @@ -218,8 +218,8 @@ impl ActionList { /// Add an action to the list if it is not useless /// (like changing to a font that is already active). - pub fn add(&mut self, action: TextAction) { - use TextAction::*; + pub fn add(&mut self, action: LayoutAction) { + use LayoutAction::*; match action { MoveAbsolute(pos) => self.actions.push(MoveAbsolute(self.origin + pos)), SetFont(index, size) => if (index, size) != self.active_font { @@ -231,7 +231,7 @@ impl ActionList { } /// Add a series of actions. - pub fn extend(&mut self, actions: I) where I: IntoIterator { + pub fn extend(&mut self, actions: I) where I: IntoIterator { for action in actions.into_iter() { self.add(action); } @@ -254,7 +254,7 @@ impl ActionList { } /// Return the list of actions as a vector. - pub fn into_vec(self) -> Vec { + pub fn into_vec(self) -> Vec { self.actions } } diff --git a/src/layout/text.rs b/src/layout/text.rs index 8aa76c4c..0a0241a0 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -1,6 +1,6 @@ //! Layouting of text into boxes. -use crate::doc::TextAction; +use crate::doc::LayoutAction; use crate::font::FontQuery; use crate::size::{Size, Size2D}; use super::*; @@ -39,11 +39,11 @@ pub fn layout(text: &str, ctx: &TextContext) -> LayoutResult { // Change the font if necessary. if active_font != index { if !buffer.is_empty() { - actions.push(TextAction::WriteText(buffer)); + actions.push(LayoutAction::WriteText(buffer)); buffer = String::new(); } - actions.push(TextAction::SetFont(index, ctx.style.font_size)); + actions.push(LayoutAction::SetFont(index, ctx.style.font_size)); active_font = index; } @@ -52,11 +52,11 @@ pub fn layout(text: &str, ctx: &TextContext) -> LayoutResult { // Write the remaining characters. if !buffer.is_empty() { - actions.push(TextAction::WriteText(buffer)); + actions.push(LayoutAction::WriteText(buffer)); } Ok(BoxLayout { - dimensions: Size2D::new(width, Size::points(ctx.style.font_size)), + dimensions: Size2D::new(width, Size::pt(ctx.style.font_size)), actions, }) } -- cgit v1.2.3