commit 9b03d878573d85bec88905adda4375d2077b380f
parent 2e7c482b15ce6e24fc80e3e2e12aec25024ac581
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date: Sat, 27 Feb 2021 16:47:21 +0800
ux: display summarised details in ticket card
Diffstat:
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/cmd/kanban/widgets.go b/cmd/kanban/widgets.go
@@ -209,9 +209,9 @@ type Ticket struct {
// Layout the ticket card.
//
// The layouting here was actually quite tricky because `layout.List` simulates
-// an infinite Y axis. That means you can just specify a max Y constraint. This
-// makes expanding stacked content vertically impossible with a naive use of
-// `layout.Stack`.
+// an infinite Y axis. That means you can't just specify a max Y constraint.
+// This makes expanding stacked content vertically impossible with a naive use
+// of `layout.Stack`.
//
// To get around this I used a macro and manually stacked things sized exactly
// to the content, rather than the maximum Y.
@@ -270,6 +270,8 @@ func (t *Ticket) Layout(gtx C, th *material.Theme, focused bool) D {
})
}
+// @todo: de-emphasize details content.
+// @todo: summarize based on card size rather than content length.
func (t *Ticket) content(gtx C, th *material.Theme) D {
macro := op.Record(gtx.Ops)
dims := layout.Inset{
@@ -290,6 +292,11 @@ func (t *Ticket) content(gtx C, th *material.Theme) D {
return material.Body1(th, t.Summary).Layout(gtx)
})
}),
+ layout.Rigid(func(gtx C) D {
+ return layout.Inset{Top: unit.Dp(10)}.Layout(gtx, func(gtx C) D {
+ return material.Body1(th, summarize(t.Details, 0)).Layout(gtx)
+ })
+ }),
)
})
call := macro.Stop()
@@ -461,3 +468,15 @@ func (t *TicketDetails) Layout(gtx C, th *material.Theme) D {
}),
)
}
+
+// summarize truncates string s after n amount of characters, and appends an
+// elipsis to indicate missing content.
+func summarize(s string, n int) string {
+ if n == 0 {
+ n = 70
+ }
+ if len(s) < n {
+ return s
+ }
+ return strings.TrimSpace(s[:n]) + string('\u2026')
+}