pub struct UiContext {
pub appearance: Appearance,
pub charset: Charset,
pub graphics: Graphics,
pub jamo_width: JamoWidth,
pub theme: Theme,
pub elements: Elements,
pub now: Duration,
pub revision: u64,
pub loader: Option<ImageLoader>,
}Expand description
Presentation context threaded through parse, layout, and paint.
Fields§
§appearance: AppearanceTerminal-reported dark or light background appearance.
charset: CharsetGlyph capability tier.
graphics: GraphicsTerminal image rendering capability.
jamo_width: JamoWidthHangul Compatibility Jamo width policy.
Prefer UiContext::set_jamo_width over direct assignment: the method
also updates the process-wide hot-path setting and invalidates width
caches.
theme: ThemeSemantic color palette.
elements: ElementsCustom element registry.
now: DurationPresentation clock of the pass in flight: crate::Ui::tick advances
it so size transitions can be sampled during layout, where no
crate::PaintCtx exists. Excluded from equality — a moving clock
must never read as a context change.
revision: u64Cache-invalidation revision, advanced by crate::Ui::set_context
when a differing context is applied. Geometry and render memos fold
it into their keys so output derived from the previous context is
discarded. Excluded from equality, like the clock.
loader: Option<ImageLoader>Off-thread image decoder. None decodes inline during layout for
deterministic tests and bare synchronous hosts. crate::App installs
one before building the crate::Ui.
Implementations§
Source§impl UiContext
impl UiContext
Sourcepub fn set_jamo_width(&mut self, width: JamoWidth) -> bool
pub fn set_jamo_width(&mut self, width: JamoWidth) -> bool
Applies a Hangul Compatibility Jamo policy process-wide.
Returns whether the effective configuration changed. Width-derived
caches observe that change through [crate::rich::width_config_epoch].
Sourcepub fn apply_terminal_caps(&mut self, caps: &TerminalCaps) -> bool
pub fn apply_terminal_caps(&mut self, caps: &TerminalCaps) -> bool
Applies the detected terminal’s capabilities: graphics tier, glyph charset, Compatibility Jamo policy, and background appearance.
Capability values are 0 for platform default, 1 for narrow, and 2
for wide.
Sourcepub fn with_terminal_caps(self, caps: &TerminalCaps) -> Self
pub fn with_terminal_caps(self, caps: &TerminalCaps) -> Self
Returns this context configured for the detected terminal.
Examples found in repository?
53async fn main() -> io::Result<()> {
54 let caps = detect();
55 let charset = UiContext::default().with_terminal_caps(&caps).charset;
56 let mut terminal = Terminal::enter(TerminalOptions::new(caps).mouse(true))?;
57 let mut renderer = Renderer::new(TtyOut::new()?);
58 renderer.apply_caps(&caps)?;
59 match run(&mut terminal, &mut renderer, charset).await {
60 Ok(()) => terminal.leave_alt(),
61 Err(error) => {
62 let _ = terminal.leave_alt();
63 Err(error)
64 },
65 }
66}More examples
Trait Implementations§
impl Eq for UiContext
Auto Trait Implementations§
impl !RefUnwindSafe for UiContext
impl !UnwindSafe for UiContext
impl Freeze for UiContext
impl Send for UiContext
impl Sync for UiContext
impl Unpin for UiContext
impl UnsafeUnpin for UiContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more