Skip to content

Commit

Permalink
Merge branch 'ime_adavanced_text' into upstream20231122
Browse files Browse the repository at this point in the history
  • Loading branch information
KentaTheBugMaker authored Nov 22, 2023
2 parents 100d15f + c5ffd5f commit 48e68e2
Show file tree
Hide file tree
Showing 53 changed files with 906 additions and 70 deletions.
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
5 changes: 3 additions & 2 deletions core/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pub use element::Element;
pub use group::Group;

use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::renderer;

Check failure on line 10 in core/src/overlay.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/core/src/overlay.rs

Check failure on line 10 in core/src/overlay.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/core/src/overlay.rs
use crate::widget;
use crate::widget::Tree;
use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector};
use crate::{Clipboard,IME, Layout, Point, Rectangle, Shell, Size, Vector};


/// An interactive component that can be displayed on top of other widgets.
pub trait Overlay<Message, Renderer>
Expand Down Expand Up @@ -70,6 +70,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
6 changes: 5 additions & 1 deletion core/src/overlay/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget;

Check failure on line 6 in core/src/overlay/group.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/core/src/overlay/group.rs

Check failure on line 6 in core/src/overlay/group.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced/iced/core/src/overlay/group.rs

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


/// An [`Overlay`] container that displays multiple overlay [`overlay::Element`]
/// children.
#[allow(missing_debug_implementations)]
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

0 comments on commit 48e68e2

Please sign in to comment.