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::chart::{build_histogram_config, render_chart, Candle, ChartBuilder, HistogramBuilder};
11use crate::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton, MouseKind};
12use crate::halfblock::HalfBlockImage;
13use crate::layout::{BeginContainerArgs, BeginScrollableArgs, Command, Direction};
14use crate::rect::Rect;
15use crate::style::{
16    Align, Border, BorderSides, Breakpoint, Color, Constraints, ContainerStyle, Justify, Margin,
17    Modifiers, Padding, Spacing, Style, Theme, ThemeColor, WidgetColors, WidgetTheme,
18};
19use crate::widgets::{
20    color_hex_label, parse_hex_color, ApprovalAction, BreadcrumbResponse, ButtonVariant, CalDate,
21    CalendarSelect, CalendarState, ColorPickerState, CommandPaletteState, ContextItem,
22    FilePickerState, FormField, FormState, GaugeResponse, GridColumn, GutterResponse,
23    HighlightRange, ListState, MultiSelectState, NumberInputState, PaginatorState, PaginatorStyle,
24    PickerMode, RadioState, SchedKind, SchedulerSlot, SchedulerState, ScreenState, ScrollState,
25    SelectState, SpinnerState, SplitPaneResponse, SplitPaneState, StreamingTextState, TableState,
26    TabsState, TextInputState, TextareaState, ToastLevel, ToastState, ToolApprovalState, TreeState,
27    ValidateTrigger,
28};
29use crate::FrameState;
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")]
80pub use async_tasks::TaskHandle;
81
82mod helpers;
83pub(crate) use helpers::*;
84
85#[cfg(all(test, feature = "async"))]
86mod async_tasks_tests;
87
88#[cfg(test)]
89mod tests;
90
91#[cfg(test)]
92mod scheduler_tests;