Add debug package
This commit is contained in:
parent
de12ee6bcd
commit
76bd2837d3
28
debug/debug.go
Normal file
28
debug/debug.go
Normal file
@ -0,0 +1,28 @@
|
||||
package debug
|
||||
|
||||
import "image/draw"
|
||||
import "image/color"
|
||||
import "golang.org/x/image/math/fixed"
|
||||
import "git.tebibyte.media/tomo/typeset"
|
||||
import "git.tebibyte.media/tomo/typeset/internal"
|
||||
|
||||
// DrawBounds draws the LayoutBounds, MinimumSize, and LayoutBoundsSpace of a
|
||||
// TypeSetter to the given image using these colors:
|
||||
// - Red: LayoutBounds
|
||||
// - Green: MinimumSize
|
||||
// - Blue: LayoutBoundsSpace
|
||||
func DrawBounds (destination draw.Image, setter *typeset.TypeSetter, offset fixed.Point26_6) {
|
||||
blue := color.RGBA { B: 255, A: 255 }
|
||||
red := color.RGBA { R: 255, A: 255 }
|
||||
green := color.RGBA { G: 255, A: 255 }
|
||||
|
||||
layoutBoundsSpace := setter.LayoutBoundsSpace()
|
||||
layoutBounds := setter.LayoutBounds()
|
||||
|
||||
minimum := setter.MinimumSize()
|
||||
minimumRect := internal.RoundRect(fixed.Rectangle26_6 { Max: minimum }.Add(offset).Add(layoutBounds.Min))
|
||||
internal.DrawRectangleOutline(destination, minimumRect, green)
|
||||
|
||||
internal.DrawRectangleOutline(destination, internal.RoundRect(layoutBoundsSpace.Add(offset)), blue)
|
||||
internal.DrawRectangleOutline(destination, internal.RoundRect(layoutBounds.Add(offset)), red)
|
||||
}
|
21
draw.go
21
draw.go
@ -50,27 +50,6 @@ func Draw (destination draw.Image, setter *TypeSetter, offset fixed.Point26_6, c
|
||||
return updatedRegion
|
||||
}
|
||||
|
||||
// DrawBounds draws the LayoutBounds, MinimumSize, and LayoutBoundsSpace of a
|
||||
// TypeSetter to the given image using these colors:
|
||||
// - Red: LayoutBounds
|
||||
// - Green: MinimumSize
|
||||
// - Blue: LayoutBoundsSpace
|
||||
func DrawBounds (destination draw.Image, setter *TypeSetter, offset fixed.Point26_6) {
|
||||
blue := color.RGBA { B: 255, A: 255 }
|
||||
red := color.RGBA { R: 255, A: 255 }
|
||||
green := color.RGBA { G: 255, A: 255 }
|
||||
|
||||
layoutBoundsSpace := setter.LayoutBoundsSpace()
|
||||
layoutBounds := setter.LayoutBounds()
|
||||
|
||||
minimum := setter.MinimumSize()
|
||||
minimumRect := internal.RoundRect(fixed.Rectangle26_6 { Max: minimum }.Add(offset).Add(layoutBounds.Min))
|
||||
internal.DrawRectangleOutline(destination, minimumRect, green)
|
||||
|
||||
internal.DrawRectangleOutline(destination, internal.RoundRect(layoutBoundsSpace.Add(offset)), blue)
|
||||
internal.DrawRectangleOutline(destination, internal.RoundRect(layoutBounds.Add(offset)), red)
|
||||
}
|
||||
|
||||
func drawTofu (
|
||||
char rune,
|
||||
destination draw.Image,
|
||||
|
@ -9,6 +9,7 @@ import "image/color"
|
||||
import "golang.org/x/image/math/fixed"
|
||||
import "git.tebibyte.media/tomo/typeset"
|
||||
import "golang.org/x/image/font/basicfont"
|
||||
import "git.tebibyte.media/tomo/typeset/debug"
|
||||
|
||||
func main () {
|
||||
img := image.NewRGBA(image.Rect(0, 0, 2048, 1024))
|
||||
@ -122,7 +123,7 @@ func drawText (destination subDrawImage, setter *typeset.TypeSetter, bounds imag
|
||||
Y: metrics.Ascent + fixed.I(bounds.Min.Y),
|
||||
}
|
||||
// typeset.Draw(destination, setter, offset, color.Black)
|
||||
typeset.DrawBounds(subImage, setter, offset)
|
||||
debug.DrawBounds(subImage, setter, offset)
|
||||
typeset.Draw(subImage, setter, offset, color.Black)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user