diff --git a/addons/ui/fnc_openItemContextMenu.sqf b/addons/ui/fnc_openItemContextMenu.sqf index 3fd9328bd..5a49c1047 100644 --- a/addons/ui/fnc_openItemContextMenu.sqf +++ b/addons/ui/fnc_openItemContextMenu.sqf @@ -48,6 +48,10 @@ if (_options isEqualTo []) exitWith {}; // ctrlSetBackgroundColor command does not seem to work for RscListBox. private _list = _display ctrlCreate [QGVAR(ItemContextMenu), -1]; +private _font = getText (configfile >> QGVAR(ItemContextMenu) >> "font"); +private _fontSize = getNumber (configFile >> ctrlClassName _list >> "sizeEx"); +private _longestName = ""; + // --- // Populate context menu with options. { @@ -63,6 +67,10 @@ private _list = _display ctrlCreate [QGVAR(ItemContextMenu), -1]; }; if ((_slot in _slots || {"ALL" in _slots}) && {_args call _conditionShow}) then { + if (count _longestName < count _displayName) then { + _longestName = _displayName; + }; + private _index = _list lbAdd _displayName; _list lbSetTooltip [_index, "_tooltip"]; // Does not seem to work for RscDisplayInventory controls? Hard coded overwrite? @@ -154,8 +162,8 @@ getMousePosition params ["_left", "_top"]; _left = _left - pixelW; _top = _top - pixelH; -private _width = ctrlPosition _list select 2; -private _height = lbSize _list * getNumber (configFile >> ctrlClassName _list >> "sizeEx"); +private _width = (ctrlPosition _list select 2) max ((_longestName getTextWidth [_font, _fontSize]) + TEXT_MARGINS_WIDTH + RSCLISTBOX_PICTURE_WIDTH); +private _height = lbSize _list * _fontSize; _list ctrlSetPosition [_left, _top, _width, _height]; _list ctrlCommit 0; diff --git a/addons/ui/script_component.hpp b/addons/ui/script_component.hpp index 06e9a446a..431bfc06a 100644 --- a/addons/ui/script_component.hpp +++ b/addons/ui/script_component.hpp @@ -36,6 +36,9 @@ #define GRID_3DEN_W (pixelW * pixelGrid * 0.5) #define GRID_3DEN_H (pixelH * pixelGrid * 0.5) +#define TEXT_MARGINS_WIDTH (2 * 0.008) // Hardcoded value, see https://community.bistudio.com/wiki/getTextWidth +#define RSCLISTBOX_PICTURE_WIDTH 0.05 // Empirical value, RSCListBox's left icon picture width + // Lobby Manager #define IDC_LM_SLOTS 50 #define IDC_LM_CALLSIGN 51