Skip to content

hi, i had some issue for render text on the screen #1746

Answered by ModNope
ChrisChou-freeman asked this question in Q&A
Discussion options

You must be logged in to vote

Drawing glyphs of the font starts from the bottom corner. If you do not take into account the size of the glyph, then at coordinates 0,0 the glyph will be off-screen at the top.


After adding a vertical offset, the text will be below the screen border.

To account for the offset, there is a function that reports the length and width of the text with the selected font.

Bound := BoundString(Font, Text)
// bound is image.Rectangle{}
// For get x, y length, use .Dx(), and .Dy()
// https://pkg.go.dev/image#Rectangle

If you need to display texts with different fonts in 1 zone at a fixed size, use 1 font as the standard size.

var(
	Default := // default font
	StandardZoneSize := BoundString(Default

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ChrisChou-freeman
Comment options

@ModNope
Comment options

@ChrisChou-freeman
Comment options

Answer selected by ChrisChou-freeman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants