page_builder
page_builder
#
PageBuilder — a function that builds components becomes a function returning a Page.
- Calling the decorated function opens a
Build, then builds and opens a freshVStackas the root, so every component the body constructs attaches to the innermost open stack, the way procedure nodes attach to the recording context under@cg.procedure. - When the body returns, the root and the title a
Titleset become thePagethe wrapper returns; the wrapper is annotated to returnPage, so@cgserver.pageand@cg.pure_functionaccept it as they would a hand-written page function.
PageBuilder
#
Decorate a component-building function into one that returns its Page.
The body constructs components in document order; with on an
HStack or VStack nests them; Title names the page. The body
returns nothing.
@cg.ui.PageBuilder()
def overview(session: Session) -> None:
cg.ui.Title(session.captured.date().isoformat())
cg.ui.ImageViewer(session.photo)
with cg.ui.HStack():
cg.ui.Stat("Width", session.photo.width, unit="px")
cg.ui.Stat("Height", session.photo.height, unit="px")
page = overview(session)
Source code in capturegraph-lib/capturegraph/ui/page_builder.py
__call__(func)
#
func wrapped to return the page its body built.