API ReferenceText & Media
TextSelection
Caret and range selection with affinity and clamping.
use incular::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let selection = TextSelection::new(0, 5);
let caret = TextSelection::collapsed(5);
let app = Application::new(move |_cx| {
Container::builder()
.padding(EdgeInsets::all(24.0))
.alignment(Alignment::CENTER)
.child(Text::new(format!(
"range {}..{}, collapsed: {}",
selection.start(),
selection.end(),
caret.is_collapsed()
)))
.build()
.into()
})?;
incular::run(app)?;
Ok(())
}| Member | Kind | Notes |
|---|---|---|
new(base, extent) | Constructor | Anchor + focus ends |
collapsed(offset) | Constructor | Caret with no range |
start() / end() | Accessor | Ordered ends |
is_collapsed() | Query | Base equals extent |
is_forward() | Query | Extent after base |
range() | Conversion | As TextRange |
clamp_to(text) | Normalization | Snap to char boundaries |
TextRange { start, end }: EMPTY, new, collapsed, is_collapsed,
is_valid, len, is_empty, as_range, clamp_to, normalized.
TextAffinity: Downstream (default) / Upstream.
ComposingRange = TextRange.
Drive the controller with controller.set_selection(TextSelection::new(0, 5))
or controller.set_selection_with_affinity(sel, TextAffinity::Upstream).
Related: TextEditingController.