Skip to content

Add Landmark support for margin and size in Layout#222

Open
Glitch-On wants to merge 4 commits intocreativescala:mainfrom
Glitch-On:newb
Open

Add Landmark support for margin and size in Layout#222
Glitch-On wants to merge 4 commits intocreativescala:mainfrom
Glitch-On:newb

Conversation

@Glitch-On
Copy link

@Glitch-On Glitch-On commented Feb 16, 2026

This PR extends the Doodle Layout system to support Landmark-based dimensions for the margin and size methods, enabling percentage-based sizing and margins relative to bounding boxes. #169

Changes
Core Implementation

  • Layout trait: Added new margin and size method overloads that accept Landmark parameters instead of just Double values

  • GenericLayout: Implemented the logic to calculate actual dimensions based on landmark percentages relative to bounding box dimensions

  • LayoutSyntax: Extended the syntax to expose the new landmark-based methods to end users

Examples & Documentation

  • LandmarkLayoutExamples: Added comprehensive examples demonstrating percentage-based layouts, including:

      1. Proportional sizing using landmarks
    
      2. Responsive margins based on bounding box dimensions
    
      3.Practical use cases for percentage-based layout
    

@noelwelsh
Copy link
Contributor

Thanks for doing this. Some CI tasks are failing. Can you run the build command from sbt, and fix all the problems it shows? This should then get CI passing.

@Glitch-On
Copy link
Author

Thank's for appreciation
I will look into the matter fix the problem asap.

Copy link
Contributor

@noelwelsh noelwelsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There a fundamental problem with this code, which is that is misunderstands what Landmark means. This traces back to the existing documentation, which does not do a very good job of describing the semantics of Landmark, margin, and size.

margin specifies an adjustment to the bounding box. E.g. aPicture.margin(20, 20) adds 20 units (usually pixels) to each side of the bounding box. A Landmark is not an adjustment relative to the existing bounding box, but a point relative to the bounding box's origin. So aPicture.margin(Landmark.point(20, 20)) doesn't make sense, as Landmark.point(20, 20) is the point 20 units above and to the right from the origin.

To solve this there probably needs to be a new type that represents a scalar magnitude relative to some baseline. I think #190 needs the same type.

Also see #225

How you proceed is up to you. If you feel you understand the problem adequately you can have a go at fixing it. If you don't, you can wait for me to make some improvements.

bottom: Landmark,
left: Landmark
): Drawing[A] =
margin(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should not be a default implementation here. This implementation will never be useful.

* GenericLayout does).
*/
def size[A](img: Drawing[A], width: Landmark, height: Landmark): Drawing[A] =
size(img, width.x.eval(0, 0), height.y.eval(0, 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should not be a default implementation here. This implementation will never be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants