Skip to content

Commit 6bb2d5a

Browse files
committed
Introduce TextInput.caps-mode
1 parent c3d4d5e commit 6bb2d5a

File tree

11 files changed

+47
-4
lines changed

11 files changed

+47
-4
lines changed

api/cpp/cbindgen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ fn gen_corelib(
327327
"FillRule",
328328
"MouseCursor",
329329
"InputType",
330+
"CapsMode",
330331
"StandardButtonKind",
331332
"DialogButtonRole",
332333
"FocusReason",

internal/backends/android-activity/javahelper.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,21 @@ impl JavaHelper {
178178

179179
let class_it = env.find_class("android/text/InputType")?;
180180
let input_type = match data.input_type {
181-
InputType::Text => env.get_static_field(&class_it, "TYPE_CLASS_TEXT", "I")?.i()?,
181+
InputType::Text => {
182+
let caps_mode = match data.caps_mode {
183+
CapsMode::None => 0 as jint,
184+
CapsMode::Sentences => env
185+
.get_static_field(&class_it, "TYPE_TEXT_FLAG_CAP_SENTENCES", "I")?
186+
.i()?,
187+
CapsMode::Words => {
188+
env.get_static_field(&class_it, "TYPE_TEXT_FLAG_CAP_WORDS", "I")?.i()?
189+
}
190+
CapsMode::All => env
191+
.get_static_field(&class_it, "TYPE_TEXT_FLAG_CAP_CHARACTERS", "I")?
192+
.i()?,
193+
};
194+
env.get_static_field(&class_it, "TYPE_CLASS_TEXT", "I")?.i()? | caps_mode
195+
}
182196
InputType::Password => {
183197
env.get_static_field(&class_it, "TYPE_TEXT_VARIATION_PASSWORD", "I")?.i()?
184198
| env.get_static_field(&class_it, "TYPE_CLASS_TEXT", "I")?.i()?

internal/backends/qt/qt_widgets/lineedit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use i_slint_core::graphics::{Image, Rgba8Pixel, SharedPixelBuffer};
55
use i_slint_core::input::FocusEventResult;
6-
use i_slint_core::items::InputType;
6+
use i_slint_core::items::{CapsMode, InputType};
77

88
use super::*;
99

@@ -20,6 +20,7 @@ pub struct NativeLineEdit {
2020
pub enabled: Property<bool>,
2121
pub input_type: Property<InputType>,
2222
pub clear_icon: Property<Image>,
23+
pub caps_mode: Property<CapsMode>,
2324
widget_ptr: std::cell::Cell<SlintTypeErasedWidgetPtr>,
2425
animation_tracker: Property<i32>,
2526
}

internal/common/enums.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ macro_rules! for_each_enums {
6666
Center,
6767
}
6868

69+
/// This enum describes the how the soft-keyboard auto-capitalization should work for `TextInput`s.
70+
/// Currently only supported on Android.
71+
enum CapsMode {
72+
/// No auto-capitalization
73+
None,
74+
/// Capitalize the first character of each sentence
75+
Sentences,
76+
/// capitalize the first character of each word
77+
Words,
78+
/// Capitalize all characters
79+
All,
80+
}
81+
6982
/// This enum describes whether an event was rejected or accepted by an event handler.
7083
enum EventResult {
7184
/// The event is rejected by this event handler and may then be handled by the parent item

internal/compiler/builtins.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ export component TextInput {
316316
in property <length> page-height;
317317
in property <length> text-cursor-width; // StyleMetrics.text-cursor-width set in apply_default_properties_from_style
318318
in property <InputType> input-type;
319+
in property <CapsMode> caps-mode;
319320
// Internal, undocumented property, only exposed for tests.
320321
out property <int> cursor-position_byte-offset;
321322
// Internal, undocumented property, only exposed for tests.

internal/compiler/widgets/common/lineedit-base.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export component LineEditBase inherits Rectangle {
99
in property <bool> enabled <=> text-input.enabled;
1010
out property <bool> has-focus: text-input.has-focus;
1111
in property <InputType> input-type <=> text-input.input-type;
12+
in property <CapsMode> caps-mode <=> text-input.caps-mode;
1213
in property <TextHorizontalAlignment> horizontal-alignment <=> text-input.horizontal-alignment;
1314
in property <bool> read-only <=> text-input.read-only;
1415
in property <int> font-weight <=> text-input.font-weight;

internal/compiler/widgets/cosmic/lineedit.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common
77
export component LineEdit {
88
in property <bool> enabled <=> base.enabled;
99
in property <InputType> input-type;
10+
in property <CapsMode> caps-mode <=> base.caps-mode;
1011
in property <TextHorizontalAlignment> horizontal-alignment <=> base.horizontal-alignment;
1112
in property <bool> read-only <=> base.read-only;
1213
in property <length> font-size <=> base.font-size;

internal/compiler/widgets/cupertino/lineedit.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common
88
export component LineEdit {
99
in property <bool> enabled <=> base.enabled;
1010
in property <InputType> input-type;
11+
in property <CapsMode> caps-mode <=> base.caps-mode;
1112
in property <TextHorizontalAlignment> horizontal-alignment <=> base.horizontal-alignment;
1213
in property <bool> read-only <=> base.read-only;
1314
in property <length> font-size <=> base.font-size;

internal/compiler/widgets/fluent/lineedit.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common
77
export component LineEdit {
88
in property <bool> enabled <=> base.enabled;
99
in property <InputType> input-type;
10+
in property <CapsMode> caps-mode <=> base.caps-mode;
1011
in property <TextHorizontalAlignment> horizontal-alignment <=> base.horizontal-alignment;
1112
in property <bool> read-only <=> base.read-only;
1213
in property <length> font-size <=> base.font-size;

internal/core/items/text.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ When adding an item or a property, it needs to be kept in sync with different pl
88
Lookup the [`crate::items`] module documentation.
99
*/
1010
use super::{
11-
EventResult, FontMetrics, InputType, Item, ItemConsts, ItemRc, ItemRef, KeyEventArg,
11+
CapsMode, EventResult, FontMetrics, InputType, Item, ItemConsts, ItemRc, ItemRef, KeyEventArg,
1212
KeyEventResult, KeyEventType, PointArg, PointerEventButton, RenderingResult,
1313
TextHorizontalAlignment, TextOverflow, TextStrokeStyle, TextVerticalAlignment, TextWrap,
1414
VoidArg, WindowItem,
@@ -484,6 +484,7 @@ pub struct TextInput {
484484
pub vertical_alignment: Property<TextVerticalAlignment>,
485485
pub wrap: Property<TextWrap>,
486486
pub input_type: Property<InputType>,
487+
pub caps_mode: Property<CapsMode>,
487488
pub letter_spacing: Property<LogicalLength>,
488489
pub width: Property<LogicalLength>,
489490
pub height: Property<LogicalLength>,
@@ -1498,6 +1499,7 @@ impl TextInput {
14981499
cursor_rect_size,
14991500
anchor_point,
15001501
input_type: self.input_type(),
1502+
caps_mode: self.caps_mode(),
15011503
}
15021504
}
15031505

0 commit comments

Comments
 (0)