git.iko.soy/typeable/elm-ui
on master help sign in
resolves #23 - ensure proper distribution of width/height attrs on inputs
dc1f301Matthew Griffith
src/Element/Input.elm+118−18
@@ -188,6 +188,27 @@ type Label msg
188 | HiddenLabel String
188 | HiddenLabel String
189
189
190
190
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+
191{-| -}
212{-| -}
192labelRight : List (Attribute msg) -> Element msg -> Label msg
213labelRight : List (Attribute msg) -> Element msg -> Label msg
193labelRight =
214labelRight =
@@ -780,7 +801,7 @@ textHelper textInput attrs textOptions =
780 defaultTextBoxStyle ++ attrs
801 defaultTextBoxStyle ++ attrs
781
802
782 redistributed =
803 redistributed =
783− redistribute withDefaults
804+ redistribute (isStacked textOptions.label) withDefaults
784
805
785 moveUpToCompensateForPadding =
806 moveUpToCompensateForPadding =
786 calcMoveToCompensateForPadding withDefaults
807 calcMoveToCompensateForPadding withDefaults
@@ -1003,7 +1024,8 @@ redistribute them to the parent, the input, or the cover.
1003
1024
1004-}
1025-}
1005redistribute :
1026redistribute :
1027+ Bool
1006− List (Attribute msg)
1028+ -> List (Attribute msg)
1007 ->
1029 ->
1008 { fullParent : List (Attribute msg)
1030 { fullParent : List (Attribute msg)
1009 , parent : List (Attribute msg)
1031 , parent : List (Attribute msg)
@@ -1011,8 +1033,8 @@ redistribute :
1011 , input : List (Attribute msg)
1033 , input : List (Attribute msg)
1012 , cover : List (Attribute msg)
1034 , cover : List (Attribute msg)
1013 }
1035 }
1014−redistribute attrs =
1036+redistribute stacked attrs =
1015− List.foldl redistributeOver
1037+ List.foldl (redistributeOver stacked)
1016 { fullParent = []
1038 { fullParent = []
1017 , parent = []
1039 , parent = []
1018 , input = []
1040 , input = []
@@ -1030,27 +1052,105 @@ redistribute attrs =
1030 )
1052 )
1031
1053
1032
1054
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+-}
1033−redistributeOver attr els =
1111+redistributeOver stacked attr els =
1034 case attr of
1112 case attr of
1035 Internal.Nearby _ _ ->
1113 Internal.Nearby _ _ ->
1036 { els | parent = attr :: els.parent }
1114 { els | parent = attr :: els.parent }
1037
1115
1038− Internal.Width (Internal.Fill _) ->
1116+ Internal.Width width ->
1117+ if stacked then
1039− { els | fullParent = attr :: els.fullParent }
1118+ { els | fullParent = attr :: els.fullParent }
1040
1119
1041− Internal.Width _ ->
1120+ else if isFill width then
1121+ { els
1122+ | fullParent = attr :: els.fullParent
1042− { els | parent = attr :: els.parent }
1123+ , parent = attr :: els.parent
1124+ }
1043
1125
1044− Internal.Height (Internal.Fill _) ->
1126+ else if isPixel width then
1045− { els
1127+ { els | parent = attr :: els.parent }
1046− | fullParent = attr :: els.fullParent
1047− , parent = attr :: els.parent
1048− }
1049
1128
1129+ else
1130+ { els
1131+ | parent = attr :: els.parent
1132+ }
1133+
1050− Internal.Height h ->
1134+ Internal.Height height ->
1135+ if not stacked then
1051− { els
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
1052− | parent = attr :: els.parent
1148+ { els | parent = attr :: els.parent }
1149+
1150+ else
1151+ { els
1152+ | parent = attr :: els.parent
1053− }
1153+ }
1054
1154
1055 Internal.AlignX _ ->
1155 Internal.AlignX _ ->
1056 { els | fullParent = attr :: els.fullParent }
1156 { els | fullParent = attr :: els.fullParent }