From 10b99f3ffb8d50e45d86001b6f900cf203235030 Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 15 Aug 2019 09:32:39 -0400 Subject: [PATCH] Update docs. --- README.md | 27 +++++++++++++++++++++++++++ cmd/hello/main.go | 4 ++-- main.go | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5133b12..126bb5c 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,30 @@ type Enclosure interface { func Enclose(e Enclosure, w ...Widget) Widget { ... } ``` + +The `Context` struct also contains a `map[string]interface{}` allowing arbitrary +data to be maintained. This can be used, for example, to define themes, and control +the operation of a `WidgetCombinator` during operation. For example> + +```go +type fWidget struct { l Layout } +func NewfWidget(l layout) fWidget { return fWidget{ l: l } } + +func (f Flex) Flexible(v float32) Widget { + return NewfWidget(func(ctx Context) Context { + ctx.extra["Flexible"] = v + return ctx + }) +} + +... + ctx = giowrap.LayoutWithContext(ctx, + myFlex( + w1, + giowrap.Flexible(0.5), + w2, + giowrap.Flexible(1), + w3, + )) +... +``` diff --git a/cmd/hello/main.go b/cmd/hello/main.go index 52cbdc3..7eb3e94 100644 --- a/cmd/hello/main.go +++ b/cmd/hello/main.go @@ -57,9 +57,9 @@ func main() { OuterInset( f( e1, - f.Flexible(5), + giowrap.Flexible(5), InnerInset(e2), - f.Flexible(10), + giowrap.Flexible(10), btn, ))) ctx.Draw() diff --git a/main.go b/main.go index 3ebbd9e..5da3546 100644 --- a/main.go +++ b/main.go @@ -149,7 +149,7 @@ type FlexChild struct { type Flex WidgetCombinator -func (f Flex) Flexible(v float32) Widget { +func Flexible(v float32) Widget { return NewfWidget(func(ctx Context) Context { ctx.extra["Flexible"] = v return ctx