Schatten 289 Posted October 14 Hi! I wrote a function to get listbox item index by coordinates. It works fine if listbox height is a multiple of row height, otherwise a small error appears, which is especially noticeable at the end of listbox. Could anyone help solve this issue? Spoiler private ["_index", "_itemsCount"]; _index = -1; params [ "_control", "_coordinates", ["_itemHeight", getNumber (configFile >> "ctrlListbox" >> "rowHeight")] ]; _itemsCount = lbSize _control; if (_itemsCount == 0) exitWith { _index }; private ["_contentHeight", "_offset"]; (ctrlPosition _control) params ["", "_controlY", "", "_controlH"]; ((ctrlScrollValues _control) apply { if (_x < 0) then { 0 } else { _x } }) params ["_scrollValueV"]; _coordinates params ["", "_y"]; _y = _y - _controlY; _contentHeight = _itemsCount * _itemHeight; _offset = if (_contentHeight > _controlH) then { _scrollValueV * (_contentHeight - (floor (_controlH / _itemHeight)) * _itemHeight) } else { 0 }; if (_y <= (_contentHeight - _offset)) then { _index = floor ((_offset + _y) / _itemHeight); }; hintSilent (format [ "Control height: %1\nItem height: %2\nContent height: %3\nItems count: %4\ny: %5\nScroll values: %6\nOffset: %7\nIndex: %8", _controlH, _itemHeight, _contentHeight, _itemsCount, _y, ctrlScrollValues _control, _offset, _index ]); _index Spoiler Share this post Link to post Share on other sites
POLPOX 778 Posted October 14 ListBox's sizeEx will be rounded into pixel perfect. Which means if sizeEx has a modulo (sizeEx mod pixelH != 0) there can be a gap between your coordinates and real height. sizeEx = rowHeight - (rowHeight mod pixelH) is a workaround. 1 Share this post Link to post Share on other sites
Schatten 289 Posted October 14 So, you suggest changing sizeEx in my listbox config, right? If so, can I fix this gap in my function? I'm asking because I would like my dialogs to be as vanilla as possible, so I wouldn't like to change sizeEx. I also wouldn't like sizes of listboxes and, accordingly, the dialog to change when switching between tabs. Share this post Link to post Share on other sites
Schatten 289 Posted October 14 2 hours ago, POLPOX said: ListBox's sizeEx will be rounded into pixel perfect. Which means if sizeEx has a modulo (sizeEx mod pixelH != 0) there can be a gap between your coordinates and real height. sizeEx = rowHeight - (rowHeight mod pixelH) is a workaround. Unfortunately, this didn't help: #define LISTBOX_ITEM_H 1.75 * 4.32 * pixelGrid * pixelScale / (getResolution select 3) ... rowHeight = LISTBOX_ITEM_H; sizeEx = __EVAL(format ["%1 - (%1 mod pixelH)", LISTBOX_ITEM_H]); Spoiler Share this post Link to post Share on other sites
POLPOX 778 Posted October 14 If you don't want to make a new class, maybe you can use _itemHeight = _itemHeight - (_itemHeight mod pixelH)? 1 1 Share this post Link to post Share on other sites
Schatten 289 Posted October 15 It works! I added your line just after _y = _y - _controlY; Thanks, @POLPOX! 1 Share this post Link to post Share on other sites