Expand description
Newt — design canvas compiler and live renderer.
Parses .newt UI source, builds a layout tree, and renders to a wgpu canvas.
Re-exports§
pub use ast::ImportDecl;pub use ast::Program;pub use ast::ProgramItem;pub use ast::ScreenDecl;pub use ast::ThemeDecl;pub use error::format_error;pub use error::NewtError;pub use error::Source;pub use error::Span;pub use html::layout_to_html;pub use html::layout_to_reactive_html;pub use react::layout_to_react;pub use layout::layout_tree;pub use layout::LayoutNode;pub use layout::Rect;pub use lexer::TokenCategory;pub use lexer::TokenKind;pub use parser::Parser;pub use app::App;pub use value::EvalContext;pub use value::Value;pub use value::value_to_json;
Modules§
- app
- Application loop: winit window, file watch, and render.
- ast
- Abstract Syntax Tree for the Newt UI language.
- error
- Error types and source span handling for the Newt compiler.
- html
- Export layout to standalone HTML so you can open it in a browser (no GPU needed).
- layout
- Flex-like layout engine: computes bounds for each element from the AST.
- lexer
- Lexer for the Newt UI language.
- parser
- Recursive descent parser for the Newt UI language.
- react
- Generate React JSX from the Newt layout tree.
- renderer
- wgpu-based 2D canvas renderer for layout nodes.
- serve
- Canvas IDE server: HTTP + WebSocket for live-reload canvas.
- value
- Runtime values for the Newt interpreter (used during layout).
Enums§
- Symbol
Kind - Symbol kind for LSP (hover, completion, go-to-definition).
Constants§
- DEFAULT_
SERVE_ PORT - Default port for the canvas IDE server.
- DEFAULT_
VIEWPORT_ H - DEFAULT_
VIEWPORT_ W - Default viewport size for IDE and export (width, height).
Functions§
- check_
all - Collect all parse errors from the source. Returns an empty vec on success. Designed for LSP use where all diagnostics should appear at once.
- compile
- Single compile entry: parse → resolve_imports (when path is set) → EvalContext → get_screen → layout_tree. Use this from CLI, serve, LSP, and app so behavior and diagnostics are consistent. Viewport is (0, 0, DEFAULT_VIEWPORT_W, DEFAULT_VIEWPORT_H) unless overridden later by the consumer.
- compile_
with_ state - Like
compile()but accepts state overrides and returns the effective state. State overrides are applied to variables matchingstatedeclarations in the program. - completion_
element_ names - Element names for completion (row, column, card, button, etc.).
- completion_
keywords - Keywords for completion (top-level and expression context).
- completion_
prop_ names - Prop names valid for elements (layout, style, content).
- get_
screen - Get a screen by name. If
nameis None, returns the first screen. Use for multi-screen apps: Home, Dashboard, Settings, etc. - has_
state_ vars - Returns true if the program contains any
statedeclarations. - parse
- Parse source code into an AST.
Returns the first error for backward compatibility. Use
parse_allfor all errors. - parse_
all - Parse source code, returning all errors at once instead of stopping at the first.
- parse_
file - Parse a file into an AST.
- resolve_
imports - Resolve all
import "path.newt"declarations by loading and merging those files. Avoids circular imports.base_diris the directory of the current file. - screen_
names - All screen names in the program (order preserved).
- symbol_
table - Build a symbol table from a program: name → (span, kind). Later definitions shadow earlier.
- theme_
css_ vars - Collect color variables from the program for CSS export (:root { –name: #hex; }).
- tokenize
- Tokenize source for syntax highlighting. Returns (span, category) for each token until Eof.