()
| 206 | } |
| 207 | |
| 208 | func (tf *TextField) Init() { |
| 209 | tf.Frame.Init() |
| 210 | tf.AddContextMenu(tf.contextMenu) |
| 211 | |
| 212 | tf.Styler(func(s *styles.Style) { |
| 213 | s.SetAbilities(true, abilities.Activatable, abilities.Focusable, abilities.Hoverable, abilities.Slideable, abilities.DoubleClickable, abilities.TripleClickable) |
| 214 | tf.CursorWidth.Dp(1) |
| 215 | tf.SelectColor = colors.Scheme.Select.Container |
| 216 | tf.PlaceholderColor = colors.Scheme.OnSurfaceVariant |
| 217 | tf.CursorColor = colors.Scheme.Primary.Base |
| 218 | |
| 219 | s.VirtualKeyboard = styles.KeyboardSingleLine |
| 220 | if !tf.IsReadOnly() { |
| 221 | s.Cursor = cursors.Text |
| 222 | } |
| 223 | s.GrowWrap = false // note: doesn't work with Grow |
| 224 | s.Grow.Set(1, 0) |
| 225 | s.Min.Y.Em(1.1) |
| 226 | s.Min.X.Ch(20) |
| 227 | s.Max.X.Ch(40) |
| 228 | s.Gap.Zero() |
| 229 | s.Padding.Set(units.Dp(8), units.Dp(8)) |
| 230 | if tf.LeadingIcon.IsSet() { |
| 231 | s.Padding.Left.Dp(12) |
| 232 | } |
| 233 | if tf.TrailingIcon.IsSet() { |
| 234 | s.Padding.Right.Dp(12) |
| 235 | } |
| 236 | s.Text.Align = styles.Start |
| 237 | s.Align.Items = styles.Center |
| 238 | s.Color = colors.Scheme.OnSurface |
| 239 | switch tf.Type { |
| 240 | case TextFieldFilled: |
| 241 | s.Border.Style.Set(styles.BorderNone) |
| 242 | s.Border.Style.Bottom = styles.BorderSolid |
| 243 | s.Border.Width.Zero() |
| 244 | s.Border.Color.Zero() |
| 245 | s.Border.Radius = styles.BorderRadiusExtraSmallTop |
| 246 | s.Background = colors.Scheme.SurfaceContainer |
| 247 | |
| 248 | s.MaxBorder = s.Border |
| 249 | s.MaxBorder.Width.Bottom = units.Dp(2) |
| 250 | s.MaxBorder.Color.Bottom = colors.Scheme.Primary.Base |
| 251 | |
| 252 | s.Border.Width.Bottom = units.Dp(1) |
| 253 | s.Border.Color.Bottom = colors.Scheme.OnSurfaceVariant |
| 254 | if tf.error != nil { |
| 255 | s.Border.Color.Bottom = colors.Scheme.Error.Base |
| 256 | } |
| 257 | case TextFieldOutlined: |
| 258 | s.Border.Style.Set(styles.BorderSolid) |
| 259 | s.Border.Radius = styles.BorderRadiusExtraSmall |
| 260 | |
| 261 | s.MaxBorder = s.Border |
| 262 | s.MaxBorder.Width.Set(units.Dp(2)) |
| 263 | s.MaxBorder.Color.Set(colors.Scheme.Primary.Base) |
| 264 | s.Border.Width.Set(units.Dp(1)) |
| 265 | if tf.error != nil { |
nothing calls this directly
no test coverage detected