~ireas/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH genpdf-rs 0/1] Implement horizontal direction for LinearLayout.

~frankenapps
Details
Message ID
<162370213657.22528.15833839867279751390-0@git.sr.ht>
DKIM signature
missing
Download raw message
I needed a horizontal LinearLayout, so I took on the todo and
implemented it.

I was not sure about the check in `area.size().width
> Mm(0.0)`, I think it would not make any sense if either width or
height were zero, but for the sake of consistency I took that over from
`render_vertical()`.

Ferdinand Schäffler (1):
  Implement horizontal direction for LinearLayout.

 src/elements.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++----
 src/lib.rs      | 11 +++++++++++
 2 files changed, 55 insertions(+), 4 deletions(-)

-- 
2.30.2

[PATCH genpdf-rs 1/1] Implement horizontal direction for LinearLayout.

~frankenapps
Details
Message ID
<162370213657.22528.15833839867279751390-1@git.sr.ht>
In-Reply-To
<162370213657.22528.15833839867279751390-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Patch: +55 -4
From: Ferdinand Schäffler <de.frankenapps@gmail.com>

---
 src/elements.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++----
 src/lib.rs      | 11 +++++++++++
 2 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/src/elements.rs b/src/elements.rs
index 1ff2dea..14fbea7 100644
--- a/src/elements.rs
+++ b/src/elements.rs
@@ -56,6 +56,15 @@ use crate::{Alignment, Context, Element, Margins, Mm, Position, RenderResult, Si
#[cfg(feature = "images")]
pub use images::Image;

/// Defines the direction for [LinearLayout].
enum LinearLayoutDirection {
    /// Arrange the elements horzontally.
    Horizontal,

    /// Arrange the elements vertically.
    Vertical,
}

/// Arranges a list of elements sequentially.
///
/// Currently, elements can only be arranged vertically.
@@ -81,19 +90,26 @@ pub use images::Image;
pub struct LinearLayout {
    elements: Vec<Box<dyn Element>>,
    render_idx: usize,
    direction: LinearLayoutDirection,
}

impl LinearLayout {
    fn new() -> LinearLayout {
    fn new(direction: LinearLayoutDirection) -> LinearLayout {
        LinearLayout {
            elements: Vec::new(),
            render_idx: 0,
            direction
        }
    }

    /// Creates a new linear layout that arranges its elements vertically.
    pub fn vertical() -> LinearLayout {
        LinearLayout::new()
        LinearLayout::new(LinearLayoutDirection::Vertical)
    }

    /// Creates a new linear layout that arranges its elements horizontally.
    pub fn horizontal() -> LinearLayout {
        LinearLayout::new(LinearLayoutDirection::Horizontal)
    }

    /// Adds the given element to this layout.
@@ -128,6 +144,28 @@ impl LinearLayout {
        result.has_more = self.render_idx < self.elements.len();
        Ok(result)
    }

    fn render_horizontal(
        &mut self,
        context: &Context,
        mut area: render::Area<'_>,
        style: Style,
    ) -> Result<RenderResult, Error> {
        let mut result = RenderResult::default();
        while area.size().width > Mm(0.0) && self.render_idx < self.elements.len() {
            let element_result =
                self.elements[self.render_idx].render(context, area.clone(), style)?;
            area.add_offset(Position::new(element_result.size.width, 0));
            result.size = result.size.stack_horizontal(element_result.size);
            if element_result.has_more {
                result.has_more = true;
                return Ok(result);
            }
            self.render_idx += 1;
        }
        result.has_more = self.render_idx < self.elements.len();
        Ok(result)
    }
}

impl Element for LinearLayout {
@@ -137,8 +175,10 @@ impl Element for LinearLayout {
        area: render::Area<'_>,
        style: Style,
    ) -> Result<RenderResult, Error> {
        // TODO: add horizontal layout
        self.render_vertical(context, area, style)
        match self.direction {
            LinearLayoutDirection::Horizontal => self.render_horizontal(context, area, style),
            LinearLayoutDirection::Vertical => self.render_vertical(context, area, style),
        }
    }
}

diff --git a/src/lib.rs b/src/lib.rs
index 1c6d81f..ae6771c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -435,6 +435,17 @@ impl Size {
        self.height += other.height;
        self
    }

    /// Stacks the given size horizontally on this size and returns the result.
    ///
    /// This means that the height is set to the maximum of the heights and the width is set to the
    /// sum of the widths.
    #[must_use]
    pub fn stack_horizontal(mut self, other: Size) -> Size {
        self.width += other.width;
        self.height = self.height.max(other.height);
        self
    }
}

impl<W: Into<Mm>, H: Into<Mm>> From<(W, H)> for Size {
-- 
2.30.2

[genpdf-rs/patches] build failed

builds.sr.ht
Details
Message ID
<CC3MIQ1SQ3H1.YL5GVSOH4V8U@cirno2>
In-Reply-To
<162370213657.22528.15833839867279751390-1@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
genpdf-rs/patches: FAILED in 7m0s

[Implement horizontal direction for LinearLayout.][0] from [~frankenapps][1]

[0]: https://lists.sr.ht/~ireas/public-inbox/patches/23306
[1]: de.frankenapps@gmail.com

✗ #525447 FAILED  genpdf-rs/patches/archlinux.yml      https://builds.sr.ht/~ireas/job/525447
✓ #525446 SUCCESS genpdf-rs/patches/archlinux-msrv.yml https://builds.sr.ht/~ireas/job/525446
Reply to thread Export thread (mbox)