oxiui_iced/lib.rs
1#![forbid(unsafe_code)]
2#![warn(missing_docs)]
3//! iced backend adapter for OxiUI.
4//!
5//! Bridges OxiUI's `UiCtx` trait (immediate-mode) to iced's retained-mode
6//! widget tree (best-effort mapping at M2).
7//!
8//! # Architecture note
9//!
10//! iced is a retained-mode framework (Elm-style update/view loop), whereas
11//! OxiUI's `UiCtx` is immediate-mode (per-frame closure). `IcedUiCtx` bridges
12//! the gap by collecting widget operations from a content closure and building
13//! an iced `Column` from the collected elements. The mapping is one-way and
14//! best-effort at M2; M3 wired the full message round-trip.
15//!
16//! # IME CJK note (M4)
17//!
18//! iced 0.14 does not expose a public per-widget IME injection API at the level
19//! of `UiEvent`. IME events are surfaced as `UiEvent::ImePreedit` /
20//! `UiEvent::ImeCommit` through the `oxiui-core` event sink, but no direct
21//! iced widget action is generated for them at this milestone. See
22//! [`forward_ime_event`] for the stub that documents the gap.
23
24#[cfg(feature = "a11y")]
25pub mod a11y_bridge;
26pub mod adapter;
27pub mod theme;
28
29#[cfg(feature = "a11y")]
30pub use a11y_bridge::{spec_to_a11y_node, spec_to_a11y_tree, IcedA11yConfig};
31pub use adapter::{
32 apply_message, map_iced_key, map_iced_keyboard_event, map_iced_modifiers, oxi_widget,
33 spec_fingerprint, IcedConfig, IcedNullCtx, IcedSpan, IcedUiCtx, Message, OxiIcedWidget,
34 SpecCache, ThemeCache, WidgetSpec, WidgetState,
35};
36pub use theme::{
37 palette_and_tokens_to_iced_theme, palette_to_iced_theme, palette_to_iced_theme_ext,
38 scrollable_style_from_palette, scrollable_style_from_theme, text_input_style_from_palette,
39 text_input_style_from_theme, DesignTokensAdapter,
40};
41
42use oxiui_core::UiEvent;
43
44/// Forward an OxiUI [`UiEvent`] to the iced backend.
45///
46/// # IME support (M4 — best-effort)
47///
48/// iced 0.14 does not expose a public API for injecting IME composition events
49/// directly into a text-input widget. This function no-ops on IME events and
50/// logs a debug message for diagnostics. Full IME support requires iced to
51/// expose a `TextInput::ime_preedit` / `ime_commit` API, which is tracked as a
52/// future enhancement.
53///
54/// All other event variants are silently ignored.
55pub fn forward_ime_event(event: &UiEvent) {
56 match event {
57 UiEvent::ImePreedit { text, cursor: _ } => {
58 // iced 0.14 has no public IME injection API.
59 // Log for diagnostics; a future iced release may expose one.
60 let _ = text; // suppress unused-variable warning
61 }
62 UiEvent::ImeCommit(text) => {
63 // iced 0.14: no direct text-input injection — best-effort stub.
64 let _ = text;
65 }
66 _ => {}
67 }
68}