From afdf1fc21b718bd73c60c5bb1defb64bc401741f Mon Sep 17 00:00:00 2001 From: "eugene.tretyak" Date: Fri, 6 Aug 2021 14:31:51 +0300 Subject: [PATCH 1/3] Makes Item Context Menu flexible width --- addons/ui/fnc_openItemContextMenu.sqf | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/ui/fnc_openItemContextMenu.sqf b/addons/ui/fnc_openItemContextMenu.sqf index 3fd9328bd7..19d79e81ba 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. { @@ -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; @@ -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; From 2fff981da3e88bc87f4bce1999bf5afe975af73b Mon Sep 17 00:00:00 2001 From: "eugene.tretyak" Date: Mon, 10 Oct 2022 14:14:02 +0300 Subject: [PATCH 2/3] 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 --- addons/ui/fnc_openItemContextMenu.sqf | 9 +++++---- addons/ui/script_component.hpp | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/ui/fnc_openItemContextMenu.sqf b/addons/ui/fnc_openItemContextMenu.sqf index 19d79e81ba..741fe4bab8 100644 --- a/addons/ui/fnc_openItemContextMenu.sqf +++ b/addons/ui/fnc_openItemContextMenu.sqf @@ -61,15 +61,16 @@ private _longestName = ""; if (isLocalized _displayName) then { _displayName = localize _displayName; }; - if (count _longestName < count _displayName) then { - _longestName = _displayName; - }; if (isLocalized _tooltip) then { _tooltip = localize _tooltip; }; 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? @@ -161,7 +162,7 @@ getMousePosition params ["_left", "_top"]; _left = _left - pixelW; _top = _top - pixelH; -private _width = (ctrlPosition _list select 2) max 1.1 * (_longestName getTextWidth [_font, _fontSize]); +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]; diff --git a/addons/ui/script_component.hpp b/addons/ui/script_component.hpp index 06e9a446a8..431bfc06a5 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 From 0bbf3092bfdf3f9d9f19d487dd524a8a958af486 Mon Sep 17 00:00:00 2001 From: "eugene.tretyak" Date: Mon, 10 Oct 2022 18:53:15 +0300 Subject: [PATCH 3/3] Fix indentation styling --- addons/ui/fnc_openItemContextMenu.sqf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/ui/fnc_openItemContextMenu.sqf b/addons/ui/fnc_openItemContextMenu.sqf index 741fe4bab8..5a49c1047d 100644 --- a/addons/ui/fnc_openItemContextMenu.sqf +++ b/addons/ui/fnc_openItemContextMenu.sqf @@ -67,10 +67,10 @@ private _longestName = ""; }; if ((_slot in _slots || {"ALL" in _slots}) && {_args call _conditionShow}) then { - if (count _longestName < count _displayName) then { - _longestName = _displayName; - }; - + 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?