Skip to content

Commit

Permalink
refactor: make size, pixel, percent copy (#445)
Browse files Browse the repository at this point in the history
Signed-off-by: Jérémie Drouet <[email protected]>
  • Loading branch information
jdrouet authored Jul 22, 2024
1 parent 87bec4b commit c6ee2f7
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/mrml-core/src/helper/size.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::convert::TryFrom;

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Size {
Pixel(Pixel),
Percent(Percent),
Expand Down Expand Up @@ -79,7 +79,7 @@ impl std::fmt::Display for Size {
}
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Percent(f32);

impl Percent {
Expand Down Expand Up @@ -119,7 +119,7 @@ impl std::fmt::Display for Percent {
}
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Pixel(f32);

impl Pixel {
Expand Down
4 changes: 1 addition & 3 deletions packages/mrml-core/src/mj_accordion/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ impl<'root> Render<'root> for Renderer<'root, MjAccordion, ()> {
}

fn get_width(&self) -> Option<Size> {
self.container_width
.as_ref()
.map(|w| Size::Pixel(w.clone()))
self.container_width.as_ref().copied().map(Size::Pixel)
}

fn set_container_width(&mut self, width: Option<Pixel>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_body/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'root> Renderer<'root, MjBody, ()> {
.count();
for (index, child) in self.element.children.iter().enumerate() {
let mut renderer = child.renderer(self.context());
renderer.set_container_width(element_width.clone());
renderer.set_container_width(element_width);
renderer.set_index(index);
renderer.set_raw_siblings(raw_siblings);
renderer.set_siblings(self.element.children.len());
Expand Down
10 changes: 4 additions & 6 deletions packages/mrml-core/src/mj_carousel/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'root> Renderer<'root, MjCarousel, MjCarouselExtra> {
renderer.maybe_add_extra_attribute("tb-border", tb_border);
renderer.maybe_add_extra_attribute("tb-border-radius", tb_border_radius);
renderer.set_index(index);
renderer.set_container_width(Some(width.clone()));
renderer.set_container_width(Some(width));
renderer.render_fragment("thumbnail", cursor)?;
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ impl<'root> Renderer<'root, MjCarousel, MjCarouselExtra> {
renderer
.maybe_add_extra_attribute("tb-border-radius", self.attribute("tb-border-radius"));
renderer.set_index(index);
renderer.set_container_width(self.container_width.clone());
renderer.set_container_width(self.container_width);
renderer.render(cursor)?;
}

Expand Down Expand Up @@ -236,7 +236,7 @@ impl<'root> Renderer<'root, MjCarousel, MjCarouselExtra> {
renderer.maybe_add_extra_attribute("tb-border", self.attribute("tb-border"));
renderer
.maybe_add_extra_attribute("tb-border-radius", self.attribute("tb-border-radius"));
renderer.set_container_width(self.container_width.clone());
renderer.set_container_width(self.container_width);

cursor.buffer.start_mso_conditional_tag();
renderer.render(cursor)?;
Expand Down Expand Up @@ -427,9 +427,7 @@ impl<'root> Render<'root> for Renderer<'root, MjCarousel, MjCarouselExtra> {
}

fn get_width(&self) -> Option<Size> {
self.container_width
.as_ref()
.map(|w| Size::Pixel(w.clone()))
self.container_width.as_ref().copied().map(Size::Pixel)
}

fn set_container_width(&mut self, width: Option<Pixel>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_column/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<'root> Renderer<'root, MjColumn, MjColumnExtra<'root>> {
renderer.set_index(index);
renderer.set_raw_siblings(raw_siblings);
renderer.set_siblings(siblings);
renderer.set_container_width(current_width.clone());
renderer.set_container_width(current_width);
if child.is_raw() {
renderer.render(cursor)?;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_group/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'root> Renderer<'root, MjGroup, ()> {
renderer.set_index(index);
renderer.set_siblings(siblings);
renderer.set_raw_siblings(raw_siblings);
renderer.set_container_width(Some(current_width.clone()));
renderer.set_container_width(Some(current_width));
renderer.add_extra_attribute("mobile-width", "mobile-width");
if child.is_raw() {
renderer.render(cursor)?;
Expand Down
4 changes: 1 addition & 3 deletions packages/mrml-core/src/mj_navbar/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ impl<'root> Render<'root> for Renderer<'root, MjNavbar, MjNavbarExtra> {
}

fn get_width(&self) -> Option<Size> {
self.container_width
.as_ref()
.map(|w| Size::Pixel(w.clone()))
self.container_width.as_ref().copied().map(Size::Pixel)
}

fn set_container_width(&mut self, width: Option<Pixel>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_raw/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'root> Render<'root> for Renderer<'root, MjRaw, ()> {
renderer.set_index(index);
renderer.set_siblings(siblings);
renderer.set_raw_siblings(siblings);
renderer.set_container_width(self.container_width.clone());
renderer.set_container_width(self.container_width);
renderer.render(cursor)?;
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_section/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub trait SectionLikeRender<'root>: WithMjSectionBackground<'root> {
let mut renderer = child.renderer(self.context());
renderer.set_siblings(siblings);
renderer.set_raw_siblings(raw_siblings);
renderer.set_container_width(self.container_width().clone());
renderer.set_container_width(*self.container_width());
if child.is_raw() {
cursor.buffer.end_conditional_tag();
renderer.render(cursor)?;
Expand Down
4 changes: 1 addition & 3 deletions packages/mrml-core/src/mj_social/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ impl<'root> Render<'root> for Renderer<'root, MjSocial, ()> {
}

fn get_width(&self) -> Option<Size> {
self.container_width
.as_ref()
.map(|w| Size::Pixel(w.clone()))
self.container_width.as_ref().copied().map(Size::Pixel)
}

fn set_container_width(&mut self, width: Option<Pixel>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_wrapper/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'root> SectionLikeRender<'root> for Renderer<'root, MjWrapper, ()> {
let mut renderer = child.renderer(self.context());
renderer.set_siblings(siblings);
renderer.set_raw_siblings(raw_siblings);
renderer.set_container_width(current_width.clone());
renderer.set_container_width(current_width);
if child.is_raw() {
renderer.render(cursor)?;
} else {
Expand Down

0 comments on commit c6ee2f7

Please sign in to comment.