ui
ui
#
cg.ui — the components a cg.Page is built from, each rendering itself to HTML.
- Build. A page function under
@PageBuilder()constructs components —Componentsubclasses whose annotated fields are their props — in document order; each attaches to the innermost open stack,withon aVStackorHStacknests them, andTitlenames the page. The standard vocabulary:VStackandHStacklay out,DividerandPaddingseparate;MarkdownandStatshow words and figures;ImageViewer,Gallery,TimelapseandSplatViewershow captured or reconstructed files;Scatterplots columns against each other,Chartdraws a specification in full andMapViewermaps;PageLinkleads to the page of another value. The viewers areImageViewer,SplatViewerandMapViewerrather thanImage,SplatandMapbecause those names belong to thecgtypes they display. A suite declares its own by subclassingComponentand implementinghtml. - Render. When the page is built, each component writes its HTML through
one
Rendercontext: files it shows are staged underfiles/and browser libraries it needs underlib/. A link is aPageLinkor anofentry, nothing else:PageLink(value)leads to the page of a value loaded from the target,Gallery.of,Timelapse.ofandMapViewer.oflink each derived item to its container entry, and a plain value renders with no link.
@cg.ui.PageBuilder()
def courtyard(target: Courtyard) -> None:
cg.ui.Title("Courtyard")
cg.ui.Markdown("# Courtyard")
with cg.ui.HStack():
cg.ui.Stat("Sessions", 12)
cg.ui.Stat("Coverage", 0.8)
cg.ui.Timelapse.of(target.sessions, lambda s: s.photo)
cg.ui.PageLink(target.sessions.values()[-1], title="Latest session")