hello, I started programming widgets with a similar thing.
Shaman in the past wrote me a widget for selecting units per class around the cursor.
I rewrote it there, with lots of annotations to understand how it works.
https://www.geany.org/p/g02r1/copy this in a txt file and rename it whatever_name_you_want.lua and place it in LuaUI/Widgets directory.
how to install local widgets
https://zero-k.info/mediawiki/Widget_Configuration#Using_custom_widgetsThat widget is not enabled by default, so you will have to enable it manually in the widget list (ALT+F11) under the name 'Area Select'