git.iko.soy/typeable/elm-ui
on master help sign in
resolves #23 - ensure proper distribution of width/height attrs on inputs
commitdc1f301c60f1a4e6a31521668bbde825da141e64 authorMatthew Griffith <mdg.griffith@gmail.com> dateMon 1 Jul 2019, 22:30 (7 years ago) parent2ee45a8
1 file changed+118−18
src/Element/Input.elm+118−18
src/Element/Input.elm+118−18
@@ -188,6 +188,27 @@ type Label msg
188188 | HiddenLabel String
189189
190190
191+isStacked : Label msg -> Bool
192+isStacked label =
193+ case label of
194+ Label loc _ _ ->
195+ case loc of
196+ OnRight ->
197+ False
198+
199+ OnLeft ->
200+ False
201+
202+ Above ->
203+ True
204+
205+ Below ->
206+ True
207+
208+ HiddenLabel _ ->
209+ True
210+
211+
191212{-| -}
192213labelRight : List (Attribute msg) -> Element msg -> Label msg
193214labelRight =
@@ -780,7 +801,7 @@ textHelper textInput attrs textOptions =
780801 defaultTextBoxStyle ++ attrs
781802
782803 redistributed =
783− redistribute withDefaults
804+ redistribute (isStacked textOptions.label) withDefaults
784805
785806 moveUpToCompensateForPadding =
786807 calcMoveToCompensateForPadding withDefaults
@@ -1003,7 +1024,8 @@ redistribute them to the parent, the input, or the cover.
10031024
10041025-}
10051026redistribute :
1006− List (Attribute msg)
1027+ Bool
1028+ -> List (Attribute msg)
10071029 ->
10081030 { fullParent : List (Attribute msg)
10091031 , parent : List (Attribute msg)
@@ -1011,8 +1033,8 @@ redistribute :
10111033 , input : List (Attribute msg)
10121034 , cover : List (Attribute msg)
10131035 }
1014−redistribute attrs =
1015− List.foldl redistributeOver
1036+redistribute stacked attrs =
1037+ List.foldl (redistributeOver stacked)
10161038 { fullParent = []
10171039 , parent = []
10181040 , input = []
@@ -1030,27 +1052,105 @@ redistribute attrs =
10301052 )
10311053
10321054
1033−redistributeOver attr els =
1055+isFill len =
1056+ case len of
1057+ Internal.Fill _ ->
1058+ True
1059+
1060+ Internal.Content ->
1061+ False
1062+
1063+ Internal.Px _ ->
1064+ False
1065+
1066+ Internal.Min _ l ->
1067+ isFill l
1068+
1069+ Internal.Max _ l ->
1070+ isFill l
1071+
1072+
1073+isShrink len =
1074+ case len of
1075+ Internal.Content ->
1076+ True
1077+
1078+ Internal.Px _ ->
1079+ False
1080+
1081+ Internal.Fill _ ->
1082+ False
1083+
1084+ Internal.Min _ l ->
1085+ isShrink l
1086+
1087+ Internal.Max _ l ->
1088+ isShrink l
1089+
1090+
1091+isPixel len =
1092+ case len of
1093+ Internal.Content ->
1094+ False
1095+
1096+ Internal.Px _ ->
1097+ True
1098+
1099+ Internal.Fill _ ->
1100+ False
1101+
1102+ Internal.Min _ l ->
1103+ isPixel l
1104+
1105+ Internal.Max _ l ->
1106+ isPixel l
1107+
1108+
1109+{-| isStacked means that the label is above or below
1110+-}
1111+redistributeOver stacked attr els =
10341112 case attr of
10351113 Internal.Nearby _ _ ->
10361114 { els | parent = attr :: els.parent }
10371115
1038− Internal.Width (Internal.Fill _) ->
1039− { els | fullParent = attr :: els.fullParent }
1116+ Internal.Width width ->
1117+ if stacked then
1118+ { els | fullParent = attr :: els.fullParent }
10401119
1041− Internal.Width _ ->
1042− { els | parent = attr :: els.parent }
1120+ else if isFill width then
1121+ { els
1122+ | fullParent = attr :: els.fullParent
1123+ , parent = attr :: els.parent
1124+ }
10431125
1044− Internal.Height (Internal.Fill _) ->
1045− { els
1046− | fullParent = attr :: els.fullParent
1047− , parent = attr :: els.parent
1048− }
1126+ else if isPixel width then
1127+ { els | parent = attr :: els.parent }
10491128
1050− Internal.Height h ->
1051− { els
1052− | parent = attr :: els.parent
1053− }
1129+ else
1130+ { els
1131+ | parent = attr :: els.parent
1132+ }
1133+
1134+ Internal.Height height ->
1135+ if not stacked then
1136+ { els
1137+ | fullParent = attr :: els.fullParent
1138+ , parent = attr :: els.parent
1139+ }
1140+
1141+ else if isFill height then
1142+ { els
1143+ | fullParent = attr :: els.fullParent
1144+ , parent = attr :: els.parent
1145+ }
1146+
1147+ else if isPixel height then
1148+ { els | parent = attr :: els.parent }
1149+
1150+ else
1151+ { els
1152+ | parent = attr :: els.parent
1153+ }
10541154
10551155 Internal.AlignX _ ->
10561156 { els | fullParent = attr :: els.fullParent }