From f25da3e30749dbafe45a0ca62057d32f4abb2565 Mon Sep 17 00:00:00 2001 From: Rich Dunne Date: Sun, 11 Oct 2020 14:57:57 -0600 Subject: [PATCH] Barrier menu width now adjusts to fit scroller item text --- SceneManager/Menus/BarrierMenu.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/SceneManager/Menus/BarrierMenu.cs b/SceneManager/Menus/BarrierMenu.cs index 8a0de4c..ca628e4 100644 --- a/SceneManager/Menus/BarrierMenu.cs +++ b/SceneManager/Menus/BarrierMenu.cs @@ -150,6 +150,8 @@ namespace SceneManager { rotateBarrier.Enabled = true; } + + barrierMenu.Width = SetMenuWidth(); } if (scrollerItem == rotateBarrier) @@ -269,5 +271,27 @@ namespace SceneManager resetBarriers.Enabled = barriers.Count == 0 ? false : true; } } + + private static float SetMenuWidth() + { + float defaultWidth = UIMenu.DefaultWidth; + float width = barrierMenu.Width; + + barrierList.TextStyle.Apply(); + Rage.Native.NativeFunction.Natives.x54CE8AC98E120CAB("STRING"); // _BEGIN_TEXT_COMMAND_GET_WIDTH + Rage.Native.NativeFunction.Natives.ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(barrierList.SelectedItem); + float textWidth = Rage.Native.NativeFunction.Natives.x85F061DA64ED2F67(true); // _END_TEXT_COMMAND_GET_WIDTH + float padding = 0.00390625f * 2; // typical padding used in RNUI + + var selectedItemWidth = textWidth + padding; + if(selectedItemWidth <= 0.14f) + { + return defaultWidth; + } + else + { + return selectedItemWidth * 1.6f; + } + } } }