text.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package fyne
  2. // TextAlign represents the horizontal alignment of text within a widget or
  3. // canvas object.
  4. type TextAlign int
  5. const (
  6. // TextAlignLeading specifies a left alignment for left-to-right languages.
  7. TextAlignLeading TextAlign = iota
  8. // TextAlignCenter places the text centrally within the available space.
  9. TextAlignCenter
  10. // TextAlignTrailing will align the text right for a left-to-right language.
  11. TextAlignTrailing
  12. )
  13. // TextTruncation controls how a `Label` or `Entry` will truncate its text.
  14. // The default value is `TextTruncateOff` which will not truncate.
  15. //
  16. // Since: 2.4
  17. type TextTruncation int
  18. const (
  19. // TextTruncateOff means no truncation will be applied, it is the default.
  20. // This means that the minimum size of a text block will be the space required to display it fully.
  21. TextTruncateOff TextTruncation = iota
  22. // TextTruncateClip will truncate text when it reaches the end of the available space.
  23. TextTruncateClip
  24. // TextTruncateEllipsis is like regular truncation except that an ellipses (…) will be inserted
  25. // wherever text has been shortened to fit.
  26. //
  27. // Since: 2.4
  28. TextTruncateEllipsis
  29. )
  30. // TextWrap represents how text longer than the widget's width will be wrapped.
  31. type TextWrap int
  32. const (
  33. // TextWrapOff extends the widget's width to fit the text, no wrapping is applied.
  34. TextWrapOff TextWrap = iota
  35. // TextTruncate trims the text to the widget's width, no wrapping is applied.
  36. // If an entry is asked to truncate it will provide scrolling capabilities.
  37. //
  38. // Deprecated: Use `TextTruncateClip` value of the widget `Truncation` field instead
  39. TextTruncate
  40. // TextWrapBreak trims the line of characters to the widget's width adding the excess as new line.
  41. // An Entry with text wrapping will scroll vertically if there is not enough space for all the text.
  42. TextWrapBreak
  43. // TextWrapWord trims the line of words to the widget's width adding the excess as new line.
  44. // An Entry with text wrapping will scroll vertically if there is not enough space for all the text.
  45. TextWrapWord
  46. )
  47. // TextStyle represents the styles that can be applied to a text canvas object
  48. // or text based widget.
  49. type TextStyle struct {
  50. Bold bool // Should text be bold
  51. Italic bool // Should text be italic
  52. Monospace bool // Use the system monospace font instead of regular
  53. // Since: 2.2
  54. Symbol bool // Use the system symbol font.
  55. // Since: 2.1
  56. TabWidth int // Width of tabs in spaces
  57. }
  58. // MeasureText uses the current driver to calculate the size of text when rendered.
  59. func MeasureText(text string, size float32, style TextStyle) Size {
  60. s, _ := CurrentApp().Driver().RenderedTextSize(text, size, style)
  61. return s
  62. }