Skip to content

Commit

Permalink
Item Context Menu - Flexible menu width (#1492)
Browse files Browse the repository at this point in the history
* Makes Item Context Menu flexible width

* Fix width calculations to use static margins and skip hidden options

Changes width calculation to use static margins.
Fixes width calculation was checking for hidden options

* Fix indentation styling
  • Loading branch information
10Dozen authored Jun 24, 2023
1 parent 191deb8 commit 9fd18c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 9fd18c2

Please sign in to comment.