Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/cpp/cbindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ fn gen_corelib(
"FillRule",
"MouseCursor",
"InputType",
"CapsMode",
"StandardButtonKind",
"DialogButtonRole",
"FocusReason",
Expand Down
18 changes: 16 additions & 2 deletions internal/backends/android-activity/javahelper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use super::*;
use i_slint_core::api::{PhysicalPosition, PhysicalSize};
use i_slint_core::graphics::{euclid, Color};
use i_slint_core::items::{ColorScheme, InputType};
use i_slint_core::items::{CapsMode, ColorScheme, InputType};
use i_slint_core::platform::WindowAdapter;
use i_slint_core::SharedString;
use jni::objects::{JClass, JObject, JString, JValue};
Expand Down Expand Up @@ -178,7 +178,21 @@ impl JavaHelper {

let class_it = env.find_class("android/text/InputType")?;
let input_type = match data.input_type {
InputType::Text => env.get_static_field(&class_it, "TYPE_CLASS_TEXT", "I")?.i()?,
InputType::Text => {
let caps_mode = match data.caps_mode {
CapsMode::None => 0 as jint,
CapsMode::Sentences => env
.get_static_field(&class_it, "TYPE_TEXT_FLAG_CAP_SENTENCES", "I")?
.i()?,
CapsMode::Words => {
env.get_static_field(&class_it, "TYPE_TEXT_FLAG_CAP_WORDS", "I")?.i()?
}
CapsMode::All => env
.get_static_field(&class_it, "TYPE_TEXT_FLAG_CAP_CHARACTERS", "I")?
.i()?,
};
env.get_static_field(&class_it, "TYPE_CLASS_TEXT", "I")?.i()? | caps_mode
}
InputType::Password => {
env.get_static_field(&class_it, "TYPE_TEXT_VARIATION_PASSWORD", "I")?.i()?
| env.get_static_field(&class_it, "TYPE_CLASS_TEXT", "I")?.i()?
Expand Down
3 changes: 2 additions & 1 deletion internal/backends/qt/qt_widgets/lineedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use i_slint_core::graphics::{Image, Rgba8Pixel, SharedPixelBuffer};
use i_slint_core::input::FocusEventResult;
use i_slint_core::items::InputType;
use i_slint_core::items::{CapsMode, InputType};

use super::*;

Expand All @@ -20,6 +20,7 @@ pub struct NativeLineEdit {
pub enabled: Property<bool>,
pub input_type: Property<InputType>,
pub clear_icon: Property<Image>,
pub caps_mode: Property<CapsMode>,
widget_ptr: std::cell::Cell<SlintTypeErasedWidgetPtr>,
animation_tracker: Property<i32>,
}
Expand Down
13 changes: 13 additions & 0 deletions internal/common/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ macro_rules! for_each_enums {
Center,
}

/// This enum describes the how the soft-keyboard auto-capitalization should work for `TextInput`s.
/// Currently only supported on Android.
enum CapsMode {
/// No auto-capitalization
None,
/// Capitalize the first character of each sentence
Sentences,
/// capitalize the first character of each word
Words,
/// Capitalize all characters
All,
}

/// This enum describes whether an event was rejected or accepted by an event handler.
enum EventResult {
/// The event is rejected by this event handler and may then be handled by the parent item
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export component TextInput {
in property <length> page-height;
in property <length> text-cursor-width; // StyleMetrics.text-cursor-width set in apply_default_properties_from_style
in property <InputType> input-type;
in property <CapsMode> caps-mode;
// Internal, undocumented property, only exposed for tests.
out property <int> cursor-position_byte-offset;
// Internal, undocumented property, only exposed for tests.
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/widgets/common/lineedit-base.slint
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export component LineEditBase inherits Rectangle {
in property <bool> enabled <=> text-input.enabled;
out property <bool> has-focus: text-input.has-focus;
in property <InputType> input-type <=> text-input.input-type;
in property <CapsMode> caps-mode <=> text-input.caps-mode;
in property <TextHorizontalAlignment> horizontal-alignment <=> text-input.horizontal-alignment;
in property <bool> read-only <=> text-input.read-only;
in property <int> font-weight <=> text-input.font-weight;
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/widgets/cosmic/lineedit.slint
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common
export component LineEdit {
in property <bool> enabled <=> base.enabled;
in property <InputType> input-type;
in property <CapsMode> caps-mode <=> base.caps-mode;
in property <TextHorizontalAlignment> horizontal-alignment <=> base.horizontal-alignment;
in property <bool> read-only <=> base.read-only;
in property <length> font-size <=> base.font-size;
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/widgets/cupertino/lineedit.slint
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common
export component LineEdit {
in property <bool> enabled <=> base.enabled;
in property <InputType> input-type;
in property <CapsMode> caps-mode <=> base.caps-mode;
in property <TextHorizontalAlignment> horizontal-alignment <=> base.horizontal-alignment;
in property <bool> read-only <=> base.read-only;
in property <length> font-size <=> base.font-size;
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/widgets/fluent/lineedit.slint
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common
export component LineEdit {
in property <bool> enabled <=> base.enabled;
in property <InputType> input-type;
in property <CapsMode> caps-mode <=> base.caps-mode;
in property <TextHorizontalAlignment> horizontal-alignment <=> base.horizontal-alignment;
in property <bool> read-only <=> base.read-only;
in property <length> font-size <=> base.font-size;
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/widgets/material/lineedit.slint
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export component LineEdit {
in property <string> placeholder-text <=> base.placeholder-text;
in property <bool> enabled <=> base.enabled;
in property <InputType> input-type;
in property <CapsMode> caps-mode <=> base.caps-mode;
in property horizontal-alignment <=> base.horizontal-alignment;
in property read-only <=> base.read-only;
out property <bool> has-focus: base.has-focus;
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/widgets/qt/lineedit.slint
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export component LineEdit {
in property <length> font-size <=> inner.font-size;
in property <string> placeholder-text <=> inner.placeholder-text;
in property input-type <=> inner.input-type;
in property <CapsMode> caps-mode <=> inner.caps-mode;
in property horizontal-alignment <=> inner.horizontal-alignment;
in property read-only <=> inner.read-only;
in property <bool> enabled: true;
Expand Down
4 changes: 3 additions & 1 deletion internal/core/items/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ When adding an item or a property, it needs to be kept in sync with different pl
Lookup the [`crate::items`] module documentation.
*/
use super::{
EventResult, FontMetrics, InputType, Item, ItemConsts, ItemRc, ItemRef, KeyEventArg,
CapsMode, EventResult, FontMetrics, InputType, Item, ItemConsts, ItemRc, ItemRef, KeyEventArg,
KeyEventResult, KeyEventType, PointArg, PointerEventButton, RenderingResult,
TextHorizontalAlignment, TextOverflow, TextStrokeStyle, TextVerticalAlignment, TextWrap,
VoidArg, WindowItem,
Expand Down Expand Up @@ -484,6 +484,7 @@ pub struct TextInput {
pub vertical_alignment: Property<TextVerticalAlignment>,
pub wrap: Property<TextWrap>,
pub input_type: Property<InputType>,
pub caps_mode: Property<CapsMode>,
pub letter_spacing: Property<LogicalLength>,
pub width: Property<LogicalLength>,
pub height: Property<LogicalLength>,
Expand Down Expand Up @@ -1498,6 +1499,7 @@ impl TextInput {
cursor_rect_size,
anchor_point,
input_type: self.input_type(),
caps_mode: self.caps_mode(),
}
}

Expand Down
9 changes: 8 additions & 1 deletion internal/core/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::item_tree::{
ItemRc, ItemTreeRc, ItemTreeRef, ItemTreeVTable, ItemTreeWeak, ItemWeak,
ParentItemTraversalMode,
};
use crate::items::{ColorScheme, InputType, ItemRef, MouseCursor, PopupClosePolicy};
use crate::items::{CapsMode, ColorScheme, InputType, ItemRef, MouseCursor, PopupClosePolicy};
use crate::lengths::{LogicalLength, LogicalPoint, LogicalRect, SizeLengths};
use crate::menus::MenuVTable;
use crate::properties::{Property, PropertyTracker};
Expand Down Expand Up @@ -293,6 +293,8 @@ pub struct InputMethodProperties {
pub anchor_point: LogicalPosition,
/// The type of input for the text edit.
pub input_type: InputType,
/// The caps mode for the text edit
pub caps_mode: CapsMode,
}

/// This struct describes layout constraints of a resizable element, such as a window.
Expand Down Expand Up @@ -915,6 +917,11 @@ impl WindowInner {
}
}

/// Unfocus the currently focused item, if any.
pub fn unfocus_current(&self) {
self.take_focus_item(&FocusEvent::FocusOut(FocusReason::Programmatic));
}

/// Publish the new focus_item to this Window and return the FocusEventResult
///
/// This sends a FocusIn event!
Expand Down
Loading