How to construct a stretchable array?
Here's a first shot using drivers, with a set-up to keep the expressions as simple as possible to begin with.

The X location of an Empty('End'), marks the length of the array. Moving 'End' in X changes a collection of driven values, and stretches the array. Everything is parented to another Empty at the origin, ('Start') so the rig works in Start's space, and can be moved about.

The arrayed object is a rectangle with 2 shape keys. The Basis key is set to width 0. The 'Width' key is set to width 1 at relative value 1, so the Value directly encodes the width.

The Count of the array is driven as follows:



The shape key of the rectangle is driven by the 'End' Empty, too:



... and the rectangle is rounded top and bottom by a driven Bevel modifier:



..with this result, so far:



I don't know whether this satisfies your requirements directly, but I'm sure it could be adjusted?