2024-09-15 17:57:02 +00:00
|
|
|
#:import theme_font_styles kivymd.font_definitions.theme_font_styles
|
|
|
|
|
|
|
|
|
2024-09-15 12:12:16 +00:00
|
|
|
<MDTextField>
|
|
|
|
input_filter: self.field_filter
|
|
|
|
do_backspace: self.do_backspace
|
|
|
|
|
|
|
|
canvas.before:
|
|
|
|
Clear
|
2024-09-15 17:57:02 +00:00
|
|
|
# Filled mode.
|
2024-09-15 12:12:16 +00:00
|
|
|
Color:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "fill-color"
|
2024-09-15 12:12:16 +00:00
|
|
|
rgba:
|
|
|
|
( \
|
2024-09-15 17:57:02 +00:00
|
|
|
( \
|
|
|
|
self.theme_cls.surfaceVariantColor \
|
|
|
|
if self.theme_bg_color == "Primary" else
|
|
|
|
( \
|
|
|
|
self.fill_color_normal \
|
|
|
|
if self.fill_color_normal else \
|
|
|
|
self.theme_cls.surfaceVariantColor \
|
2024-09-15 12:12:16 +00:00
|
|
|
) \
|
2024-09-15 17:57:02 +00:00
|
|
|
) \
|
|
|
|
if not self.focus else \
|
|
|
|
( \
|
|
|
|
self.theme_cls.surfaceVariantColor \
|
|
|
|
if self.theme_bg_color == "Primary" else
|
|
|
|
( \
|
|
|
|
self.fill_color_focus \
|
|
|
|
if self.fill_color_focus else \
|
|
|
|
self.theme_cls.onSurfaceVariantColor \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
if self.mode == "filled" else self.theme_cls.transparentColor
|
2024-09-15 12:12:16 +00:00
|
|
|
RoundedRectangle:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "fill-color-rounded-rectangle"
|
2024-09-15 12:12:16 +00:00
|
|
|
pos: self.x, self.y
|
|
|
|
size: self.width, self.height
|
2024-09-15 17:57:02 +00:00
|
|
|
radius: self.radius[0], self.radius[1], 0, 0
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
# Active indicator.
|
2024-09-15 12:12:16 +00:00
|
|
|
Color:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "active-indicator-color"
|
2024-09-15 12:12:16 +00:00
|
|
|
rgba:
|
2024-09-15 17:57:02 +00:00
|
|
|
( \
|
|
|
|
( \
|
|
|
|
( \
|
|
|
|
( \
|
|
|
|
self.theme_cls.onSurfaceVariantColor \
|
|
|
|
if self.theme_line_color == "Primary" else \
|
|
|
|
( \
|
|
|
|
self.line_color_normal \
|
|
|
|
if self.line_color_normal else \
|
|
|
|
self.theme_cls.onSurfaceVariantColor \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
if not self.focus else \
|
|
|
|
( \
|
|
|
|
self.theme_cls.primaryColor \
|
|
|
|
if self.theme_line_color == "Primary" else \
|
|
|
|
( \
|
|
|
|
self.line_color_focus \
|
|
|
|
if self.line_color_focus else \
|
|
|
|
self.theme_cls.primaryColor \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
if not self.error else self._get_error_color()
|
|
|
|
) \
|
|
|
|
if not self.disabled else self.theme_cls.disabledTextColor \
|
|
|
|
) \
|
|
|
|
if self.mode == "filled" else self.theme_cls.transparentColor
|
2024-09-15 12:12:16 +00:00
|
|
|
Line:
|
2024-09-15 17:57:02 +00:00
|
|
|
width: self._indicator_height
|
|
|
|
points:
|
|
|
|
self.x + dp(1 if self.focus else 0), \
|
|
|
|
self.y, \
|
|
|
|
self.x - dp(1 if self.focus else 0) + self.width, \
|
|
|
|
self.y
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
# Helper text texture.
|
2024-09-15 12:12:16 +00:00
|
|
|
Color:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "helper-text-color"
|
2024-09-15 12:12:16 +00:00
|
|
|
Rectangle:
|
2024-09-15 17:57:02 +00:00
|
|
|
texture:
|
|
|
|
self._helper_text_label.texture \
|
|
|
|
if self._helper_text_label else \
|
|
|
|
None
|
|
|
|
size:
|
|
|
|
self._helper_text_label.texture_size \
|
|
|
|
if self._helper_text_label else \
|
|
|
|
(0, 0)
|
2024-09-15 12:12:16 +00:00
|
|
|
pos:
|
2024-09-15 17:57:02 +00:00
|
|
|
self.x + (dp(16) if self.mode == "filled" else \
|
|
|
|
(0 if self.mode == "filled" else dp(12))), \
|
|
|
|
self.y + dp(-18)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
# Leading icon texture.
|
2024-09-15 12:12:16 +00:00
|
|
|
Color:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "leading-icons-color"
|
2024-09-15 12:12:16 +00:00
|
|
|
Rectangle:
|
2024-09-15 17:57:02 +00:00
|
|
|
texture:
|
|
|
|
self._leading_icon.texture if self._leading_icon else None
|
|
|
|
size:
|
|
|
|
self._leading_icon.texture_size \
|
|
|
|
if self._leading_icon else \
|
|
|
|
(0, 0)
|
2024-09-15 12:12:16 +00:00
|
|
|
pos:
|
2024-09-15 17:57:02 +00:00
|
|
|
( \
|
|
|
|
( \
|
|
|
|
self.x + \
|
|
|
|
( \
|
|
|
|
( \
|
|
|
|
0 if self.mode != "outlined" else dp(12) \
|
|
|
|
) \
|
|
|
|
if self.mode != "filled" else \
|
|
|
|
( \
|
|
|
|
dp(4) if not self._leading_icon else dp(16) \
|
|
|
|
) \
|
|
|
|
), \
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
self.center_y - self._leading_icon.texture_size[1] / 2 \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
if self._leading_icon else (0, 0)
|
|
|
|
|
|
|
|
# Trailing icon texture.
|
2024-09-15 12:12:16 +00:00
|
|
|
Color:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "trailing-icons-color"
|
2024-09-15 12:12:16 +00:00
|
|
|
Rectangle:
|
|
|
|
texture:
|
2024-09-15 17:57:02 +00:00
|
|
|
self._trailing_icon.texture if self._trailing_icon else None
|
2024-09-15 12:12:16 +00:00
|
|
|
size:
|
2024-09-15 17:57:02 +00:00
|
|
|
self._trailing_icon.texture_size \
|
|
|
|
if self._trailing_icon else \
|
|
|
|
(0, 0)
|
2024-09-15 12:12:16 +00:00
|
|
|
pos:
|
|
|
|
( \
|
2024-09-15 17:57:02 +00:00
|
|
|
(self.width + self.x) - \
|
|
|
|
(self._trailing_icon.texture_size[1]) - dp(14), \
|
|
|
|
self.center_y - self._trailing_icon.texture_size[1] / 2 \
|
2024-09-15 12:12:16 +00:00
|
|
|
) \
|
2024-09-15 17:57:02 +00:00
|
|
|
if self._trailing_icon else (0, 0)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
# Max length texture.
|
|
|
|
Color:
|
|
|
|
group: "max-length-color"
|
|
|
|
Rectangle:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "max-length-rect"
|
|
|
|
texture:
|
|
|
|
self._max_length_label.texture \
|
|
|
|
if self._max_length_label else \
|
|
|
|
None
|
|
|
|
size:
|
|
|
|
self._max_length_label.texture_size \
|
|
|
|
if self._max_length_label else \
|
|
|
|
(0, 0)
|
2024-09-15 12:12:16 +00:00
|
|
|
pos:
|
2024-09-15 17:57:02 +00:00
|
|
|
( \
|
|
|
|
(self.x + self.width) \
|
|
|
|
- (self._max_length_label.texture_size[0] + dp(16)), \
|
|
|
|
self.y - dp(18) \
|
|
|
|
) \
|
|
|
|
if self._max_length_label else (0, 0)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
# Cursor blink.
|
|
|
|
Color:
|
|
|
|
rgba:
|
|
|
|
( \
|
2024-09-15 17:57:02 +00:00
|
|
|
( \
|
|
|
|
self.theme_cls.primaryColor \
|
|
|
|
if not self.error else \
|
|
|
|
self._get_error_color() \
|
|
|
|
) \
|
2024-09-15 12:12:16 +00:00
|
|
|
if self.focus \
|
2024-09-15 17:57:02 +00:00
|
|
|
else self.theme_cls.primaryColor \
|
2024-09-15 12:12:16 +00:00
|
|
|
) \
|
|
|
|
if self.focus and not self._cursor_blink \
|
|
|
|
else \
|
|
|
|
(0, 0, 0, 0)
|
|
|
|
Rectangle:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "rectangle-cursor-blink"
|
2024-09-15 12:12:16 +00:00
|
|
|
pos: (int(x) for x in self.cursor_pos)
|
|
|
|
size: 1, -self.line_height
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
# Outlined mode.
|
2024-09-15 12:12:16 +00:00
|
|
|
Color:
|
|
|
|
group: "rectangle-color"
|
|
|
|
rgba:
|
|
|
|
( \
|
|
|
|
( \
|
|
|
|
( \
|
2024-09-15 17:57:02 +00:00
|
|
|
( \
|
|
|
|
self.theme_cls.primaryColor \
|
|
|
|
if self.theme_line_color == "Primary" else \
|
|
|
|
self.line_color_focus \
|
|
|
|
if self.line_color_focus else \
|
|
|
|
self.theme_cls.primaryColor \
|
2024-09-15 12:12:16 +00:00
|
|
|
) \
|
|
|
|
if self.focus else \
|
|
|
|
( \
|
2024-09-15 17:57:02 +00:00
|
|
|
self.theme_cls.outlineColor \
|
|
|
|
if self.theme_line_color == "Primary" else \
|
|
|
|
self.line_color_normal \
|
|
|
|
if self.line_color_normal else \
|
|
|
|
self.theme_cls.outlineColor \
|
2024-09-15 12:12:16 +00:00
|
|
|
) \
|
|
|
|
) \
|
2024-09-15 17:57:02 +00:00
|
|
|
if not self.error else self._get_error_color() \
|
2024-09-15 12:12:16 +00:00
|
|
|
) \
|
2024-09-15 17:57:02 +00:00
|
|
|
if not self.disabled else \
|
|
|
|
app.theme_cls.onSurfaceColor[:-1] + \
|
|
|
|
[self.text_field_opacity_value_disabled_line]
|
|
|
|
) \
|
|
|
|
if self.mode != "filled" else self.theme_cls.transparentColor
|
|
|
|
|
|
|
|
# Top right corner.
|
|
|
|
# ------------------------------------------------------─╮
|
|
|
|
SmoothLine:
|
|
|
|
width: self._outline_height
|
|
|
|
circle:
|
|
|
|
self.x + self.width - self.radius[1], \
|
|
|
|
self.y + self.height - self.radius[1], \
|
|
|
|
self.radius[1], \
|
|
|
|
0, \
|
|
|
|
90
|
|
|
|
|
|
|
|
# Bottom corner.
|
|
|
|
# -----------------------------------------------------─╯
|
|
|
|
SmoothLine:
|
|
|
|
width: self._outline_height
|
|
|
|
circle:
|
|
|
|
self.x + self.width - self.radius[2], \
|
|
|
|
self.y + self.radius[2], \
|
|
|
|
-self.radius[2], \
|
|
|
|
0, \
|
|
|
|
-90
|
|
|
|
|
|
|
|
# Top left corner.
|
|
|
|
# ╭─------------------------------------------------------
|
|
|
|
SmoothLine:
|
|
|
|
width: self._outline_height
|
|
|
|
circle:
|
|
|
|
self.x + self.radius[0], \
|
|
|
|
self.y + self.height - self.radius[0], \
|
|
|
|
-self.radius[0], \
|
|
|
|
180, \
|
|
|
|
90
|
|
|
|
|
|
|
|
# Bottom left corner.
|
|
|
|
# ╰─-----------------------------------------------------
|
|
|
|
SmoothLine:
|
|
|
|
width: self._outline_height
|
|
|
|
circle:
|
|
|
|
self.x + self.radius[3], \
|
|
|
|
self.y + self.radius[3], \
|
|
|
|
-self.radius[3], \
|
|
|
|
0, \
|
|
|
|
90
|
|
|
|
|
|
|
|
# Left vertical line.
|
|
|
|
# │
|
|
|
|
# │
|
|
|
|
# ╰─------------------------------------------------------
|
|
|
|
SmoothLine:
|
|
|
|
width: self._outline_height
|
|
|
|
points:
|
|
|
|
self.x, \
|
|
|
|
self.y + self.radius[3], \
|
|
|
|
self.x, \
|
|
|
|
self.y + (self.height - self.radius[0])
|
|
|
|
|
|
|
|
# Right vertical line.
|
|
|
|
# │
|
|
|
|
# │
|
|
|
|
# -----------------------------------------------------─╯
|
|
|
|
SmoothLine:
|
|
|
|
width: self._outline_height
|
|
|
|
points:
|
|
|
|
self.x + self.width, \
|
|
|
|
self.y + self.radius[2], \
|
|
|
|
self.x + self.width, \
|
|
|
|
self.y + (self.height - self.radius[1])
|
|
|
|
|
|
|
|
# Bottom horizontal line.
|
|
|
|
# ——————————————————————————————————————————————————————─╯
|
2024-09-15 12:12:16 +00:00
|
|
|
SmoothLine:
|
2024-09-15 17:57:02 +00:00
|
|
|
width: self._outline_height
|
2024-09-15 12:12:16 +00:00
|
|
|
points:
|
2024-09-15 17:57:02 +00:00
|
|
|
self.x + self.radius[3], \
|
|
|
|
self.y, \
|
|
|
|
self.x + self.width - self.radius[2], \
|
|
|
|
self.y
|
|
|
|
|
|
|
|
# Top (left) part of the line.
|
|
|
|
# ╭─-----------------------------------------------------
|
|
|
|
SmoothLine:
|
|
|
|
width: self._outline_height
|
|
|
|
points:
|
|
|
|
self.x + self.radius[0], \
|
|
|
|
self.y + self.height, \
|
|
|
|
self.x + self._left_x_axis_pos, \
|
|
|
|
self.y + self.height
|
|
|
|
|
|
|
|
# Top (right) part of the line.
|
|
|
|
# ╭─-----------—————————————————————————————————————————─╮
|
|
|
|
SmoothLine:
|
|
|
|
width: self._outline_height
|
|
|
|
points:
|
|
|
|
self.x + self._right_x_axis_pos, \
|
|
|
|
self.y + self.height, \
|
|
|
|
self.x + self.width - self.radius[1], \
|
|
|
|
self.y + self.height
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
# Text color.
|
|
|
|
Color:
|
|
|
|
group: "text-color"
|
|
|
|
rgba:
|
2024-09-15 17:57:02 +00:00
|
|
|
self.theme_cls.disabled_hint_text_color \
|
|
|
|
if self.disabled else \
|
2024-09-15 12:12:16 +00:00
|
|
|
( \
|
2024-09-15 17:57:02 +00:00
|
|
|
self.text_color_focus \
|
|
|
|
if self.text_color_focus and self.theme_text_color == "Custom" \
|
|
|
|
else self.theme_cls.onSurfaceColor \
|
2024-09-15 12:12:16 +00:00
|
|
|
) \
|
2024-09-15 17:57:02 +00:00
|
|
|
if self.focus else \
|
|
|
|
( \
|
|
|
|
self.text_color_normal \
|
|
|
|
if self.text_color_normal and self.theme_text_color == "Custom" \
|
|
|
|
else self.theme_cls.onSurfaceVariantColor \
|
|
|
|
)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
# Hint texture.
|
2024-09-15 12:12:16 +00:00
|
|
|
canvas.after:
|
|
|
|
Color:
|
|
|
|
group: "hint-text-color"
|
|
|
|
Rectangle:
|
2024-09-15 17:57:02 +00:00
|
|
|
group: "hint-text-rectangle"
|
|
|
|
texture:
|
|
|
|
self._hint_text_label.texture \
|
|
|
|
if self._hint_text_label else \
|
|
|
|
None
|
|
|
|
size:
|
|
|
|
self._hint_text_label.texture_size \
|
|
|
|
if self._hint_text_label else \
|
|
|
|
(0, 0)
|
2024-09-15 12:12:16 +00:00
|
|
|
pos:
|
|
|
|
( \
|
2024-09-15 17:57:02 +00:00
|
|
|
self.x + \
|
|
|
|
( \
|
|
|
|
dp(16) \
|
|
|
|
if not self._leading_icon else \
|
|
|
|
self._leading_icon.texture_size[0] + dp(28) + self._hint_x \
|
2024-09-15 12:12:16 +00:00
|
|
|
), \
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
self.y + self.height \
|
|
|
|
+ (self._hint_text_label.texture_size[1] / 2) \
|
|
|
|
- (self.height / 2) \
|
|
|
|
- self._hint_y \
|
|
|
|
) \
|
|
|
|
if self._hint_text_label else (0, 0)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
bold: False
|
2024-09-15 17:57:02 +00:00
|
|
|
font_name: theme_font_styles[self.font_style][self.role]["font-name"]
|
|
|
|
font_size: theme_font_styles[self.font_style][self.role]["font-size"]
|
2024-09-15 12:12:16 +00:00
|
|
|
padding:
|
|
|
|
( \
|
2024-09-15 17:57:02 +00:00
|
|
|
dp(16) if not self._leading_icon else dp(42) \
|
|
|
|
if self.mode != "filled" else \
|
|
|
|
(dp(16) if not self._leading_icon else dp(52)), \
|
|
|
|
|
|
|
|
(self.height / 2.0 - (self.line_height / 2.0) * len(self._lines)) \
|
|
|
|
+ dp(8 if self.mode == "filled" else 0), \
|
|
|
|
|
|
|
|
dp(16) \
|
|
|
|
if not self._trailing_icon else \
|
|
|
|
self._trailing_icon.texture_size[0] + dp(28), \
|
|
|
|
|
|
|
|
0 \
|
|
|
|
)
|
2024-09-15 12:12:16 +00:00
|
|
|
multiline: False
|
|
|
|
size_hint_y: None
|
2024-09-15 17:57:02 +00:00
|
|
|
height: dp(56) if not self.multiline else (dp(10) + self.minimum_height)
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
<BaseTextFieldIcon>
|
|
|
|
size_hint: None, None
|
|
|
|
size: "20dp", "20dp"
|
2024-09-15 12:12:16 +00:00
|
|
|
size_hint_x: None
|
|
|
|
width: self.texture_size[0]
|
2024-09-15 17:57:02 +00:00
|
|
|
theme_text_color: "Custom"
|
2024-09-15 12:12:16 +00:00
|
|
|
|
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
<MDTextFieldHintText>
|
|
|
|
role: "large"
|
|
|
|
theme_font_size: "Custom"
|
2024-09-15 12:12:16 +00:00
|
|
|
|
2024-09-15 17:57:02 +00:00
|
|
|
|
|
|
|
<BaseTextFieldLabel>
|
|
|
|
size_hint_x: None
|
|
|
|
width: self.texture_size[0]
|
|
|
|
adaptive_width: True
|
|
|
|
shorten: True
|
|
|
|
shorten_from: "right"
|
|
|
|
font_style: "Body"
|
|
|
|
role: "small"
|
|
|
|
theme_text_color: "Custom"
|