Skip to content

Commit

Permalink
output renderSize
Browse files Browse the repository at this point in the history
  • Loading branch information
myrho committed Oct 11, 2024
1 parent b46e239 commit 6d5ec3a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
14 changes: 13 additions & 1 deletion codegen/src/Generate/Common/DefaultShapeTraits.elm
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,21 @@ getStrokeWidth node =

toDetails : List Elm.Expression -> { a | defaultShapeTraits : DefaultShapeTraits } -> Details
toDetails styles node =
let
bbox =
getBoundingBox node

rbox =
node.defaultShapeTraits.absoluteRenderBounds
|> Maybe.withDefault bbox
in
{ name = getName node
, instanceName = ""
, bbox = getBoundingBox node
, bbox = bbox
, renderedSize =
{ width = rbox.width
, height = rbox.height
}
, strokeWidth = getStrokeWidth node
, styles = styles
}
Expand Down
12 changes: 12 additions & 0 deletions codegen/src/Generate/Common/FrameTraits.elm
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,21 @@ getStrokeWidth node =

toDetails : (FrameTraits -> List Elm.Expression) -> { a | frameTraits : FrameTraits } -> Details
toDetails getStyles node =
let
bbox =
getBoundingBox node

rbox =
node.frameTraits.absoluteRenderBounds
|> Maybe.withDefault bbox
in
{ name = getName node
, instanceName = ""
, bbox = getBoundingBox node
, renderedSize =
{ width = rbox.width
, height = rbox.height
}
, strokeWidth = getStrokeWidth node
, styles = getStyles node.frameTraits
}
Expand Down
2 changes: 2 additions & 0 deletions codegen/src/Generate/Util.elm
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ detailsToDeclaration parentName componentName details =
, ( "y", Elm.float details.bbox.y )
, ( "width", Elm.float details.bbox.width )
, ( "height", Elm.float details.bbox.height )
, ( "renderedWidth", Elm.float details.renderedSize.width )
, ( "renderedHeight", Elm.float details.renderedSize.height )
, ( "strokeWidth", Elm.float details.strokeWidth )
, ( "styles", Elm.list details.styles )
]
Expand Down
3 changes: 2 additions & 1 deletion codegen/src/Types.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Types exposing (..)

import Api.Raw exposing (Rectangle)
import Api.Raw exposing (Rectangle, Size)
import Dict exposing (Dict)
import Elm exposing (Expression)

Expand All @@ -20,6 +20,7 @@ type alias Details =
-- enclosing instance name
, instanceName : String
, bbox : Rectangle
, renderedSize : Size
, strokeWidth : Float
, styles : List Elm.Expression
}
Expand Down

0 comments on commit 6d5ec3a

Please sign in to comment.