Skip to main content

dear_imgui_cte/
lib.rs

1//! Preview, context-bound ImGuiColorTextEdit bindings through cimCTE.
2//!
3//! Persistent [`TextEditor`] and [`TextDiff`] values are created from a
4//! [`dear_imgui_rs::Context`] and rendered through [`CteUiExt`] on that same Context.
5//! This fragment assumes an attached managed renderer and platform frame setup;
6//! see `examples/03-features/cte_minimal.rs` for a runnable application:
7//!
8//! ```no_run
9//! use dear_imgui_cte::{CteUiExt, Language, TextEditor};
10//! use dear_imgui_rs::Context;
11//!
12//! # fn main() -> Result<(), dear_imgui_cte::CteError> {
13//! let mut imgui = Context::create();
14//! let mut editor = TextEditor::try_create(&imgui)?;
15//! editor.set_text("int main() { return 0; }\n")?;
16//! editor.set_language(Some(Language::Cpp));
17//!
18//! let ui = imgui.frame();
19//! ui.text_editor(&mut editor, "Source")
20//!     .size([640.0, 480.0])
21//!     .build()?;
22//! # Ok(())
23//! # }
24//! ```
25//!
26//! Native owners are neither [`Send`] nor [`Sync`]. Rendering with a `Ui` from another Context is
27//! rejected before FFI, and applications should drop every CTE owner before its Context. If the
28//! Context has already died, Drop deliberately leaks the native handle rather than dereferencing
29//! invalid native state.
30//!
31//! Stateful callbacks are owned by their editor. Reentering the same mutable callback skips the
32//! nested invocation; text filters validate a complete batch before mutation. A callback panic is
33//! diagnosed and aborts rather than unwinding through native C++ frames. Trie autocomplete uses
34//! upstream-exclusive callback slots, so conflicts are reported instead of silently replacing
35//! user callbacks.
36//!
37//! Add [`dejavu_font_source`] to the managed font atlas before renderer initialization. Do not use
38//! the raw cimCTE `SetDejavu` helper from safe integrations: it clears the complete atlas and
39//! changes its loader outside renderer texture management.
40
41mod autocomplete;
42mod callbacks;
43mod context;
44mod error;
45mod font;
46mod language;
47mod palette;
48mod text_diff;
49mod text_editor;
50mod types;
51mod ui;
52mod validation;
53
54pub use autocomplete::{
55    AutocompleteConfig, AutocompleteContext, AutocompleteRequest, TrieAutocomplete,
56};
57pub use callbacks::{
58    CaretEvent, DecoratorEvent, LineNumberEvent, PopupEvent, TextChange, TextChangeKind,
59};
60pub use error::{CteError, CteResult};
61pub use font::{dejavu_font_source, noto_sans_sc_font_source};
62pub use language::Language;
63pub use palette::{Palette, PaletteColor};
64pub use text_diff::{TextDiff, TextDiffRenderer};
65pub use text_editor::{TextEditor, TextEditorRenderer};
66pub use types::{
67    MiddleMouseMode, Position, ScrollAlignment, SearchOptions, Selection, SquiggleKind,
68    SquiggleStyle, VisualPosition,
69};
70pub use ui::CteUiExt;
71
72pub(crate) use dear_imgui_cte_sys as sys;