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
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 10 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 @@ -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?

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions addons/ui/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down