Skip to content

get_mobile_width with pixel values returns incorrect percentage #619

@foggy1

Description

@foggy1

In mj_column/render.js there's the following function:

    fn get_mobile_width(&self) -> Option<Size> {
        if !self.attribute_exists("mobile-width") {
            return Some(Size::percent(100.0));
        }
        if let Some(width) = self.attribute_as_size("width") {
            if width.is_percent() {
                Some(width)
            } else if width.is_pixel() {
                self.container_width
                    .as_ref()
                    .map(|w| Size::percent(width.value() / w.value()))
            } else {
                None
            }
        } else {
            Some(Size::percent(100.0 / (self.non_raw_siblings() as f32)))
        }
    }

I believe the line .map(|w| Size::percent(width.value() / w.value())) should in fact be .map(|w| Size::percent(width.value() / w.value() * 100.0)). Presently returned percentages for the pixel branch of this function are off by a factor of 100.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions