/// <summary> /// Draws a dummy GUI layout element and measures its rect. /// If the current event is not the repaint event, then use the backup rect reference. /// </summary> public static U.Rect FindLayoutAreaRect(ref U.Rect backupRect, int border = 0) { //DRAW DUMMY LAYOUT GROUP TO GET THE RECT FROM Gl.BeginVertical(Gl.MaxWidth(U.Screen.width), Gl.MaxHeight(U.Screen.height)); Gl.Label(""); //<- layout dummy Gl.EndVertical(); U.Rect _fieldRect = U.GUILayoutUtility.GetLastRect(); //rect update handling (ignore dummy rect at layout event) if (U.Event.current.type != U.EventType.Repaint) { _fieldRect = backupRect; } else { backupRect = _fieldRect; } _fieldRect.x += border; _fieldRect.y += border; _fieldRect.width -= border * 2; _fieldRect.height -= border * 2; return(_fieldRect); }
public void OnGUI(UnityModManager.ModEntry modEntry) { if (!Mod.Enabled) { return; } if (toggleStyle == null) { toggleStyle = new GUIStyle(GUI.skin.toggle) { wordWrap = true } } ; using (new GL.VerticalScope("box")) { ToggleVendorProgression = GL.Toggle(ToggleVendorProgression, Local["Menu_Tog_VenProgress"], Array.Empty <GLO>()); } using (new GL.VerticalScope("box")) { ToggleHighlightScrolls = GL.Toggle(ToggleHighlightScrolls, Local["Menu_Tog_HLScrolls"], Array.Empty <GLO>()); using (new GUISubScope()) ScrollColor = OnGUIColorSlider(ScrollColor, Local["Menu_Txt_Unlearned"]); } using (new GL.VerticalScope("box")) { ToggleVendorTrash = GL.Toggle(ToggleVendorTrash, Local["Menu_Tog_VendorTrash"], toggleStyle, GL.ExpandWidth(false)); using (new GUISubScope()) { TrashColor = OnGUIColorSlider(TrashColor, Local["Menu_Txt_VendorTrash"]); ToggleAutoSell = GL.Toggle(ToggleAutoSell, Local["Menu_Tog_AutoSell"], toggleStyle, GL.ExpandWidth(false)); using (new GL.HorizontalScope()) { if (GL.Button(ToggleShowTrash ? Local["Menu_Tog_HideTrash"] : Local["Menu_Tog_ShowTrash"], GL.ExpandWidth(false))) { ToggleShowTrash = !ToggleShowTrash; } if (GL.Button(Local["Menu_Btn_ClearTrash"], GL.ExpandWidth(false))) { VendorTrashItems.Clear(); } } if (ToggleShowTrash) { using (new GUISubScope()) { string remove = ""; foreach (string trash in VendorTrashItems) { using (new GL.VerticalScope("box", GL.ExpandWidth(false))) { using (new GL.HorizontalScope()) { bool hasKeep = TrashItemsKeep.ContainsKey(trash); GL.Label($"{library.Get<BlueprintItem>(trash).Name} x{((hasKeep) ? TrashItemsKeep[trash] : 0)} {Local["Menu_Txt_Kept"]}", GL.MaxHeight(screenWidth), GL.MaxHeight(lineHeight)); if (GL.Button("+", GL.ExpandWidth(false))) { if (hasKeep) { TrashItemsKeep[trash]++; } else { TrashItemsKeep.Add(trash, 1); } } if (GL.Button("-", GL.ExpandWidth(false))) { if (hasKeep && TrashItemsKeep[trash] > 0) { TrashItemsKeep[trash]--; } else if (hasKeep) { TrashItemsKeep.Remove(trash); } } if (GL.Button(Local["Menu_Btn_Remove"], GL.ExpandWidth(false))) { remove = trash; } if (Event.current.type == EventType.Repaint) { screenWidth = GUILayoutUtility.GetLastRect().width; } } } } if (remove != "") { VendorTrashItems.Remove(remove); } } } } } using (new GL.VerticalScope("box")) { using (new GUISubScope()) OnGUILang(); } }
public static GUILayoutOption MaxHeight(float v) => GL.MaxHeight(v);
public static GUILayoutOption[] Height(float min, float max) => new GUILayoutOption[] { GL.MinHeight(min), GL.MaxHeight(max) };
public static GUILayoutOption MaxHeight(float v) { return(GL.MaxHeight(v)); }