text.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // TextWrap represents how text longer than the widget's width will be wrapped.
  14. type TextWrap int
  15. const (
  16. // TextWrapOff extends the widget's width to fit the text, no wrapping is applied.
  17. TextWrapOff TextWrap = iota
  18. // TextTruncate trims the text to the widget's width, no wrapping is applied.
  19. // If an entry is asked to truncate it will provide scrolling capabilities.
  20. TextTruncate
  21. // TextWrapBreak trims the line of characters to the widget's width adding the excess as new line.
  22. // An Entry with text wrapping will scroll vertically if there is not enough space for all the text.
  23. TextWrapBreak
  24. // TextWrapWord trims the line of words to the widget's width adding the excess as new line.
  25. // An Entry with text wrapping will scroll vertically if there is not enough space for all the text.
  26. TextWrapWord
  27. )
  28. // TextStyle represents the styles that can be applied to a text canvas object
  29. // or text based widget.
  30. type TextStyle struct {
  31. Bold bool // Should text be bold
  32. Italic bool // Should text be italic
  33. Monospace bool // Use the system monospace font instead of regular
  34. // Since: 2.2
  35. Symbol bool // Use the system symbol font.
  36. // Since: 2.1
  37. TabWidth int // Width of tabs in spaces
  38. }
  39. // MeasureText uses the current driver to calculate the size of text when rendered.
  40. func MeasureText(text string, size float32, style TextStyle) Size {
  41. s, _ := CurrentApp().Driver().RenderedTextSize(text, size, style)
  42. return s
  43. }