Skip to main content

ferroui_base/input/
input_scope_name_value.rs

1//! Input scope names from WinUI's pinned Microsoft.UI.Xaml.Input model.
2//! Copyright (c) Microsoft Corporation. See NOTICE.md for source attribution.
3
4use super::text_input::TextInputContentType;
5use crate::utilities::FormatError;
6
7/// A virtual keyboard and input-method hint. Values match the WinUI public ABI;
8/// they do not restrict, validate, or obscure the editor's document contents.
9#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
10#[repr(i32)]
11pub enum InputScopeNameValue {
12    #[default]
13    Default = 0,
14    Url = 1,
15    EmailSmtpAddress = 5,
16    PersonalFullName = 7,
17    CurrencyAmountAndSymbol = 20,
18    CurrencyAmount = 21,
19    DateMonthNumber = 23,
20    DateDayNumber = 24,
21    DateYear = 25,
22    Digits = 28,
23    Number = 29,
24    Password = 31,
25    TelephoneNumber = 32,
26    TelephoneCountryCode = 33,
27    TelephoneAreaCode = 34,
28    TelephoneLocalNumber = 35,
29    TimeHour = 37,
30    TimeMinutesOrSeconds = 38,
31    NumberFullWidth = 39,
32    AlphanumericHalfWidth = 40,
33    AlphanumericFullWidth = 41,
34    Hiragana = 44,
35    KatakanaHalfWidth = 45,
36    KatakanaFullWidth = 46,
37    Hanja = 47,
38    HangulHalfWidth = 48,
39    HangulFullWidth = 49,
40    Search = 50,
41    Formula = 51,
42    SearchIncremental = 52,
43    ChineseHalfWidth = 53,
44    ChineseFullWidth = 54,
45    NativeScript = 55,
46    Text = 57,
47    Chat = 58,
48    NameOrPhoneNumber = 59,
49    EmailNameOrAddress = 60,
50    Maps = 62,
51    NumericPassword = 63,
52    NumericPin = 64,
53    AlphanumericPin = 65,
54    FormulaNumber = 67,
55    ChatWithoutEmoji = 68,
56}
57
58impl InputScopeNameValue {
59    /// Every public value in the pinned WinUI InputScopeNameValue enumeration.
60    pub const ALL: [Self; 43] = [
61        Self::Default,
62        Self::Url,
63        Self::EmailSmtpAddress,
64        Self::PersonalFullName,
65        Self::CurrencyAmountAndSymbol,
66        Self::CurrencyAmount,
67        Self::DateMonthNumber,
68        Self::DateDayNumber,
69        Self::DateYear,
70        Self::Digits,
71        Self::Number,
72        Self::Password,
73        Self::TelephoneNumber,
74        Self::TelephoneCountryCode,
75        Self::TelephoneAreaCode,
76        Self::TelephoneLocalNumber,
77        Self::TimeHour,
78        Self::TimeMinutesOrSeconds,
79        Self::NumberFullWidth,
80        Self::AlphanumericHalfWidth,
81        Self::AlphanumericFullWidth,
82        Self::Hiragana,
83        Self::KatakanaHalfWidth,
84        Self::KatakanaFullWidth,
85        Self::Hanja,
86        Self::HangulHalfWidth,
87        Self::HangulFullWidth,
88        Self::Search,
89        Self::Formula,
90        Self::SearchIncremental,
91        Self::ChineseHalfWidth,
92        Self::ChineseFullWidth,
93        Self::NativeScript,
94        Self::Text,
95        Self::Chat,
96        Self::NameOrPhoneNumber,
97        Self::EmailNameOrAddress,
98        Self::Maps,
99        Self::NumericPassword,
100        Self::NumericPin,
101        Self::AlphanumericPin,
102        Self::FormulaNumber,
103        Self::ChatWithoutEmoji,
104    ];
105
106    /// The public WinUI symbolic name.
107    pub const fn name(self) -> &'static str {
108        match self {
109            Self::Default => "Default",
110            Self::Url => "Url",
111            Self::EmailSmtpAddress => "EmailSmtpAddress",
112            Self::PersonalFullName => "PersonalFullName",
113            Self::CurrencyAmountAndSymbol => "CurrencyAmountAndSymbol",
114            Self::CurrencyAmount => "CurrencyAmount",
115            Self::DateMonthNumber => "DateMonthNumber",
116            Self::DateDayNumber => "DateDayNumber",
117            Self::DateYear => "DateYear",
118            Self::Digits => "Digits",
119            Self::Number => "Number",
120            Self::Password => "Password",
121            Self::TelephoneNumber => "TelephoneNumber",
122            Self::TelephoneCountryCode => "TelephoneCountryCode",
123            Self::TelephoneAreaCode => "TelephoneAreaCode",
124            Self::TelephoneLocalNumber => "TelephoneLocalNumber",
125            Self::TimeHour => "TimeHour",
126            Self::TimeMinutesOrSeconds => "TimeMinutesOrSeconds",
127            Self::NumberFullWidth => "NumberFullWidth",
128            Self::AlphanumericHalfWidth => "AlphanumericHalfWidth",
129            Self::AlphanumericFullWidth => "AlphanumericFullWidth",
130            Self::Hiragana => "Hiragana",
131            Self::KatakanaHalfWidth => "KatakanaHalfWidth",
132            Self::KatakanaFullWidth => "KatakanaFullWidth",
133            Self::Hanja => "Hanja",
134            Self::HangulHalfWidth => "HangulHalfWidth",
135            Self::HangulFullWidth => "HangulFullWidth",
136            Self::Search => "Search",
137            Self::Formula => "Formula",
138            Self::SearchIncremental => "SearchIncremental",
139            Self::ChineseHalfWidth => "ChineseHalfWidth",
140            Self::ChineseFullWidth => "ChineseFullWidth",
141            Self::NativeScript => "NativeScript",
142            Self::Text => "Text",
143            Self::Chat => "Chat",
144            Self::NameOrPhoneNumber => "NameOrPhoneNumber",
145            Self::EmailNameOrAddress => "EmailNameOrAddress",
146            Self::Maps => "Maps",
147            Self::NumericPassword => "NumericPassword",
148            Self::NumericPin => "NumericPin",
149            Self::AlphanumericPin => "AlphanumericPin",
150            Self::FormulaNumber => "FormulaNumber",
151            Self::ChatWithoutEmoji => "ChatWithoutEmoji",
152        }
153    }
154
155    /// Converts only defined WinUI values, never manufacturing an invalid enum.
156    pub fn from_raw(value: i32) -> Option<Self> {
157        Self::ALL.into_iter().find(|item| *item as i32 == value)
158    }
159
160    /// Parses a public symbolic name or a defined numeric value.
161    pub fn parse(value: &str) -> Result<Self, FormatError> {
162        let value = value.trim();
163        Self::ALL
164            .into_iter()
165            .find(|item| item.name().eq_ignore_ascii_case(value))
166            .or_else(|| value.parse::<i32>().ok().and_then(Self::from_raw))
167            .ok_or_else(|| FormatError::new("The input scope name is not a defined WinUI value."))
168    }
169
170    /// Best matching existing FerroUI content type for hosts without this exact
171    /// scope. The original scope remains in TextInputOptions for richer hosts.
172    pub fn content_type(self) -> TextInputContentType {
173        use TextInputContentType as Content;
174        match self {
175            Self::Url => Content::Url,
176            Self::EmailSmtpAddress | Self::EmailNameOrAddress => Content::Email,
177            Self::PersonalFullName | Self::NameOrPhoneNumber => Content::Name,
178            Self::CurrencyAmountAndSymbol
179            | Self::CurrencyAmount
180            | Self::Number
181            | Self::NumberFullWidth
182            | Self::FormulaNumber => Content::Number,
183            Self::DateMonthNumber
184            | Self::DateDayNumber
185            | Self::DateYear
186            | Self::Digits
187            | Self::TelephoneNumber
188            | Self::TelephoneCountryCode
189            | Self::TelephoneAreaCode
190            | Self::TelephoneLocalNumber
191            | Self::TimeHour
192            | Self::TimeMinutesOrSeconds => Content::Digits,
193            Self::NumericPassword | Self::NumericPin => Content::Pin,
194            Self::Password | Self::AlphanumericPin => Content::Password,
195            Self::Search | Self::SearchIncremental | Self::Maps => Content::Search,
196            Self::Chat => Content::Social,
197            Self::AlphanumericHalfWidth => Content::Alpha,
198            _ => Content::Normal,
199        }
200    }
201}
202
203impl From<TextInputContentType> for InputScopeNameValue {
204    fn from(value: TextInputContentType) -> Self {
205        match value {
206            TextInputContentType::Normal => Self::Default,
207            TextInputContentType::Alpha => Self::AlphanumericHalfWidth,
208            TextInputContentType::Digits => Self::Digits,
209            TextInputContentType::Pin => Self::NumericPin,
210            TextInputContentType::Number => Self::Number,
211            TextInputContentType::Email => Self::EmailSmtpAddress,
212            TextInputContentType::Url => Self::Url,
213            TextInputContentType::Name => Self::PersonalFullName,
214            TextInputContentType::Password => Self::Password,
215            TextInputContentType::Social => Self::Chat,
216            TextInputContentType::Search => Self::Search,
217        }
218    }
219}
220
221crate::ferro_markup_enum!(InputScopeNameValue {
222    Default, Url, EmailSmtpAddress, PersonalFullName, CurrencyAmountAndSymbol,
223    CurrencyAmount, DateMonthNumber, DateDayNumber, DateYear, Digits, Number,
224    Password, TelephoneNumber, TelephoneCountryCode, TelephoneAreaCode,
225    TelephoneLocalNumber, TimeHour, TimeMinutesOrSeconds, NumberFullWidth,
226    AlphanumericHalfWidth, AlphanumericFullWidth, Hiragana, KatakanaHalfWidth,
227    KatakanaFullWidth, Hanja, HangulHalfWidth, HangulFullWidth, Search, Formula,
228    SearchIncremental, ChineseHalfWidth, ChineseFullWidth, NativeScript, Text,
229    Chat, NameOrPhoneNumber, EmailNameOrAddress, Maps, NumericPassword, NumericPin,
230    AlphanumericPin, FormulaNumber, ChatWithoutEmoji,
231}, { namespace: "FerroUI.Input" });