add background for F3 text, fix single-channel texture display

This commit is contained in:
2022-02-10 21:13:55 +08:00
parent a17a43505c
commit a628fdb434
7 changed files with 44 additions and 11 deletions

View File

@@ -21,6 +21,20 @@ func Text(format string, a ...interface{}) {
imgui.Text(fmt.Sprintf(format, a...))
}
// TextBackground wraps imgui.Text to create a
// shortcut for fmt.Sprintf.
//
// It also fills the background of the text with the given color.
func TextBackground(color itype.Vec4f, 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.Text(text)
}
// Begin wraps imgui.BeginV to create a
// easy-to-use and intuitive interface.
//