Widgets

  • An abstract widget is a category defined purely by what it does, not by how it looks.
  • A widget (sometimes called a concrete or specific widget) is one actual control you can place in a UI.
  • Button

image.png

  • The function gc.measureText(text) is a method provided by the Canvas 2D rendering context (gc is short for graphics context). It is used to measure how much space a specific string of text will occupy when rendered on the canvas with the current font settings.
  • Canvas Buffer: The utility renders text onto an off-screen canvas buffer to measure it accurately (like getting pixel-perfect metrics).
    • Caching: To improve performance, it caches the result of text measurements so that the same text string doesn’t need to be measured again unless the font changes.
  • Height = Ascent + Descent:
    • Ascent: Distance from the baseline to the top of the tallest character (like “Gˇ”).
    • Descent: Distance from the baseline to the bottom of the lowest character (like the tail of “g”).
    • The total font height is the sum of these two.
  • SKContainer to hold “child” widgets (i.e. SKElements)
    • children are drawn relative to container position
    • containers create widget tree