segmented render time display

This commit is contained in:
2022-02-22 14:28:35 +08:00
parent e2717aaaa9
commit 3595c32ae5
3 changed files with 63 additions and 3 deletions

@ -1,6 +1,8 @@
package igwrap
import (
"math"
"edgaru089.ml/go/gl01/internal/util/itype"
"github.com/inkyblackness/imgui-go/v4"
)
@ -20,6 +22,17 @@ func PackedColor(color itype.Vec4f) imgui.PackedColor {
return imgui.PackedColorFromVec4(Vec4(color))
}
// UnpackedColor unpacks a color to RGBA.
func UnpackedColor(color imgui.PackedColor) itype.Vec4f {
r, g, b, a := color.RGBA()
return itype.Vec4f{
float32(r) / float32(math.MaxUint32),
float32(g) / float32(math.MaxUint32),
float32(b) / float32(math.MaxUint32),
float32(a) / float32(math.MaxUint32),
}
}
// Vec2 converts itype.Vec2f to imgui.Vec2.
func Vec2(v itype.Vec2f) imgui.Vec2 {
return imgui.Vec2{X: v[0], Y: v[1]}

@ -30,18 +30,18 @@ func Text(format string, a ...interface{}) {
// It also fills the background of the text with half-transparant black, and takes care of the padding.
func TextBackground(format string, a ...interface{}) {
pad := Vec2f(imgui.CurrentStyle().ItemSpacing())
TextBackgroundV(itype.Vec4f{0, 0, 0, 0.5}, pad, format, a...)
TextBackgroundV(PackedColor(itype.Vec4f{0, 0, 0, 0.5}), pad, format, a...)
}
// TextBackgroundV wraps imgui.Text to create a shortcut for fmt.Sprintf.
//
// It also fills the background of the text with the given color.
func TextBackgroundV(color itype.Vec4f, padding itype.Vec2f, format string, a ...interface{}) {
func TextBackgroundV(color imgui.PackedColor, padding itype.Vec2f, format string, a ...interface{}) {
text := fmt.Sprintf(format, a...)
orig := imgui.CursorScreenPos()
size := imgui.CalcTextSize(text, false, 0)
halfpad := padding.Multiply(0.5)
imgui.BackgroundDrawList().AddRectFilledV(orig.Minus(Vec2(halfpad)), orig.Plus(size).Plus(Vec2(halfpad)), PackedColor(color), 0, 0)
imgui.BackgroundDrawList().AddRectFilledV(orig.Minus(Vec2(halfpad)), orig.Plus(size).Plus(Vec2(halfpad)), color, 0, 0)
imgui.Text(text)
}