Skip to content

Commit

Permalink
Merge pull request iced-rs#2 from t18b219k/ime_support
Browse files Browse the repository at this point in the history
Move IME candidate window .
sorry for big change
  • Loading branch information
KentaTheBugMaker authored Oct 20, 2022
2 parents 54a7de7 + ec2aba2 commit 9c72c92
Show file tree
Hide file tree
Showing 38 changed files with 268 additions and 93 deletions.
4 changes: 3 additions & 1 deletion examples/integration_opengl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod controls;
mod scene;

use controls::Controls;
use iced_glutin::ime::IME;
use scene::Scene;

use glow::*;
Expand Down Expand Up @@ -77,7 +78,7 @@ pub fn main() {

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

let ime = IME::connect(windowed_context.window());
match event {
Event::WindowEvent { event, .. } => {
match event {
Expand Down Expand Up @@ -130,6 +131,7 @@ pub fn main() {
text_color: Color::WHITE,
},
&mut clipboard,
&ime,
&mut debug,
);

Expand Down
8 changes: 5 additions & 3 deletions examples/integration_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use scene::Scene;

use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport};
use iced_winit::{
conversion, futures, program, renderer, winit, Clipboard, Color, Debug,
Size,
conversion, futures, ime::IME, program, renderer, winit, Clipboard, Color,
Debug, Size,
};

use winit::{
Expand Down Expand Up @@ -147,7 +147,8 @@ pub fn main() {
event_loop.run(move |event, _, control_flow| {
// You should change this if you want to render continuosly
*control_flow = ControlFlow::Wait;

let ime = IME::connect(&window);
ime.set_ime_allowed(true);
match event {
Event::WindowEvent { event, .. } => {
match event {
Expand Down Expand Up @@ -189,6 +190,7 @@ pub fn main() {
&iced_wgpu::Theme::Dark,
&renderer::Style { text_color: Color::WHITE },
&mut clipboard,
& ime,
&mut debug,
);

Expand Down
1 change: 1 addition & 0 deletions examples/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ publish = false

[dependencies]
iced = { path = "../..", features = ["async-std", "debug"] }
iced_native = {path="../../native/"}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4"
Expand Down
7 changes: 6 additions & 1 deletion glutin/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use iced_winit::application;
use iced_winit::conversion;
use iced_winit::futures;
use iced_winit::futures::channel::mpsc;
use iced_winit::ime::IME;
use iced_winit::renderer;
use iced_winit::user_interface;
use iced_winit::{Clipboard, Command, Debug, Proxy, Settings};
Expand Down Expand Up @@ -194,7 +195,7 @@ async fn run_instance<A, E, C>(
{
use glutin::event;
use iced_winit::futures::stream::StreamExt;

let mut ime = IME::connect(context.window());
let mut clipboard = Clipboard::connect(context.window());
let mut cache = user_interface::Cache::default();
let mut state = application::State::new(&application, context.window());
Expand All @@ -208,6 +209,7 @@ async fn run_instance<A, E, C>(
init_command,
&mut runtime,
&mut clipboard,
&ime,
&mut proxy,
&mut debug,
context.window(),
Expand Down Expand Up @@ -244,6 +246,7 @@ async fn run_instance<A, E, C>(
state.cursor_position(),
&mut renderer,
&mut clipboard,
&ime,
&mut messages,
);

Expand All @@ -270,6 +273,7 @@ async fn run_instance<A, E, C>(
&mut renderer,
&mut runtime,
&mut clipboard,
&ime,
&mut proxy,
&mut debug,
&mut messages,
Expand Down Expand Up @@ -339,6 +343,7 @@ async fn run_instance<A, E, C>(
context = context
.make_current()
.expect("Make OpenGL context current");
ime = IME::connect(context.window());
}
}

Expand Down
3 changes: 2 additions & 1 deletion graphics/src/widget/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub use text::Text;
use crate::{Backend, Primitive, Renderer};

use iced_native::layout::{self, Layout};
use iced_native::mouse;
use iced_native::renderer;
use iced_native::widget::tree::{self, Tree};
use iced_native::{mouse, IME};
use iced_native::{
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Vector, Widget,
};
Expand Down Expand Up @@ -165,6 +165,7 @@ where
cursor_position: Point,
_renderer: &Renderer<B, T>,
_clipboard: &mut dyn Clipboard,
_ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> event::Status {
let bounds = layout.bounds();
Expand Down
6 changes: 5 additions & 1 deletion lazy/src/component.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Build and reuse custom widgets using The Elm Architecture.
use iced_native::event;
use iced_native::layout::{self, Layout};
use iced_native::mouse;
use iced_native::overlay;
use iced_native::renderer;
use iced_native::widget;
use iced_native::widget::tree::{self, Tree};
use iced_native::{event, IME};
use iced_native::{
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
};
Expand Down Expand Up @@ -178,6 +178,7 @@ where
cursor_position: Point,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> event::Status {
let mut local_messages = Vec::new();
Expand All @@ -191,6 +192,7 @@ where
cursor_position,
renderer,
clipboard,
ime,
&mut local_shell,
)
});
Expand Down Expand Up @@ -455,6 +457,7 @@ where
cursor_position: Point,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> iced_native::event::Status {
let mut local_messages = Vec::new();
Expand All @@ -468,6 +471,7 @@ where
cursor_position,
renderer,
clipboard,
ime,
&mut local_shell,
)
})
Expand Down
6 changes: 5 additions & 1 deletion lazy/src/responsive.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use iced_native::event;
use iced_native::layout::{self, Layout};
use iced_native::mouse;
use iced_native::overlay;
use iced_native::renderer;
use iced_native::widget::horizontal_space;
use iced_native::widget::tree::{self, Tree};
use iced_native::{event, IME};
use iced_native::{
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
};
Expand Down Expand Up @@ -150,6 +150,7 @@ where
cursor_position: Point,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> event::Status {
let state = tree.state.downcast_mut::<State>();
Expand All @@ -168,6 +169,7 @@ where
cursor_position,
renderer,
clipboard,
ime,
shell,
)
},
Expand Down Expand Up @@ -372,6 +374,7 @@ where
cursor_position: Point,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.with_overlay_mut_maybe(|overlay| {
Expand All @@ -381,6 +384,7 @@ where
cursor_position,
renderer,
clipboard,
ime,
shell,
)
})
Expand Down
8 changes: 8 additions & 0 deletions native/src/command/action.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::clipboard;
use crate::ime;
use crate::system;
use crate::widget;
use crate::window;
Expand All @@ -19,6 +20,9 @@ pub enum Action<T> {
/// Run a clipboard action.
Clipboard(clipboard::Action<T>),

/// Run a IME releated action.
IME(ime::Action),

/// Run a window action.
Window(window::Action<T>),

Expand Down Expand Up @@ -46,6 +50,7 @@ impl<T> Action<T> {
match self {
Self::Future(future) => Action::Future(Box::pin(future.map(f))),
Self::Clipboard(action) => Action::Clipboard(action.map(f)),
Self::IME(action) => Action::IME(action),
Self::Window(window) => Action::Window(window.map(f)),
Self::System(system) => Action::System(system.map(f)),
Self::Widget(widget) => Action::Widget(widget.map(f)),
Expand All @@ -60,6 +65,9 @@ impl<T> fmt::Debug for Action<T> {
Self::Clipboard(action) => {
write!(f, "Action::Clipboard({:?})", action)
}
Self::IME(action) => {
write!(f, "Action::IME({:?})", action)
}
Self::Window(action) => write!(f, "Action::Window({:?})", action),
Self::System(action) => write!(f, "Action::System({:?})", action),
Self::Widget(_action) => write!(f, "Action::Widget"),
Expand Down
6 changes: 5 additions & 1 deletion native/src/element.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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::{layout, IME};
use crate::{
Clipboard, Color, Layout, Length, Point, Rectangle, Shell, Widget,
};
Expand Down Expand Up @@ -330,6 +330,7 @@ where
cursor_position: Point,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, B>,
) -> event::Status {
let mut local_messages = Vec::new();
Expand All @@ -342,6 +343,7 @@ where
cursor_position,
renderer,
clipboard,
ime,
&mut local_shell,
);

Expand Down Expand Up @@ -470,6 +472,7 @@ where
cursor_position: Point,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
ime: &dyn IME,
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.element.widget.on_event(
Expand All @@ -479,6 +482,7 @@ where
cursor_position,
renderer,
clipboard,
ime,
shell,
)
}
Expand Down
43 changes: 43 additions & 0 deletions native/src/ime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Access the IME.
use std::fmt;

///
pub trait IME {
///
fn set_ime_allowed(&self, allowed: bool);

///
fn set_ime_position(&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_allowed(&self, _allowed: bool) {}

fn set_ime_position(&self, _x: i32, _y: i32) {}
}

/// A IME action to be performed by some [`Command`].
///
/// [`Command`]: crate::Command
pub enum Action {
///
Allow(bool),

///
Position(i32, i32),
}

impl fmt::Debug for Action {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Action::Allow(_) => {
write!(f, "Action::Allow")
}
Action::Position(_, _) => write!(f, "Action::SetPosition"),
}
}
}
2 changes: 2 additions & 0 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod clipboard;
pub mod command;
pub mod event;
pub mod image;
pub mod ime;
pub mod keyboard;
pub mod layout;
pub mod mouse;
Expand Down Expand Up @@ -96,6 +97,7 @@ pub use debug::Debug;
pub use element::Element;
pub use event::Event;
pub use hasher::Hasher;
pub use ime::IME;
pub use layout::Layout;
pub use overlay::Overlay;
pub use program::Program;
Expand Down
3 changes: 2 additions & 1 deletion native/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub use element::Element;
pub use menu::Menu;

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

/// An interactive component that can be displayed on top of other widgets.
Expand Down Expand Up @@ -91,6 +91,7 @@ where
_cursor_position: Point,
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_ime: &dyn IME,
_shell: &mut Shell<'_, Message>,
) -> event::Status {
event::Status::Ignored
Expand Down
Loading

0 comments on commit 9c72c92

Please sign in to comment.