Skip to main content

slt/
context.rs

1//! `Context` — the per-frame handle threaded into every render closure.
2//!
3//! This file defines the [`Context`] struct itself plus the dispatching
4//! facade that imports widget impl blocks from the `widgets_display`,
5//! `widgets_input`, `widgets_interactive`, and `widgets_viz` sub-modules.
6//! See [`crate`] root for the entry-point [`crate::run`] / [`crate::frame`]
7//! functions and `docs/ARCHITECTURE.md` for the 5-layer model that
8//! organizes which method lives where.
9
10use crate::FrameState;
11use crate::chart::{Candle, ChartBuilder, HistogramBuilder, build_histogram_config, render_chart};
12use crate::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton, MouseKind};
13use crate::halfblock::HalfBlockImage;
14use crate::layout::{BeginContainerArgs, BeginScrollableArgs, Command, Direction};
15use crate::rect::Rect;
16use crate::style::{
17    Align, Border, BorderSides, Breakpoint, Color, Constraints, ContainerStyle, Justify, Margin,
18    Modifiers, Padding, Spacing, Style, Theme, ThemeColor, WidgetColors, WidgetTheme,
19};
20use crate::widgets::{
21    ApprovalAction, BreadcrumbResponse, ButtonVariant, CalDate, CalendarSelect, CalendarState,
22    ColorPickerState, CommandPaletteState, ContextItem, FilePickerState, FormField, FormState,
23    GaugeResponse, GridColumn, GutterResponse, HighlightRange, ListState, MultiSelectState,
24    NumberInputState, PaginatorState, PaginatorStyle, PickerMode, RadioState, SchedKind,
25    SchedulerSlot, SchedulerState, ScreenState, ScrollState, SelectState, SpinnerState,
26    SplitPaneResponse, SplitPaneState, StreamingTextState, TableState, TabsState, TextInputState,
27    TextareaState, ToastLevel, ToastState, ToolApprovalState, TreeState, ValidateTrigger,
28    color_hex_label, parse_hex_color,
29};
30use unicode_segmentation::UnicodeSegmentation;
31use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
32
33#[allow(dead_code)]
34fn slt_assert(condition: bool, msg: &str) {
35    if !condition {
36        panic!("[SLT] {}", msg);
37    }
38}
39
40#[cfg(debug_assertions)]
41#[allow(dead_code, clippy::print_stderr)]
42fn slt_warn(msg: &str) {
43    eprintln!("\x1b[33m[SLT warning]\x1b[0m {}", msg);
44}
45
46#[cfg(not(debug_assertions))]
47#[allow(dead_code)]
48fn slt_warn(_msg: &str) {}
49
50mod widgets_display;
51mod widgets_input;
52mod widgets_interactive;
53mod widgets_viz;
54pub use widgets_display::{Anchor, Breadcrumb, CodeBlock, Gauge, GutterOpts, LineGauge};
55pub use widgets_viz::TreemapItem;
56
57mod state;
58pub use state::*;
59
60mod bars;
61pub use bars::*;
62
63mod widget;
64pub use widget::*;
65
66mod core;
67pub use core::*;
68
69mod container;
70pub use container::*;
71
72mod runtime;
73
74/// Issue #234: in-frame async task API (`spawn`/`poll`), gated behind `async`.
75#[cfg(feature = "async")]
76mod async_tasks;
77#[cfg(feature = "async")]
78pub(crate) use async_tasks::AsyncTasks;
79#[cfg(feature = "async")]
80#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
81pub use async_tasks::TaskHandle;
82
83mod helpers;
84pub(crate) use helpers::*;
85
86#[cfg(all(test, feature = "async"))]
87mod async_tasks_tests;
88
89#[cfg(test)]
90mod tests;
91
92#[cfg(test)]
93mod scheduler_tests;