Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Input Method support to the Platform API #3811

Open
tronical opened this issue Oct 30, 2023 · 1 comment
Open

Add Input Method support to the Platform API #3811

tronical opened this issue Oct 30, 2023 · 1 comment
Labels
api Changes or additions to APIs

Comments

@tronical
Copy link
Member

tronical commented Oct 30, 2023

Currently all IME related functions are in WindowAdapterInternal, but we should make the API public to allow others implementing platform backends to provide or communicate with input methods.

We discussed the following API:

  1. A new function in WindowAdapter:
pub trait WindowAdapter {
    // Update the state of the input method
    fn input_method_request(&self, request: InputMethodRequest) {}
}

pub enum InputMethodRequest {
    Enable(InputMethodProperties),
    Update(InputMethodProperties),
    Disable
}

#[non_exhaustive]
#[derive(Clone, Default)]
pub struct InputMethodProperties {
    /// Surrounding text: (does not include pre-eedit text / composition)
    pub text: SharedString,

    pub cursor_position: usize,
    pub anchor_position: Option<usize>,
    pub preedit_text: SharedString,
    /// When the preedit_text is not empty, this is the offset of the preedit within the `text`
    pub preedit_offset: usize
    /// in window coordinates
    pub cursor_rect_origin: LogicalPosition,
    pub cursor_rect_size: LogicalSize,
    pub input_type: slint::platform::InputType, 

}
  1. For updating the state based on data from the IME, we add a new event:
pub enum WindowEvent {
    InputMethod(InputMethodEvent)
}

#[non_exhaustive]
#[derive(Default)]
struct InputMethodEvent {
    /// When None, replaces the selection
    pub replacement_range: Option<Range>,
    pub commit_text: Option<SharedString>,
    pub preedit_text: SharedString,
    /// When None, the cursor is pur after the commit_text
    pub cursor_position: Option<usize>,
}

The data structures are deliberately non-exhaustive to permit adding new fields in the future.

@tronical tronical added the api Changes or additions to APIs label Oct 30, 2023
@ogoffart ogoffart self-assigned this Nov 1, 2023
ogoffart added a commit that referenced this issue Nov 1, 2023
Part of #3811

But this is still on the internal trait for now
ogoffart added a commit that referenced this issue Nov 1, 2023
Base the info on what's discussed in #3811
but this is just the internal event and not the public API
ogoffart added a commit that referenced this issue Nov 2, 2023
Base the info on what's discussed in #3811
but this is just the internal event and not the public API
ogoffart added a commit that referenced this issue Nov 2, 2023
Base the info on what's discussed in #3811
but this is just the internal event and not the public API
ogoffart added a commit that referenced this issue Nov 2, 2023
Base the info on what's discussed in #3811
but this is just the internal event and not the public API
ogoffart added a commit that referenced this issue Nov 2, 2023
Part of #3811

But this is still on the internal trait for now
ogoffart added a commit that referenced this issue Nov 2, 2023
Base the info on what's discussed in #3811
but this is just the internal event and not the public API
@ogoffart ogoffart removed their assignment Dec 18, 2023
@ogoffart
Copy link
Member

The API has been implemented (in Rust) but is still internal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Changes or additions to APIs
Projects
None yet
Development

No branches or pull requests

2 participants