forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FontConfig.go
140 lines (120 loc) · 4.91 KB
/
FontConfig.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package imgui
// #include "wrapper/FontConfig.h"
import "C"
// FontConfig describes properties of a single font.
type FontConfig uintptr
// DefaultFontConfig lets ImGui take default properties as per implementation.
// The properties of the default configuration cannot be changed using the SetXXX functions.
const DefaultFontConfig FontConfig = 0
func (config FontConfig) handle() C.IggFontConfig {
return C.IggFontConfig(config)
}
// NewFontConfig creates a new font configuration.
// Delete must be called on the returned config.
func NewFontConfig() FontConfig {
configHandle := C.iggNewFontConfig()
return FontConfig(configHandle)
}
// Delete removes the font configuration and resets it to the DefaultFontConfig.
func (config *FontConfig) Delete() {
if *config != DefaultFontConfig {
C.iggFontConfigDelete(config.handle())
*config = DefaultFontConfig
}
}
// SetSize sets the size in pixels for rasterizer (more or less maps to the
// resulting font height).
func (config FontConfig) SetSize(sizePixels float32) {
if config != DefaultFontConfig {
C.iggFontConfigSetSize(config.handle(), C.float(sizePixels))
}
}
// SetOversampleH sets the oversampling amount for the X axis.
// Rasterize at higher quality for sub-pixel positioning.
// We don't use sub-pixel positions on the Y axis.
func (config FontConfig) SetOversampleH(value int) {
if config != DefaultFontConfig {
C.iggFontConfigSetOversampleH(config.handle(), C.int(value))
}
}
// SetOversampleV sets the oversampling amount for the Y axis.
// Rasterize at higher quality for sub-pixel positioning.
// We don't use sub-pixel positions on the Y axis.
func (config FontConfig) SetOversampleV(value int) {
if config != DefaultFontConfig {
C.iggFontConfigSetOversampleV(config.handle(), C.int(value))
}
}
// SetPixelSnapH aligns every glyph to pixel boundary if enabled. Useful e.g. if
// you are merging a non-pixel aligned font with the default font. If enabled,
// you can set OversampleH/V to 1.
func (config FontConfig) SetPixelSnapH(value bool) {
if config != DefaultFontConfig {
C.iggFontConfigSetPixelSnapH(config.handle(), castBool(value))
}
}
// SetGlyphMinAdvanceX sets the minimum AdvanceX for glyphs.
// Set Min to align font icons, set both Min/Max to enforce mono-space font.
func (config FontConfig) SetGlyphMinAdvanceX(value float32) {
if config != DefaultFontConfig {
C.iggFontConfigSetGlyphMinAdvanceX(config.handle(), C.float(value))
}
}
// SetGlyphMaxAdvanceX sets the maximum AdvanceX for glyphs.
// Set both Min/Max to enforce mono-space font.
func (config FontConfig) SetGlyphMaxAdvanceX(value float32) {
if config != DefaultFontConfig {
C.iggFontConfigSetGlyphMaxAdvanceX(config.handle(), C.float(value))
}
}
// SetGlyphOffsetX sets the horizontal offset for all glyphs. Positive values
// adjust the glyph to the right and negative values adjust the glyph to the
// left.
func (config FontConfig) SetGlyphOffsetX(value float32) {
if config != DefaultFontConfig {
C.iggFontConfigSetGlyphOffsetX(config.handle(), C.float(value))
}
}
// SetGlyphOffsetY sets the vertical offset for all glyphs. Positive values
// adjust the glyph downward and negative value adjust the glyph upward.
func (config FontConfig) SetGlyphOffsetY(value float32) {
if config != DefaultFontConfig {
C.iggFontConfigSetGlyphOffsetY(config.handle(), C.float(value))
}
}
// SetMergeMode merges the new fonts into the previous font if enabled. This way
// you can combine multiple input fonts into one (e.g. ASCII font + icons +
// Japanese glyphs). You may want to use GlyphOffset.y when merge font of
// different heights.
func (config FontConfig) SetMergeMode(value bool) {
if config != DefaultFontConfig {
C.iggFontConfigSetMergeMode(config.handle(), castBool(value))
}
}
// SetName sets a short display name for a font, for diagnostic purposes.
// If the FontConfig does not provide a name, one will be synthesized for
// fonts which are added from files. When adding fonts from memory, this
// method can be used to provide a name.
// The name will be truncated if it is longer than the limit supported by imgui.
func (config FontConfig) SetName(name string) {
if config != DefaultFontConfig {
nameArg, nameFin := wrapString(name)
defer nameFin()
C.iggFontConfigSetName(config.handle(), nameArg)
}
}
// getFontDataOwnedByAtlas gets the current ownership status of the font data.
func (config FontConfig) getFontDataOwnedByAtlas() bool {
if config != DefaultFontConfig {
return C.iggFontConfigGetFontDataOwnedByAtlas(config.handle()) != 0
}
return true
}
// FontBuilderFlags returns settings for custom font builder.
func (config FontConfig) FontBuilderFlags() uint {
return uint(C.iggFontConfigGetFontBuilderFlags(config.handle()))
}
// SetFontBuilderFlags sets settings for custom font builder. THIS IS BUILDER IMPLEMENTATION DEPENDENT. Leave as zero if unsure.
func (config FontConfig) SetFontBuilderFlags(flags uint) {
C.iggFontConfigSetFontBuilderFlags(config.handle(), C.uint(flags))
}