Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item Context Menu - Flexible menu width #1492

Merged
merged 3 commits into from
Jun 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions addons/ui/fnc_openItemContextMenu.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
{
Expand All @@ -57,6 +61,9 @@ private _list = _display ctrlCreate [QGVAR(ItemContextMenu), -1];
if (isLocalized _displayName) then {
_displayName = localize _displayName;
};
if (count _longestName < count _displayName) then {
_longestName = _displayName;
};

if (isLocalized _tooltip) then {
_tooltip = localize _tooltip;
Expand Down Expand Up @@ -154,8 +161,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 1.1 * (_longestName getTextWidth [_font, _fontSize]);
private _height = lbSize _list * _fontSize;

_list ctrlSetPosition [_left, _top, _width, _height];
_list ctrlCommit 0;
Expand Down