FontConfig.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package imgui
  2. // #include "FontConfigWrapper.h"
  3. import "C"
  4. // FontConfig describes properties of a single font.
  5. type FontConfig uintptr
  6. // DefaultFontConfig lets ImGui take default properties as per implementation.
  7. // The properties of the default configuration cannot be changed using the SetXXX functions.
  8. const DefaultFontConfig FontConfig = 0
  9. func (config FontConfig) handle() C.IggFontConfig {
  10. return C.IggFontConfig(config)
  11. }
  12. // NewFontConfig creates a new font configuration.
  13. // Delete must be called on the returned config.
  14. func NewFontConfig() FontConfig {
  15. configHandle := C.iggNewFontConfig()
  16. return FontConfig(configHandle)
  17. }
  18. // Delete removes the font configuration and resets it to the DefaultFontConfig.
  19. func (config *FontConfig) Delete() {
  20. if *config != DefaultFontConfig {
  21. C.iggFontConfigDelete(config.handle())
  22. *config = DefaultFontConfig
  23. }
  24. }
  25. // SetSize sets the size in pixels for rasterizer (more or less maps to the
  26. // resulting font height).
  27. func (config FontConfig) SetSize(sizePixels float32) {
  28. if config != DefaultFontConfig {
  29. C.iggFontConfigSetSize(config.handle(), C.float(sizePixels))
  30. }
  31. }
  32. // SetOversampleH sets the oversampling amount for the X axis.
  33. // Rasterize at higher quality for sub-pixel positioning.
  34. // We don't use sub-pixel positions on the Y axis.
  35. func (config FontConfig) SetOversampleH(value int) {
  36. if config != DefaultFontConfig {
  37. C.iggFontConfigSetOversampleH(config.handle(), C.int(value))
  38. }
  39. }
  40. // SetOversampleV sets the oversampling amount for the Y axis.
  41. // Rasterize at higher quality for sub-pixel positioning.
  42. // We don't use sub-pixel positions on the Y axis.
  43. func (config FontConfig) SetOversampleV(value int) {
  44. if config != DefaultFontConfig {
  45. C.iggFontConfigSetOversampleV(config.handle(), C.int(value))
  46. }
  47. }
  48. // SetPixelSnapH aligns every glyph to pixel boundary if enabled. Useful e.g. if
  49. // you are merging a non-pixel aligned font with the default font. If enabled,
  50. // you can set OversampleH/V to 1.
  51. func (config FontConfig) SetPixelSnapH(value bool) {
  52. if config != DefaultFontConfig {
  53. C.iggFontConfigSetPixelSnapH(config.handle(), castBool(value))
  54. }
  55. }
  56. // SetGlyphMinAdvanceX sets the minimum AdvanceX for glyphs.
  57. // Set Min to align font icons, set both Min/Max to enforce mono-space font.
  58. func (config FontConfig) SetGlyphMinAdvanceX(value float32) {
  59. if config != DefaultFontConfig {
  60. C.iggFontConfigSetGlyphMinAdvanceX(config.handle(), C.float(value))
  61. }
  62. }
  63. // SetGlyphMaxAdvanceX sets the maximum AdvanceX for glyphs.
  64. // Set both Min/Max to enforce mono-space font.
  65. func (config FontConfig) SetGlyphMaxAdvanceX(value float32) {
  66. if config != DefaultFontConfig {
  67. C.iggFontConfigSetGlyphMaxAdvanceX(config.handle(), C.float(value))
  68. }
  69. }
  70. // SetMergeMode merges the new fonts into the previous font if enabled. This way
  71. // you can combine multiple input fonts into one (e.g. ASCII font + icons +
  72. // Japanese glyphs). You may want to use GlyphOffset.y when merge font of
  73. // different heights.
  74. func (config FontConfig) SetMergeMode(value bool) {
  75. if config != DefaultFontConfig {
  76. C.iggFontConfigSetMergeMode(config.handle(), castBool(value))
  77. }
  78. }
  79. // getFontDataOwnedByAtlas gets the current ownership status of the font data.
  80. func (config FontConfig) getFontDataOwnedByAtlas() bool {
  81. if config != DefaultFontConfig {
  82. return C.iggFontConfigGetFontDataOwnedByAtlas(config.handle()) != 0
  83. }
  84. return true
  85. }
  86. // Brighten (>1.0f) or darken (<1.0f) font output. Brightening small fonts may be a good workaround to make them more readable.
  87. func (config FontConfig) SetRasterizerMultiply(value float32) {
  88. if config != DefaultFontConfig {
  89. C.iggFontConfigSetRasterizerMultiply(config.handle(), C.float(value))
  90. }
  91. }
  92. // FontBuilderFlags returns settings for custom font builder.
  93. func (config FontConfig) FontBuilderFlags() uint {
  94. return uint(C.iggFontConfigGetFontBuilderFlags(config.handle()))
  95. }
  96. // SetFontBuilderFlags sets settings for custom font builder. THIS IS BUILDER IMPLEMENTATION DEPENDENT. Leave as zero if unsure.
  97. func (config FontConfig) SetFontBuilderFlags(flags uint) {
  98. C.iggFontConfigSetFontBuilderFlags(config.handle(), C.uint(flags))
  99. }