Skip to content

Commit 74c6e16

Browse files
committed
Introduce TextInput.caps-mode
1 parent c3d4d5e commit 74c6e16

File tree

13 files changed

+50
-5
lines changed

13 files changed

+50
-5
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: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use super::*;
55
use i_slint_core::api::{PhysicalPosition, PhysicalSize};
66
use i_slint_core::graphics::{euclid, Color};
7-
use i_slint_core::items::{ColorScheme, InputType};
7+
use i_slint_core::items::{CapsMode, ColorScheme, InputType};
88
use i_slint_core::platform::WindowAdapter;
99
use i_slint_core::SharedString;
1010
use jni::objects::{JClass, JObject, JString, JValue};
@@ -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/compiler/widgets/material/lineedit.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export component LineEdit {
1010
in property <string> placeholder-text <=> base.placeholder-text;
1111
in property <bool> enabled <=> base.enabled;
1212
in property <InputType> input-type;
13+
in property <CapsMode> caps-mode <=> base.caps-mode;
1314
in property horizontal-alignment <=> base.horizontal-alignment;
1415
in property read-only <=> base.read-only;
1516
out property <bool> has-focus: base.has-focus;

0 commit comments

Comments
 (0)