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

basic IME support rebase #1858

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
86a16f9
ime rebase
KentaTheBugMaker May 20, 2023
956dc9d
Merge branch 'iced-rs:master' into ime_adavanced_text
KentaTheBugMaker May 23, 2023
b68dae0
Merge branch 'iced-rs:master' into ime_adavanced_text
KentaTheBugMaker Jun 2, 2023
e2de5de
fix needless clone
KentaTheBugMaker Jun 2, 2023
91fe845
fix macos build issue
KentaTheBugMaker Jun 2, 2023
5b17793
doc test fix
KentaTheBugMaker Jun 2, 2023
8411b87
Merge branch 'master' into ime_adavanced_text
KentaTheBugMaker Jun 21, 2023
ed17552
merge related fix
KentaTheBugMaker Jun 21, 2023
c1d93f7
Merge pull request #20 from iced-rs/master
KentaTheBugMaker Jun 21, 2023
2522fd1
doctest fix
KentaTheBugMaker Jun 21, 2023
8d77971
Merge branch 'ime_adavanced_text' of https://github.com/t18b219k/iced…
KentaTheBugMaker Jun 21, 2023
6205b93
Merge branch 'ime_adavanced_text' of https://github.com/t18b219k/iced…
KentaTheBugMaker Nov 11, 2023
1add649
add ime command interface for widgets.
KentaTheBugMaker Nov 11, 2023
f2f850c
fixed to match latest iced
KentaTheBugMaker Nov 12, 2023
f6ee02e
merge upstream
KentaTheBugMaker Nov 12, 2023
6a358cf
fit to ime
KentaTheBugMaker Nov 12, 2023
50fb846
lint fix
KentaTheBugMaker Nov 12, 2023
9189c65
fix lint macos
KentaTheBugMaker Nov 12, 2023
6ac0176
fix mac lint
KentaTheBugMaker Nov 12, 2023
96514f1
fix offset calculation
KentaTheBugMaker Nov 12, 2023
aaa1af4
Merge pull request #22 from t18b219k/latest_master_1112
KentaTheBugMaker Nov 12, 2023
087bb59
Merge branch 'iced-rs:master' into ime_adavanced_text
KentaTheBugMaker Nov 12, 2023
e6450c4
Merge branch 'iced-rs:master' into ime_adavanced_text
KentaTheBugMaker Nov 15, 2023
b927163
add ime parameter for Shader widget
KentaTheBugMaker Nov 15, 2023
f9187a3
restrict overflowing IME candidate window
KentaTheBugMaker Nov 16, 2023
3fb06a7
more precise event handling
KentaTheBugMaker Nov 16, 2023
c5ffd5f
Merge branch 'iced-rs:master' into ime_adavanced_text
KentaTheBugMaker Nov 17, 2023
48e68e2
Merge branch 'ime_adavanced_text' into upstream20231122
KentaTheBugMaker Nov 22, 2023
defc22c
import layout in overlay
KentaTheBugMaker Nov 22, 2023
32a62e3
apply fmt
KentaTheBugMaker Nov 22, 2023
dbc34f1
Merge pull request #23 from KentaTheBugMaker/upstream20231122
KentaTheBugMaker Nov 24, 2023
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
16 changes: 9 additions & 7 deletions core/src/element.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget;
use crate::widget::tree::{self, Tree};
use crate::{
Clipboard, Color, Layout, Length, Rectangle, Shell, Vector, Widget,
};
use crate::IME;
use crate::{layout, mouse};
use crate::{overlay, Vector};
use crate::{Clipboard, Color, Layout, Length, Rectangle, Shell, Widget};

use std::any::Any;
use std::borrow::Borrow;
Expand Down Expand Up @@ -385,6 +383,7 @@ where
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, B>,
viewport: &Rectangle,
) -> event::Status {
Expand All @@ -398,6 +397,7 @@ where
cursor,
renderer,
clipboard,
ime,
&mut local_shell,
viewport,
);
Expand Down Expand Up @@ -519,11 +519,13 @@ where
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.element.widget.on_event(
state, event, layout, cursor, renderer, clipboard, shell, viewport,
state, event, layout, cursor, renderer, clipboard, ime, shell,
viewport,
)
}

Expand Down
5 changes: 4 additions & 1 deletion core/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Handle events of a user interface.
use crate::ime;
use crate::keyboard;
use crate::mouse;
use crate::touch;
use crate::window;

/// A user interface event.
///
/// _**Note:** This type is largely incomplete! If you need to track
Expand All @@ -26,6 +26,9 @@ pub enum Event {

/// A platform specific event
PlatformSpecific(PlatformSpecific),

/// A ime event
IME(ime::Event),
}

/// A platform specific event
Expand Down
65 changes: 65 additions & 0 deletions core/src/ime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Access the IME.

mod event;

pub use event::Event;

/// IME Access interface.
pub trait IME {
///
fn set_ime_position(&self, x: i32, y: i32);

/// need to call if clicked position is widget's region.
///
/// IME willbe enabled.
fn inside(&self);

/// need to call if clicked position is not widget's region.
///
/// used to determine disable ime.
fn outside(&self);

/// disable IME.
///
fn password_mode(&self);

/// force ime enabled or disabled.
///
/// this will block request until unlock_set_ime_allowed.
fn force_set_ime_allowed(&self, _allowed: bool);
/// remove request of force_set_ime_allowed
///
fn unlock_set_ime_allowed(&self);

#[cfg(target_os = "macos")]
/// macos's strange behavior of set_ime_position workaround.
///
/// on macos we can't move cadidate window by set_ime_position.
///
/// we set ime candidate window position by these steps when IME::Commit event processed.
///
/// * disable IME
/// * set candidate position
/// * enable IME
fn set_ime_position_with_reenable(&self, x: i32, y: i32);
}

/// A null implementation of the [`IME`] trait.
#[derive(Debug, Clone, Copy)]
pub struct Null;

impl IME for Null {
fn set_ime_position(&self, _x: i32, _y: i32) {}

fn outside(&self) {}

fn password_mode(&self) {}

fn inside(&self) {}

fn force_set_ime_allowed(&self, _: bool) {}

fn unlock_set_ime_allowed(&self) {}
#[cfg(target_os = "macos")]
fn set_ime_position_with_reenable(&self, _x: i32, _y: i32) {}
}
19 changes: 19 additions & 0 deletions core/src/ime/event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// A IME event.
///
/// _**Note:** This type is largely incomplete! If you need to track
/// additional events, feel free to [open an issue] and share your use case!_
///
/// [open an issue]: https://github.com/iced-rs/iced/issues
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
/// IME enabled.
IMEEnabled,

/// selecting input.
IMEPreedit(String, Option<(usize, usize)>),

/// enter input.
IMECommit(String),
/// Notifies when the IME was disabled.
IMEDisabled,
}
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod event;
pub mod font;
pub mod gradient;
pub mod image;
pub mod ime;
pub mod keyboard;
pub mod layout;
pub mod mouse;
Expand Down Expand Up @@ -62,6 +63,7 @@ pub use event::Event;
pub use font::Font;
pub use gradient::Gradient;
pub use hasher::Hasher;
pub use ime::IME;
pub use layout::Layout;
pub use length::Length;
pub use overlay::Overlay;
Expand Down
6 changes: 4 additions & 2 deletions core/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ pub use element::Element;
pub use group::Group;

use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::renderer;
use crate::widget;
use crate::widget::Tree;
use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector};
use crate::{
layout, Clipboard, Layout, Point, Rectangle, Shell, Size, Vector, IME,
};

/// An interactive component that can be displayed on top of other widgets.
pub trait Overlay<Message, Renderer>
Expand Down Expand Up @@ -70,6 +71,7 @@ where
_cursor: mouse::Cursor,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_ime: &dyn IME,
_shell: &mut Shell<'_, Message>,
) -> event::Status {
event::Status::Ignored
Expand Down
7 changes: 5 additions & 2 deletions core/src/overlay/element.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub use crate::Overlay;

use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::renderer;
use crate::widget;
use crate::{layout, IME};
use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector};

use std::any::Any;
Expand Down Expand Up @@ -82,10 +82,11 @@ where
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.overlay
.on_event(event, layout, cursor, renderer, clipboard, shell)
.on_event(event, layout, cursor, renderer, clipboard, ime, shell)
}

/// Returns the current [`mouse::Interaction`] of the [`Element`].
Expand Down Expand Up @@ -236,6 +237,7 @@ where
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, B>,
) -> event::Status {
let mut local_messages = Vec::new();
Expand All @@ -247,6 +249,7 @@ where
cursor,
renderer,
clipboard,
ime,
&mut local_shell,
);

Expand Down
4 changes: 4 additions & 0 deletions core/src/overlay/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget;

use crate::{
Clipboard, Event, Layout, Overlay, Point, Rectangle, Shell, Size, Vector,
IME,
};

/// An [`Overlay`] container that displays multiple overlay [`overlay::Element`]
Expand Down Expand Up @@ -85,6 +87,7 @@ where
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.children
Expand All @@ -97,6 +100,7 @@ where
cursor,
renderer,
clipboard,
ime,
shell,
)
})
Expand Down
3 changes: 2 additions & 1 deletion core/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub use tree::Tree;

use crate::event::{self, Event};
use crate::layout::{self, Layout};
use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::{mouse, IME};
use crate::{Clipboard, Length, Rectangle, Shell};

/// A component that displays information and allows interaction.
Expand Down Expand Up @@ -115,6 +115,7 @@ where
_cursor: mouse::Cursor,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_ime: &dyn IME,
_shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
Expand Down
7 changes: 4 additions & 3 deletions examples/integration/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iced_winit::core::{Color, Font, Pixels, Size};
use iced_winit::runtime::program;
use iced_winit::runtime::Debug;
use iced_winit::style::Theme;
use iced_winit::{conversion, futures, winit, Clipboard};
use iced_winit::{conversion, futures, winit, Clipboard, IME};

use winit::{
event::{Event, ModifiersState, WindowEvent},
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut cursor_position = None;
let mut modifiers = ModifiersState::default();
let mut clipboard = Clipboard::connect(&window);

let ime = IME::new();
// Initialize wgpu
#[cfg(target_arch = "wasm32")]
let default_backend = wgpu::Backends::GL;
Expand Down Expand Up @@ -208,9 +208,10 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
text_color: Color::WHITE,
},
&mut clipboard,
&ime,
&mut debug,
);

ime.apply_request(&window);
// and request a redraw
window.request_redraw();
}
Expand Down
2 changes: 2 additions & 0 deletions examples/loading_spinners/src/circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use iced::advanced::layout;
use iced::advanced::renderer;
use iced::advanced::widget::tree::{self, Tree};
use iced::advanced::IME;
use iced::advanced::{Clipboard, Layout, Renderer, Shell, Widget};
use iced::event;
use iced::mouse;
Expand Down Expand Up @@ -272,6 +273,7 @@ where
_cursor: mouse::Cursor,
_renderer: &iced::Renderer<Theme>,
_clipboard: &mut dyn Clipboard,
_ime: &dyn IME,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
Expand Down
3 changes: 2 additions & 1 deletion examples/loading_spinners/src/linear.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Show a linear progress indicator.
use iced::advanced::layout;
use iced::advanced::renderer::{self, Quad};
use iced::advanced::widget::tree::{self, Tree};
use iced::advanced::{layout, IME};
use iced::advanced::{Clipboard, Layout, Shell, Widget};
use iced::event;
use iced::mouse;
Expand Down Expand Up @@ -193,6 +193,7 @@ where
_cursor: mouse::Cursor,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_ime: &dyn IME,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
Expand Down
6 changes: 5 additions & 1 deletion examples/modal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod modal {
use iced::advanced::overlay;
use iced::advanced::renderer;
use iced::advanced::widget::{self, Widget};
use iced::advanced::{self, Clipboard, Shell};
use iced::advanced::{self, Clipboard, Shell, IME};
use iced::alignment::Alignment;
use iced::event;
use iced::mouse;
Expand Down Expand Up @@ -310,6 +310,7 @@ mod modal {
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
Expand All @@ -320,6 +321,7 @@ mod modal {
cursor,
renderer,
clipboard,
ime,
shell,
viewport,
)
Expand Down Expand Up @@ -440,6 +442,7 @@ mod modal {
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> event::Status {
let content_bounds = layout.children().next().unwrap().bounds();
Expand All @@ -463,6 +466,7 @@ mod modal {
cursor,
renderer,
clipboard,
ime,
shell,
&layout.bounds(),
)
Expand Down
Loading