~gioverse/chat

ref: c86e075f0df33cc01ac99f167a09f981997727d0 chat/debug/debug.go -rw-r--r-- 657 bytes
c86e075fChris Waldon debug: add function to easily log structures 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Package debug provides tools for debugging Gio layout code.
*/
package debug

import (
	"bytes"
	"encoding/json"
	"image/color"
	"io"
	"os"

	"gioui.org/layout"
	"gioui.org/unit"
	"gioui.org/widget"
)

type (
	C = layout.Context
	D = layout.Dimensions
)

// Outline traces a small black outline around the provided widget.
func Outline(gtx C, w func(gtx C) D) D {
	return widget.Border{
		Color: color.NRGBA{A: 255},
		Width: unit.Dp(1),
	}.Layout(gtx, w)
}

// Dump logs the input as formatting JSON on stderr.
func Dump(v interface{}) {
	b, _ := json.MarshalIndent(v, "", "  ")
	b = append(b, []byte("\n")...)
	io.Copy(os.Stderr, bytes.NewBuffer(b))
}