Changes
5 changed files (+136/-143)
-
-
@@ -82,9 +82,10 @@ A4 ->( mm 210, mm 297 ) type alias Canvas = type alias Rendering = { size : CanvasSize , margin : Length , lineWidth : Length }
-
@@ -95,7 +96,7 @@ , shortPiece : ShortPiece, profile : Profile , thickness : Length , lining : Maybe Length , canvas : Canvas , rendering : Rendering }
-
@@ -132,8 +133,9 @@ }, profile = Straight , thickness = mm 2.5 , lining = Just (mm 0.5) , canvas = , rendering = { size = A4 , margin = mm 10 , lineWidth = mm 0.3 } }
-
-
-
@@ -30,15 +30,16 @@ { buckleHole : BuckleHole} type alias Canvas = type alias Rendering = { margin : NumberConstraints Length , lineWidth : NumberConstraints Length } type alias Parameters = { lugWidth : NumberConstraints Length , longPiece : LongPiece , canvas : Canvas , rendering : Rendering }
-
@@ -51,7 +52,8 @@ { count = { min = Just 0, max = Just 10 }, diameter = { min = Just (mm 1), max = Just (mm 10) } } } , canvas = , rendering = { margin = { min = Just (mm 0), max = Just (mm 20) } , lineWidth = { min = Just (mm 0.1), max = Just (mm 1) } } }
-
-
-
@@ -47,7 +47,8 @@ Dict.fromList[ ( Key.toString LugWidth, String.fromFloat (toMM params.lugWidth) ) , ( Key.toString BuckleHoleCount, String.fromInt params.longPiece.buckleHole.count ) , ( Key.toString BuckleHoleDiameter, String.fromFloat (toMM params.longPiece.buckleHole.diameter) ) , ( Key.toString CanvasMargin, String.fromFloat (toMM params.canvas.margin) ) , ( Key.toString CanvasMargin, String.fromFloat (toMM params.rendering.margin) ) , ( Key.toString LineWidth, String.fromFloat (toMM params.rendering.lineWidth) ) ] in { fields = fields
-
@@ -135,18 +136,27 @@ Err errors ->Err errors parseCanvas : Fields -> Result Errors Parameters.Canvas parseCanvas : Fields -> Result Errors Parameters.Rendering parseCanvas fields = case parseField CanvasMargin (parseLength constraints.canvas.margin) fields of Ok margin -> case ( parseField CanvasMargin (parseLength constraints.rendering.margin) fields , parseField LineWidth (parseLength constraints.rendering.lineWidth) fields ) of ( Ok margin, Ok lineWidth ) -> let base = Parameters.default.canvas Parameters.default.rendering in Ok { base | margin = margin } Ok { base | margin = margin, lineWidth = lineWidth } Err err -> Err (mkErrors [ ( CanvasMargin, Just err ) ]) ( margin, lineWidth ) -> Err (mkErrors [ ( CanvasMargin, getError margin ) , ( LineWidth, getError lineWidth ) ] ) parse : Fields -> Result Errors Parameters
-
@@ -157,17 +167,17 @@ , parseLongPiece fields, parseCanvas fields ) of ( Ok lugWidth, Ok longPiece, Ok canvas ) -> ( Ok lugWidth, Ok longPiece, Ok rendering ) -> let base = Parameters.default in Ok { base | lugWidth = lugWidth, longPiece = longPiece, canvas = canvas } Ok { base | lugWidth = lugWidth, longPiece = longPiece, rendering = rendering } ( lugWidth, longPiece, canvas ) -> ( lugWidth, longPiece, rendering ) -> [ mkErrors [ ( LugWidth, getError lugWidth ) ] , getError longPiece |> Maybe.withDefault Dict.empty , getError canvas |> Maybe.withDefault Dict.empty , getError rendering |> Maybe.withDefault Dict.empty ] |> List.map Dict.toList |> List.concat
-
@@ -294,126 +304,96 @@ descriptionId key =Key.toString key ++ "_description" type alias FieldProps msg = { key : Key , title : List (Html.Html msg) , description : List (Html.Html msg) , unit : Maybe String , attrs : List (Html.Attribute msg) } field : Model -> FieldProps InternalMsg -> Html.Html InternalMsg field model { key, title, description, attrs, unit } = node "x-field" [] [ label [ for (Key.toString key), attribute "slot" "title" ] title , p [ id (descriptionId key), attribute "slot" "description" ] description , node "x-number-input" [] [ input (id (Key.toString key) :: value (model.fields |> Dict.get (Key.toString key) |> Maybe.withDefault "") :: onInput (FieldChanged key) :: ariaInvalid (not (Dict.get (Key.toString key) model.errors == Nothing)) :: ariaDescribedBy [ errorId key, descriptionId key ] :: attrs ) [] , case unit of Just u -> span [ attribute "slot" "unit" ] [ text u ] Nothing -> text "" ] , p [ id (errorId key), attribute "slot" "error" ] (Dict.get (Key.toString key) model.errors |> Maybe.map errorText |> Maybe.withDefault [] ) ] view : Model -> Parameters -> List (Html.Attribute InternalMsg) -> Html.Html Msg view model params attrs = let value : Key -> Html.Attribute InternalMsg value key = model.fields |> Dict.get (Key.toString key) |> Maybe.withDefault "" |> Html.Attributes.value in div attrs [ node "x-field" [] [ label [ for (Key.toString LugWidth), attribute "slot" "title" ] [ text "Lug width" ] , p [ id (descriptionId LugWidth), attribute "slot" "description" ] [ field model { key = LugWidth , title = [ text "Lug width" ] , description = [ text "This will be the final width of your strap. " , text "You can use a size smaller than your lug width to create a play." ] , node "x-number-input" [] [ input (id (Key.toString LugWidth) :: step "1.0" :: value LugWidth :: onInput (FieldChanged LugWidth) :: ariaInvalid (not (Dict.get (Key.toString LugWidth) model.errors == Nothing)) :: ariaDescribedBy [ errorId LugWidth, descriptionId LugWidth ] :: lengthFieldAttrs constraints.lugWidth ) [] , span [ attribute "slot" "unit" ] [ text "mm" ] ] , p [ id (errorId LugWidth), attribute "slot" "error" ] (Dict.get (Key.toString LugWidth) model.errors |> Maybe.map errorText |> Maybe.withDefault [] ) ] , node "x-field" [] [ label [ for (Key.toString BuckleHoleCount), attribute "slot" "title" ] [ text "Hole Count" ] , p [ id (descriptionId BuckleHoleCount), attribute "slot" "description" ] [ text "Set 0 to disable buckle holes generation." ] , node "x-number-input" [] [ input (id (Key.toString BuckleHoleCount) :: step "1" :: value BuckleHoleCount :: onInput (FieldChanged BuckleHoleCount) :: ariaInvalid (not (Dict.get (Key.toString BuckleHoleCount) model.errors == Nothing)) :: ariaDescribedBy [ errorId BuckleHoleCount, descriptionId BuckleHoleCount ] :: intFieldAttrs constraints.longPiece.buckleHole.count ) [] ] , p [ id (errorId BuckleHoleCount), attribute "slot" "error" ] (Dict.get (Key.toString BuckleHoleCount) model.errors |> Maybe.map errorText |> Maybe.withDefault [] ) ] , node "x-field" [] [ label [ for (Key.toString BuckleHoleDiameter), attribute "slot" "title" ] [ text "Hole Diameter" ] , p [ id (descriptionId BuckleHoleDiameter), attribute "slot" "description" ] , unit = Just "mm" , attrs = step "1.0" :: lengthFieldAttrs constraints.lugWidth } , field model { key = BuckleHoleCount , title = [ text "Hole Count" ] , description = [ text "Set 0 to disable buckle holes generation." ] , unit = Nothing , attrs = step "1" :: intFieldAttrs constraints.longPiece.buckleHole.count } , field model { key = BuckleHoleDiameter , title = [ text "Hole Diameter" ] , description = [ text "Diameter of buckle holes. You can leave the default value if you're going to use the center mark." ] , node "x-number-input" [] [ input (id (Key.toString BuckleHoleDiameter) :: step "1.0" :: value BuckleHoleDiameter :: onInput (FieldChanged BuckleHoleDiameter) :: disabled (params.longPiece.buckleHole.count == 0) :: ariaInvalid (not (Dict.get (Key.toString BuckleHoleDiameter) model.errors == Nothing)) :: ariaDescribedBy [ errorId BuckleHoleDiameter, descriptionId BuckleHoleDiameter ] :: lengthFieldAttrs constraints.longPiece.buckleHole.diameter ) [] , span [ attribute "slot" "unit" ] [ text "mm" ] ] , p [ id (errorId BuckleHoleDiameter), attribute "slot" "error" ] (Dict.get (Key.toString BuckleHoleDiameter) model.errors |> Maybe.map errorText |> Maybe.withDefault [] ) ] , node "x-field" [] [ label [ for (Key.toString CanvasMargin), attribute "slot" "title" ] [ text "Print Margin" ] , p [ id (descriptionId CanvasMargin), attribute "slot" "description" ] , unit = Just "mm" , attrs = step "1.0" :: disabled (params.longPiece.buckleHole.count == 0) :: lengthFieldAttrs constraints.longPiece.buckleHole.diameter } , field model { key = CanvasMargin , title = [ text "Print Margin" ] , description = [ text "Lower values can cause printing problems depending on your printer." ] , node "x-number-input" [] [ input (id (Key.toString CanvasMargin) :: step "1.0" :: value CanvasMargin :: onInput (FieldChanged CanvasMargin) :: ariaInvalid (not (Dict.get (Key.toString CanvasMargin) model.errors == Nothing)) :: ariaDescribedBy [ errorId CanvasMargin, descriptionId CanvasMargin ] :: lengthFieldAttrs constraints.canvas.margin ) [] , span [ attribute "slot" "unit" ] [ text "mm" ] ] , p [ id (errorId CanvasMargin), attribute "slot" "error" ] (Dict.get (Key.toString CanvasMargin) model.errors |> Maybe.map errorText |> Maybe.withDefault [] ) ] , unit = Just "mm" , attrs = step "1.0" :: lengthFieldAttrs constraints.rendering.margin } , field model { key = LineWidth , title = [ text "Line Width" ] , description = [ text "Stroke width (thickness) of the cutting lines and seam lines." ] , unit = Just "mm" , attrs = step "0.1" :: lengthFieldAttrs constraints.rendering.lineWidth } ] |> Html.map Internal
-
-
-
@@ -15,6 +15,7 @@ = LugWidth| BuckleHoleCount | BuckleHoleDiameter | CanvasMargin | LineWidth toString : Key -> String
-
@@ -31,3 +32,6 @@ "buckle-hole-diameter"CanvasMargin -> "canvas-margin" LineWidth -> "line-width"
-
-
-
@@ -44,11 +44,11 @@ template : Parameters -> List (Svg.Attribute msg) -> Svg.Svg msgtemplate params attrs = let ( canvasWidth, canvasHeight ) = canvasSizeDimension params.canvas.size canvasSizeDimension params.rendering.size |> Tuple.mapBoth toMM toMM margin = toMM params.canvas.margin toMM params.rendering.margin in svg (viewBox (String.join " " [ "0", "0", String.fromInt (ceiling canvasWidth), String.fromInt (ceiling canvasHeight) ])
-
@@ -124,9 +124,13 @@ [ text "10mm" ]] skivingSeamStroke : List (Svg.Attribute msg) skivingSeamStroke = [ fill "none", stroke "currentColor", strokeWidth "0.3", strokeDasharray "1 0.5" ] skivingSeamStroke : Parameters -> List (Svg.Attribute msg) skivingSeamStroke params = [ fill "none" , stroke "currentColor" , strokeWidth (toMM params.rendering.lineWidth |> String.fromFloat) , strokeDasharray "1 0.5" ] longPiece : Parameters -> Anchor -> Svg msg
-
@@ -165,7 +169,7 @@ , ClosePath] , fill "none" , stroke "currentColor" , strokeWidth "0.3" , strokeWidth (toMM params.rendering.lineWidth |> String.fromFloat) ] [] :: Svg.path
-
@@ -173,7 +177,7 @@ (Svg.Path.d[ MoveTo Absolute ( ox, oy + flap ) , HorizontalLineTo Relative lugWidth ] :: skivingSeamStroke :: skivingSeamStroke params ) [] :: Svg.path
-
@@ -201,6 +205,7 @@ interval =toMM buckleHole.interval in hole params buckleHole.diameter ( ox + lugWidth / 2 , oy + offset + interval * toFloat index
-
@@ -210,8 +215,8 @@ )) hole : Length -> ( Float, Float ) -> Svg msg hole diameter ( cx, cy ) = hole : Parameters -> Length -> ( Float, Float ) -> Svg msg hole params diameter ( cx, cy ) = let radius = toMM diameter / 2
-
@@ -224,7 +229,7 @@ , Svg.Attributes.cy (String.fromFloat cy), r (String.fromFloat radius) , fill "none" , stroke "currentColor" , strokeWidth "0.3" , strokeWidth (toMM params.rendering.lineWidth |> String.fromFloat) ] [] , g
-
@@ -280,11 +285,11 @@ , ClosePath] , fill "none" , stroke "currentColor" , strokeWidth "0.3" , strokeWidth (toMM params.rendering.lineWidth |> String.fromFloat) ] [] , g skivingSeamStroke (skivingSeamStroke params) [ Svg.path [ Svg.Path.d [ MoveTo Absolute ( ox, oy + caseSideFlap )
-