Hi!
After a bit of work, I managed to get a pretty good looking display for airspeed in the style of an aircraft hud.
Here’s how I did it: first step, get a canvas set up to cover the area you want your speed notches in, and set it to clip to bounds, like so
I populated mine with a function that just spins up a bunch of “notch” widgets and parents them to the area canvas during initialization (the notch widgets are the moving displays of airspeeds above or below your current). These widgets will display the speed values. These are all anchored to the top right corner of the display widget.
The real magic happens in the function which ticks the display area. It’s a monster of a thing, so here it is in two images:
Basically: we take in the canvas we’re ticking (my final widget has two of these canvases, one above and one below the current speed display), a display value (in this case our actual airspeed), a notch interval (do we want a notch every 10 knots? 20? etc), some vertical offsets (these say how far outside the canvas to go; if these are zero notches will seem to snap around whenever they hit the bottom or top of the display area), and a boolean which says whether the displayed value is above or below the canvas.
We use this information to figure out what the biggest and smallest airspeed values which we can display in this area are, and to figure out exactly how big the area in which these notches can be is.
In short, we now have two ranges; the first represents the range of airspeeds we’re showing, and the second is the ranges of positions we can display those airspeeds in. Positioning the notches is a matter of mapping one range onto the other.
Now, we go through the children of the canvas we’re ticking; these children are all the display notches. To find the speed displayed by the first one, we just snap the display value to the multiple of our notch interval immediately above it (that’s what the ceil with division/multiplication on either side is doing). To find the speed displayed by the second one, we just add the notch interval to it. For the third, we find add twice the interval, and so on (i.e. multiply the array index of the child by the notch interval and add to the “base” value).
The last step is to position things, which is pretty straightforward. Find where in the range of displayed values the thing lives, get that as a fraction, multiply by the range of positions we can have, and add to the “base” position.
Set the offsets as you like, and make sure that “notch display size” is set to the vertical size of your notch widget.
This was a rambling writeup which probably makes no sense, but feel free to ask questions if anything is unclear. At some point I might clean this up and turn it into a forum post, but that will be for another less busy day. Hope this helps.