Decompiled source of ReConfig v0.1.0

ReConfig.dll

Decompiled 14 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using ReConfig.Config;
using ReConfig.Overlay;
using ReConfig.Platform;
using ReConfig.Platform.Blocking;
using ReConfig.UI;
using ReConfig.UI.Fonts;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ReConfig")]
[assembly: AssemblyDescription("An in-game configuration menu for BepInEx 5 mods, in the style of ReShade's overlay.")]
[assembly: AssemblyProduct("ReConfig")]
[assembly: AssemblyCompany("lmkHenlo")]
[assembly: AssemblyCopyright("Copyright (c) 2026 lmkHenlo")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace ReConfig
{
	[BepInPlugin("com.reconfig", "ReConfig", "0.1.0")]
	public sealed class Plugin : BaseUnityPlugin, IOverlayPlatform
	{
		public const string Guid = "com.reconfig";

		public const string Name = "ReConfig";

		public const string Version = "0.1.0";

		private const float ReleaseTimeout = 0.5f;

		internal static ManualLogSource Log;

		private Settings _settings;

		private FontAtlas _atlas;

		private Gui _gui;

		private ConfigCatalog _catalog;

		private OverlayHost _host;

		private UnityRenderer _renderer;

		private ImguiInput _input;

		private InputBlocker _blocker;

		private LogBuffer _logBuffer;

		private LogCapture _logCapture;

		private List<FontSource> _fontSources;

		private float _fontSize;

		private float _nextExternalCheck;

		private bool _broken;

		private bool _started;

		private bool _releasePending;

		private int _closedFrame;

		private float _closedTime;

		string IOverlayPlatform.ModVersion => "0.1.0";

		string IOverlayPlatform.GameDescription => Application.productName + " " + Application.version + ", Unity " + Application.unityVersion;

		string IOverlayPlatform.BepInExVersion => typeof(Chainloader).Assembly.GetName().Version.ToString();

		bool IOverlayPlatform.InputBlockingWorks
		{
			get
			{
				if (_blocker != null)
				{
					return _blocker.Works;
				}
				return true;
			}
		}

		string IOverlayPlatform.InputBlockingStatus
		{
			get
			{
				if (_blocker == null)
				{
					return "";
				}
				return _blocker.Status;
			}
		}

		string IOverlayPlatform.ColorSpaceStatus
		{
			get
			{
				if (_renderer == null)
				{
					return "";
				}
				return _renderer.ColorSpaceStatus;
			}
		}

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			((MonoBehaviour)this).useGUILayout = false;
			try
			{
				_settings = new Settings(((BaseUnityPlugin)this).Config);
				_logBuffer = new LogBuffer();
				_logCapture = new LogCapture(_logBuffer);
				_logCapture.LoadExisting();
				Logger.Listeners.Add((ILogListener)(object)_logCapture);
				SafeFile.BackupDirectory = Path.Combine(Path.Combine(Paths.CachePath, "ReConfig"), "backups");
				SafeFile.LogWarning = delegate(string s)
				{
					Log.LogWarning((object)s);
				};
				ConfigSource.ValidateKeyboardShortcut = ImguiInput.ValidateShortcut;
				_fontSources = FontLoader.Load(Log);
				if (_fontSources.Count == 0)
				{
					throw new InvalidOperationException("no font could be loaded");
				}
				_atlas = new FontAtlas();
				_gui = new Gui(_atlas);
				_input = new ImguiInput();
				_blocker = new InputBlocker("com.reconfig", Log)
				{
					Mode = _settings.InputBlocking
				};
				_catalog = new ConfigCatalog(Paths.ConfigPath, () => Discovery.LiveSources("com.reconfig", Log));
				_host = new OverlayHost(_gui, _catalog, _settings, this, _logBuffer);
				_renderer = new UnityRenderer(Log)
				{
					Requested = _settings.ColorSpace
				};
				if (!_renderer.Init(out var error))
				{
					throw new InvalidOperationException("the overlay can't be drawn: " + error);
				}
				Log.LogInfo((object)("ReConfig 0.1.0 loaded (drawing with " + _renderer.ShaderName + "). Press " + _settings.OverlayKey + " to open the overlay."));
			}
			catch (Exception ex)
			{
				_broken = true;
				Log.LogError((object)("ReConfig couldn't start: " + ex));
			}
		}

		private void Start()
		{
			if (_broken)
			{
				return;
			}
			try
			{
				_catalog.Rescan();
				int num = 0;
				foreach (ConfigSource source in _catalog.Sources)
				{
					if (source.Error != null)
					{
						num++;
						Log.LogWarning((object)(source.FilePath + ": " + source.Error));
					}
					foreach (string warning in source.Warnings)
					{
						Log.LogWarning((object)(source.FilePath + ": " + warning));
					}
				}
				Log.LogInfo((object)("Found " + _catalog.Sources.Count + " config files (" + (_catalog.Sources.Count - num) + " readable) and " + _catalog.OtherFiles.Count + " other files in " + Paths.ConfigPath + "."));
				if (_settings.ShowSplash)
				{
					_host.ShowSplash(Time.realtimeSinceStartup, 12.0);
				}
				_started = true;
			}
			catch (Exception ex)
			{
				_broken = true;
				Log.LogError((object)("ReConfig couldn't read the config files: " + ex));
			}
		}

		private void Update()
		{
			if (_broken || !_started)
			{
				return;
			}
			try
			{
				if (_releasePending && Time.frameCount > _closedFrame && (!_input.AnythingHeld || Time.realtimeSinceStartup - _closedTime >= 0.5f))
				{
					_releasePending = false;
					_blocker.Release();
				}
				OverlayInputBlocking inputBlocking = _settings.InputBlocking;
				if (inputBlocking != _blocker.Mode)
				{
					_blocker.Mode = inputBlocking;
					if (_blocker.Blocking)
					{
						_blocker.Release();
						_blocker.Block();
					}
				}
				if (_host.IsOpen)
				{
					if (Time.realtimeSinceStartup >= _nextExternalCheck)
					{
						_nextExternalCheck = Time.realtimeSinceStartup + 1f;
						foreach (ConfigSource source in _catalog.Sources)
						{
							source.CheckForExternalChanges();
						}
					}
					if (_gui.ActiveId == 0)
					{
						_settings.Flush();
					}
				}
				_blocker.Maintain();
			}
			catch (Exception e)
			{
				Fail("Update", e);
			}
		}

		private void LateUpdate()
		{
			if (_blocker != null && !_broken)
			{
				_blocker.MaintainCursor();
			}
		}

		private void OnApplicationFocus(bool focused)
		{
			if (!focused)
			{
				_input?.Reset();
			}
		}

		private void Toggle()
		{
			if (_host.IsOpen)
			{
				_host.Close();
				_settings.Flush();
				_releasePending = true;
				_closedFrame = Time.frameCount;
				_closedTime = Time.realtimeSinceStartup;
			}
			else
			{
				_host.Open();
				_releasePending = false;
				if (!_blocker.Blocking)
				{
					_blocker.Block();
				}
			}
		}

		private void OnGUI()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			if (_broken || !_started)
			{
				return;
			}
			Event current = Event.current;
			try
			{
				GUI.depth = -1000;
				if ((int)current.type != 7 && (int)current.type != 8)
				{
					HandleEvent(current);
					return;
				}
				_input.Handle(current);
				if ((int)current.type != 7)
				{
					return;
				}
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				if (!_host.NeedsFrame(realtimeSinceStartup))
				{
					_input.EndFrame();
					return;
				}
				OverlayColorSpace colorSpace = _settings.ColorSpace;
				if (colorSpace != _renderer.Requested)
				{
					_renderer.Requested = colorSpace;
					if (colorSpace == OverlayColorSpace.Auto)
					{
						_renderer.Retest();
					}
				}
				float num = _host.TargetFontSize(Screen.height);
				if (num != _fontSize)
				{
					if (_fontSize > 0f)
					{
						_atlas.Clear();
					}
					_gui.SetFont(new Font(_atlas, _fontSources, num));
					_fontSize = num;
				}
				_input.Apply(_gui.IO, _host.IsOpen);
				_gui.NewFrame();
				_host.Frame(realtimeSinceStartup);
				_renderer.Render(_gui.Render());
			}
			catch (Exception e)
			{
				Fail("drawing", e);
			}
		}

		private void HandleEvent(Event e)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Invalid comparison between Unknown and I4
			bool flag = _gui.ActiveId != 0;
			if ((int)e.type == 4 && (int)e.keyCode != 0 && !flag && (_input.IsShortcutPress(e, _settings.OverlayKey) || (_host.IsOpen && (int)e.keyCode == 27 && !_input.IsHeld((KeyCode)27) && !_gui.IsAnyPopupOpen)))
			{
				_input.Handle(e);
				Toggle();
				e.Use();
				return;
			}
			_input.Handle(e);
			if (_host.IsOpen && ImguiInput.IsInputEvent(e.type))
			{
				e.Use();
			}
		}

		private void Fail(string where, Exception e)
		{
			Log.LogError((object)("ReConfig stopped after an error while " + where + ": " + e));
			_broken = true;
			try
			{
				_host?.Close();
				_blocker?.Release();
			}
			catch
			{
			}
		}

		private void OnApplicationQuit()
		{
			Shutdown();
		}

		private void OnDestroy()
		{
			Shutdown();
			_renderer?.Dispose();
			_blocker?.Dispose();
			if (_logCapture != null)
			{
				Logger.Listeners.Remove((ILogListener)(object)_logCapture);
			}
		}

		private void Shutdown()
		{
			try
			{
				if (_host != null && _host.IsOpen)
				{
					_host.Close();
				}
				_releasePending = false;
				_blocker?.Release();
				_catalog?.CommitAll();
				_settings?.Flush();
			}
			catch (Exception ex)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)("While closing: " + ex.Message));
				}
			}
		}

		void IOverlayPlatform.OpenPath(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return;
			}
			try
			{
				Process.Start(new ProcessStartInfo(path)
				{
					UseShellExecute = true
				});
			}
			catch (Exception)
			{
				Application.OpenURL("file:///" + path.Replace('\\', '/'));
			}
		}
	}
	internal sealed class Settings : IOverlaySettings
	{
		private readonly ConfigEntry<KeyboardShortcut> _overlayKey;

		private readonly ConfigEntry<bool> _showSplash;

		private readonly ConfigEntry<bool> _showDescriptions;

		private readonly ConfigEntry<bool> _showAdvanced;

		private readonly ConfigEntry<float> _fontScale;

		private readonly ConfigEntry<float> _alpha;

		private readonly ConfigEntry<float> _frameRounding;

		private readonly ConfigEntry<string> _accent;

		private readonly ConfigEntry<float> _panelWidth;

		private readonly ConfigEntry<float> _editorHeight;

		private readonly ConfigEntry<bool> _panelDocked;

		private readonly ConfigEntry<float> _panelX;

		private readonly ConfigEntry<float> _panelY;

		private readonly ConfigEntry<float> _panelHeight;

		private readonly ConfigEntry<OverlayColorSpace> _colorSpace;

		private readonly ConfigEntry<OverlayInputBlocking> _inputBlocking;

		private float? _panelWidthPending;

		private float? _editorHeightPending;

		private float? _panelXPending;

		private float? _panelYPending;

		private float? _panelHeightPending;

		public string OverlayKey
		{
			get
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				KeyboardShortcut value = _overlayKey.Value;
				return ((KeyboardShortcut)(ref value)).Serialize();
			}
			set
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				_overlayKey.Value = KeyboardShortcut.Deserialize(value ?? "");
			}
		}

		public bool ShowSplash
		{
			get
			{
				return _showSplash.Value;
			}
			set
			{
				_showSplash.Value = value;
			}
		}

		public bool ShowDescriptions
		{
			get
			{
				return _showDescriptions.Value;
			}
			set
			{
				_showDescriptions.Value = value;
			}
		}

		public bool ShowAdvanced
		{
			get
			{
				return _showAdvanced.Value;
			}
			set
			{
				_showAdvanced.Value = value;
			}
		}

		public float FontScale
		{
			get
			{
				return _fontScale.Value;
			}
			set
			{
				_fontScale.Value = value;
			}
		}

		public float Alpha
		{
			get
			{
				return _alpha.Value;
			}
			set
			{
				_alpha.Value = value;
			}
		}

		public float FrameRounding
		{
			get
			{
				return _frameRounding.Value;
			}
			set
			{
				_frameRounding.Value = (float)Math.Round(value);
			}
		}

		public string AccentColor
		{
			get
			{
				return _accent.Value;
			}
			set
			{
				_accent.Value = value;
			}
		}

		public float PanelWidth
		{
			get
			{
				return _panelWidthPending ?? _panelWidth.Value;
			}
			set
			{
				_panelWidthPending = value;
			}
		}

		public float EditorHeight
		{
			get
			{
				return _editorHeightPending ?? _editorHeight.Value;
			}
			set
			{
				_editorHeightPending = value;
			}
		}

		public bool PanelDocked
		{
			get
			{
				return _panelDocked.Value;
			}
			set
			{
				_panelDocked.Value = value;
			}
		}

		public float PanelX
		{
			get
			{
				return _panelXPending ?? _panelX.Value;
			}
			set
			{
				_panelXPending = value;
			}
		}

		public float PanelY
		{
			get
			{
				return _panelYPending ?? _panelY.Value;
			}
			set
			{
				_panelYPending = value;
			}
		}

		public float PanelHeight
		{
			get
			{
				return _panelHeightPending ?? _panelHeight.Value;
			}
			set
			{
				_panelHeightPending = value;
			}
		}

		public OverlayColorSpace ColorSpace
		{
			get
			{
				return _colorSpace.Value;
			}
			set
			{
				_colorSpace.Value = value;
			}
		}

		public OverlayInputBlocking InputBlocking
		{
			get
			{
				return _inputBlocking.Value;
			}
			set
			{
				_inputBlocking.Value = value;
			}
		}

		public Settings(ConfigFile config)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Expected O, but got Unknown
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Expected O, but got Unknown
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Expected O, but got Unknown
			_overlayKey = config.Bind<KeyboardShortcut>("General", "OverlayKey", new KeyboardShortcut((KeyCode)279, (KeyCode[])(object)new KeyCode[0]), "Key that opens and closes the overlay. End by default: ReShade uses Home, so with ReShade installed one key doesn't open both. Modifiers can be added, e.g. \"F1 + LeftControl\".");
			_showSplash = config.Bind<bool>("General", "ShowSplash", true, "Show the start-up bar with the overlay key at the top-left when the game starts.");
			_showDescriptions = config.Bind<bool>("Overlay", "ShowDescriptions", false, "Show each setting's description under it. Off = hover a setting to see it.");
			_showAdvanced = config.Bind<bool>("Overlay", "ShowAdvanced", false, "Show settings that mods mark as advanced (ConfigurationManager's IsAdvanced).");
			_fontScale = config.Bind<float>("Overlay", "FontScale", 0f, new ConfigDescription("Text size as a multiple of 13 px. 0 = automatic, like ReShade: 1 below 1440p, 1.5 from 1440p, 2 from 2160p. Ctrl + mouse wheel over the overlay changes it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 4f), new object[0]));
			_alpha = config.Bind<float>("Overlay", "Alpha", 1f, new ConfigDescription("Opacity of the whole overlay (ReShade's Global alpha).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), new object[0]));
			_frameRounding = config.Bind<float>("Overlay", "FrameRounding", 0f, new ConfigDescription("Corner rounding of frames, buttons and windows, in pixels (ReShade's Frame rounding).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 12f), new object[0]));
			_accent = config.Bind<string>("Overlay", "AccentColor", "D51717FF", "Accent colour as RRGGBBAA hex (alpha is ignored). D51717FF = red (default); F06464FF = soft red (ReShade's blue turned red); 6496F0FF = ReShade's blue.");
			_inputBlocking = config.Bind<OverlayInputBlocking>("General", "BlockGameInput", OverlayInputBlocking.Auto, "Keeps the game from reacting to keyboard and mouse while the overlay is open. Auto uses the game's own input modes when ReConfig knows the game, otherwise whatever the game uses (the Input System package, the legacy Input Manager, Rewired), and frees the cursor. CursorOnly only frees the cursor (the game still sees keys and clicks). Off touches neither.");
			_colorSpace = config.Bind<OverlayColorSpace>("Overlay", "ColorSpace", OverlayColorSpace.Auto, "How the overlay's colours are written to the screen. Auto tests the screen when the overlay first draws (and after a resolution change). Gamma draws the colours unchanged; Linear converts them for a screen that converts back. If the overlay looks much too dark (near-black background, deep red), choose Gamma; if it looks washed out, choose Linear.");
			_panelWidth = config.Bind<float>("Layout", "PanelWidth", 0.35f, new ConfigDescription("Width of the overlay panel as a fraction of the screen (ReShade docks it at 0.35). Drag the panel's right edge to change it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.15f, 0.9f), new object[0]));
			_panelDocked = config.Bind<bool>("Layout", "PanelDocked", true, "true: the panel is docked on the left at full height, like ReShade's. false: it is a window you can move (drag its title bar or a tab) and resize (drag its right edge, bottom edge or corner). Dragging the docked panel's title bar undocks it. Dropping it on the left edge of the screen, double-clicking the empty part of the title bar or the menu at its top-left docks it again.");
			_panelX = config.Bind<float>("Layout", "PanelX", 0.1f, new ConfigDescription("Left edge of the undocked panel, as a fraction of the screen width.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-1f, 1f), new object[0]));
			_panelY = config.Bind<float>("Layout", "PanelY", 0.1f, new ConfigDescription("Top edge of the undocked panel, as a fraction of the screen height.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
			_panelHeight = config.Bind<float>("Layout", "PanelHeight", 0.75f, new ConfigDescription("Height of the undocked panel, as a fraction of the screen height.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.15f, 1f), new object[0]));
			_editorHeight = config.Bind<float>("Layout", "EditorHeight", 0f, new ConfigDescription("Height in pixels of the settings editor on the Home tab. 0 = automatic. Drag the bar above it to change it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 4000f), new object[0]));
		}

		public void Flush()
		{
			if (_panelWidthPending.HasValue)
			{
				_panelWidth.Value = (float)Math.Round(_panelWidthPending.Value, 3);
				_panelWidthPending = null;
			}
			if (_editorHeightPending.HasValue)
			{
				_editorHeight.Value = (float)Math.Round(_editorHeightPending.Value);
				_editorHeightPending = null;
			}
			if (_panelXPending.HasValue)
			{
				_panelX.Value = (float)Math.Round(_panelXPending.Value, 4);
				_panelXPending = null;
			}
			if (_panelYPending.HasValue)
			{
				_panelY.Value = (float)Math.Round(_panelYPending.Value, 4);
				_panelYPending = null;
			}
			if (_panelHeightPending.HasValue)
			{
				_panelHeight.Value = (float)Math.Round(_panelHeightPending.Value, 4);
				_panelHeightPending = null;
			}
		}
	}
}
namespace ReConfig.UI
{
	public struct DrawVert
	{
		public float X;

		public float Y;

		public float U;

		public float V;

		public uint Col;
	}
	public struct DrawCmd
	{
		public RectF Clip;

		public int IdxOffset;

		public int IdxCount;
	}
	[Flags]
	public enum Corners
	{
		None = 0,
		TopLeft = 1,
		TopRight = 2,
		BottomLeft = 4,
		BottomRight = 8,
		Top = 3,
		Bottom = 0xC,
		All = 0xF
	}
	public sealed class DrawList
	{
		public DrawVert[] Vtx = new DrawVert[1024];

		public int VtxCount;

		public int[] Idx = new int[2048];

		public int IdxCount;

		public readonly List<DrawCmd> Cmds = new List<DrawCmd>();

		private readonly List<RectF> _clipStack = new List<RectF>();

		private readonly List<Vec2> _path = new List<Vec2>(64);

		private Vec2[] _tmpNormals = new Vec2[64];

		private Vec2[] _tmpPoints = new Vec2[256];

		private FontAtlas _atlas;

		private float _whiteU;

		private float _whiteV;

		private const float AaSize = 1f;

		public RectF CurrentClip { get; private set; }

		public void Reset(FontAtlas atlas, RectF screen)
		{
			_atlas = atlas;
			_whiteU = atlas.WhiteU;
			_whiteV = atlas.WhiteV;
			VtxCount = 0;
			IdxCount = 0;
			Cmds.Clear();
			_clipStack.Clear();
			_path.Clear();
			CurrentClip = screen;
			Cmds.Add(new DrawCmd
			{
				Clip = screen,
				IdxOffset = 0,
				IdxCount = 0
			});
		}

		public void PushClipRect(RectF r, bool intersect = true)
		{
			_clipStack.Add(CurrentClip);
			SetClip(intersect ? CurrentClip.Intersect(r) : r);
		}

		public void PopClipRect()
		{
			RectF clip = _clipStack[_clipStack.Count - 1];
			_clipStack.RemoveAt(_clipStack.Count - 1);
			SetClip(clip);
		}

		private void SetClip(RectF r)
		{
			CurrentClip = r;
			DrawCmd value = Cmds[Cmds.Count - 1];
			if (value.IdxCount == 0)
			{
				value.Clip = r;
				Cmds[Cmds.Count - 1] = value;
				return;
			}
			Cmds.Add(new DrawCmd
			{
				Clip = r,
				IdxOffset = IdxCount,
				IdxCount = 0
			});
		}

		private void Reserve(int vtx, int idx)
		{
			if (VtxCount + vtx > Vtx.Length)
			{
				Array.Resize(ref Vtx, Math.Max(Vtx.Length * 2, VtxCount + vtx));
			}
			if (IdxCount + idx > Idx.Length)
			{
				Array.Resize(ref Idx, Math.Max(Idx.Length * 2, IdxCount + idx));
			}
			DrawCmd value = Cmds[Cmds.Count - 1];
			value.IdxCount += idx;
			Cmds[Cmds.Count - 1] = value;
		}

		private void V(float x, float y, float u, float v, uint col)
		{
			ref DrawVert reference = ref Vtx[VtxCount++];
			reference.X = x;
			reference.Y = y;
			reference.U = u;
			reference.V = v;
			reference.Col = col;
		}

		private void I(int a, int b, int c)
		{
			Idx[IdxCount++] = a;
			Idx[IdxCount++] = b;
			Idx[IdxCount++] = c;
		}

		public void PrimRect(float x0, float y0, float x1, float y1, uint col)
		{
			if (col >> 24 != 0 && !(x1 <= x0) && !(y1 <= y0) && CurrentClip.Overlaps(new RectF(x0, y0, x1, y1)))
			{
				Reserve(4, 6);
				int vtxCount = VtxCount;
				V(x0, y0, _whiteU, _whiteV, col);
				V(x1, y0, _whiteU, _whiteV, col);
				V(x1, y1, _whiteU, _whiteV, col);
				V(x0, y1, _whiteU, _whiteV, col);
				I(vtxCount, vtxCount + 1, vtxCount + 2);
				I(vtxCount, vtxCount + 2, vtxCount + 3);
			}
		}

		public void PrimRectUV(float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, uint col)
		{
			Reserve(4, 6);
			int vtxCount = VtxCount;
			V(x0, y0, u0, v0, col);
			V(x1, y0, u1, v0, col);
			V(x1, y1, u1, v1, col);
			V(x0, y1, u0, v1, col);
			I(vtxCount, vtxCount + 1, vtxCount + 2);
			I(vtxCount, vtxCount + 2, vtxCount + 3);
		}

		public void AddRectFilled(RectF r, uint col, float rounding = 0f, Corners corners = Corners.All)
		{
			if (col >> 24 != 0)
			{
				if (rounding <= 0.5f || corners == Corners.None)
				{
					PrimRect(r.X0, r.Y0, r.X1, r.Y1, col);
					return;
				}
				PathRect(r.Min, r.Max, rounding, corners);
				PathFillConvex(col);
			}
		}

		public void AddRect(RectF r, uint col, float rounding = 0f, float thickness = 1f, Corners corners = Corners.All)
		{
			if (col >> 24 != 0)
			{
				if (rounding <= 0.5f)
				{
					float num = Math.Max(1f, (float)Math.Round(thickness));
					PrimRect(r.X0, r.Y0, r.X1, r.Y0 + num, col);
					PrimRect(r.X0, r.Y1 - num, r.X1, r.Y1, col);
					PrimRect(r.X0, r.Y0 + num, r.X0 + num, r.Y1 - num, col);
					PrimRect(r.X1 - num, r.Y0 + num, r.X1, r.Y1 - num, col);
				}
				else
				{
					PathRect(new Vec2(r.X0 + 0.5f, r.Y0 + 0.5f), new Vec2(r.X1 - 0.5f, r.Y1 - 0.5f), rounding, corners);
					PathStroke(col, closed: true, thickness);
				}
			}
		}

		public void AddLine(Vec2 a, Vec2 b, uint col, float thickness = 1f)
		{
			if (col >> 24 != 0)
			{
				_path.Add(a + new Vec2(0.5f, 0.5f));
				_path.Add(b + new Vec2(0.5f, 0.5f));
				PathStroke(col, closed: false, thickness);
			}
		}

		public void AddTriangleFilled(Vec2 a, Vec2 b, Vec2 c, uint col)
		{
			if (col >> 24 != 0)
			{
				_path.Add(a);
				_path.Add(b);
				_path.Add(c);
				PathFillConvex(col);
			}
		}

		public void AddCircleFilled(Vec2 center, float radius, uint col, int segments = 0)
		{
			if (col >> 24 != 0 && !(radius < 0.5f))
			{
				if (segments <= 0)
				{
					segments = Math.Max(8, Math.Min(64, (int)(radius * 1.5f) + 6));
				}
				PathArcTo(center, radius, 0f, (float)Math.PI * 2f * ((float)segments - 1f) / (float)segments, segments - 1);
				PathFillConvex(col);
			}
		}

		public void PathLineTo(Vec2 p)
		{
			_path.Add(p);
		}

		public void PathClear()
		{
			_path.Clear();
		}

		public void PathArcTo(Vec2 c, float radius, float aMin, float aMax, int segments)
		{
			if (radius < 0.5f)
			{
				_path.Add(c);
				return;
			}
			for (int i = 0; i <= segments; i++)
			{
				float num = aMin + (float)i / (float)segments * (aMax - aMin);
				_path.Add(new Vec2(c.X + (float)Math.Cos(num) * radius, c.Y + (float)Math.Sin(num) * radius));
			}
		}

		public void PathArcToFast(Vec2 c, float radius, int aMinOf12, int aMaxOf12)
		{
			if (radius < 0.5f)
			{
				_path.Add(c);
				return;
			}
			int val = Math.Max(2, Math.Min(12, (int)(radius * 0.6f) + 2)) * Math.Max(1, aMaxOf12 - aMinOf12) / 3;
			PathArcTo(c, radius, (float)aMinOf12 * (float)Math.PI / 6f, (float)aMaxOf12 * (float)Math.PI / 6f, Math.Max(1, val));
		}

		public void PathRect(Vec2 a, Vec2 b, float rounding, Corners corners)
		{
			float value = b.X - a.X;
			float value2 = b.Y - a.Y;
			rounding = Math.Min(rounding, Math.Abs(value) * (((corners & Corners.Top) == Corners.Top || (corners & Corners.Bottom) == Corners.Bottom) ? 0.5f : 1f) - 1f);
			rounding = Math.Min(rounding, Math.Abs(value2) * (((corners & (Corners.TopLeft | Corners.BottomLeft)) == (Corners.TopLeft | Corners.BottomLeft) || (corners & (Corners.TopRight | Corners.BottomRight)) == (Corners.TopRight | Corners.BottomRight)) ? 0.5f : 1f) - 1f);
			if (rounding <= 0.5f || corners == Corners.None)
			{
				_path.Add(a);
				_path.Add(new Vec2(b.X, a.Y));
				_path.Add(b);
				_path.Add(new Vec2(a.X, b.Y));
				return;
			}
			float num = (((corners & Corners.TopLeft) != Corners.None) ? rounding : 0f);
			float num2 = (((corners & Corners.TopRight) != Corners.None) ? rounding : 0f);
			float num3 = (((corners & Corners.BottomRight) != Corners.None) ? rounding : 0f);
			float num4 = (((corners & Corners.BottomLeft) != Corners.None) ? rounding : 0f);
			PathArcToFast(new Vec2(a.X + num, a.Y + num), num, 6, 9);
			PathArcToFast(new Vec2(b.X - num2, a.Y + num2), num2, 9, 12);
			PathArcToFast(new Vec2(b.X - num3, b.Y - num3), num3, 0, 3);
			PathArcToFast(new Vec2(a.X + num4, b.Y - num4), num4, 3, 6);
		}

		public void PathFillConvex(uint col)
		{
			AddConvexPolyFilled(_path, col);
			_path.Clear();
		}

		public void PathStroke(uint col, bool closed, float thickness)
		{
			AddPolyline(_path, col, closed, thickness);
			_path.Clear();
		}

		private static void FixNormal(ref float x, ref float y)
		{
			float num = x * x + y * y;
			if (num > 1E-06f)
			{
				float num2 = 1f / num;
				if (num2 > 100f)
				{
					num2 = 100f;
				}
				x *= num2;
				y *= num2;
			}
		}

		private void EnsureTemp(int normals, int points)
		{
			if (_tmpNormals.Length < normals)
			{
				_tmpNormals = new Vec2[normals * 2];
			}
			if (_tmpPoints.Length < points)
			{
				_tmpPoints = new Vec2[points * 2];
			}
		}

		public void AddConvexPolyFilled(List<Vec2> pts, uint col)
		{
			int count = pts.Count;
			if (count < 3 || col >> 24 == 0)
			{
				return;
			}
			uint col2 = col & 0xFFFFFF;
			EnsureTemp(count, 0);
			Reserve(count * 2, (count - 2) * 3 + count * 6);
			int vtxCount = VtxCount;
			int num = VtxCount + 1;
			for (int i = 2; i < count; i++)
			{
				I(vtxCount, vtxCount + (i - 1 << 1), vtxCount + (i << 1));
			}
			int num2 = count - 1;
			int num3 = 0;
			while (num3 < count)
			{
				float num4 = pts[num3].X - pts[num2].X;
				float num5 = pts[num3].Y - pts[num2].Y;
				float num6 = num4 * num4 + num5 * num5;
				if (num6 > 0f)
				{
					float num7 = 1f / (float)Math.Sqrt(num6);
					num4 *= num7;
					num5 *= num7;
				}
				_tmpNormals[num2] = new Vec2(num5, 0f - num4);
				num2 = num3++;
			}
			int num8 = count - 1;
			int num9 = 0;
			while (num9 < count)
			{
				Vec2 vec = _tmpNormals[num8];
				Vec2 vec2 = _tmpNormals[num9];
				float x = (vec.X + vec2.X) * 0.5f;
				float y = (vec.Y + vec2.Y) * 0.5f;
				FixNormal(ref x, ref y);
				x *= 0.5f;
				y *= 0.5f;
				V(pts[num9].X - x, pts[num9].Y - y, _whiteU, _whiteV, col);
				V(pts[num9].X + x, pts[num9].Y + y, _whiteU, _whiteV, col2);
				I(vtxCount + (num9 << 1), vtxCount + (num8 << 1), num + (num8 << 1));
				I(num + (num8 << 1), num + (num9 << 1), vtxCount + (num9 << 1));
				num8 = num9++;
			}
		}

		public void AddPolyline(List<Vec2> pts, uint col, bool closed, float thickness)
		{
			int count = pts.Count;
			if (count < 2 || col >> 24 == 0)
			{
				return;
			}
			int num = (closed ? count : (count - 1));
			bool flag = thickness > 1f;
			uint col2 = col & 0xFFFFFF;
			thickness = Math.Max(thickness, 1f);
			EnsureTemp(count, count * 4);
			Reserve(flag ? (count * 4) : (count * 3), flag ? (num * 18) : (num * 12));
			for (int i = 0; i < num; i++)
			{
				int index = ((i + 1 != count) ? (i + 1) : 0);
				float num2 = pts[index].X - pts[i].X;
				float num3 = pts[index].Y - pts[i].Y;
				float num4 = num2 * num2 + num3 * num3;
				if (num4 > 0f)
				{
					float num5 = 1f / (float)Math.Sqrt(num4);
					num2 *= num5;
					num3 *= num5;
				}
				_tmpNormals[i] = new Vec2(num3, 0f - num2);
			}
			if (!closed)
			{
				_tmpNormals[count - 1] = _tmpNormals[count - 2];
			}
			int num6 = VtxCount;
			if (!flag)
			{
				float num7 = 1f;
				if (!closed)
				{
					_tmpPoints[0] = pts[0] + _tmpNormals[0] * num7;
					_tmpPoints[1] = pts[0] - _tmpNormals[0] * num7;
					_tmpPoints[(count - 1) * 2] = pts[count - 1] + _tmpNormals[count - 1] * num7;
					_tmpPoints[(count - 1) * 2 + 1] = pts[count - 1] - _tmpNormals[count - 1] * num7;
				}
				for (int j = 0; j < num; j++)
				{
					int num8 = ((j + 1 != count) ? (j + 1) : 0);
					int num9 = ((j + 1 == count) ? VtxCount : (num6 + 3));
					float x = (_tmpNormals[j].X + _tmpNormals[num8].X) * 0.5f;
					float y = (_tmpNormals[j].Y + _tmpNormals[num8].Y) * 0.5f;
					FixNormal(ref x, ref y);
					x *= num7;
					y *= num7;
					_tmpPoints[num8 * 2] = new Vec2(pts[num8].X + x, pts[num8].Y + y);
					_tmpPoints[num8 * 2 + 1] = new Vec2(pts[num8].X - x, pts[num8].Y - y);
					I(num9, num6, num6 + 2);
					I(num6 + 2, num9 + 2, num9);
					I(num9 + 1, num6 + 1, num6);
					I(num6, num9, num9 + 1);
					num6 = num9;
				}
				for (int k = 0; k < count; k++)
				{
					V(pts[k].X, pts[k].Y, _whiteU, _whiteV, col);
					V(_tmpPoints[k * 2].X, _tmpPoints[k * 2].Y, _whiteU, _whiteV, col2);
					V(_tmpPoints[k * 2 + 1].X, _tmpPoints[k * 2 + 1].Y, _whiteU, _whiteV, col2);
				}
				return;
			}
			float num10 = (thickness - 1f) * 0.5f;
			if (!closed)
			{
				int num11 = count - 1;
				_tmpPoints[0] = pts[0] + _tmpNormals[0] * (num10 + 1f);
				_tmpPoints[1] = pts[0] + _tmpNormals[0] * num10;
				_tmpPoints[2] = pts[0] - _tmpNormals[0] * num10;
				_tmpPoints[3] = pts[0] - _tmpNormals[0] * (num10 + 1f);
				_tmpPoints[num11 * 4] = pts[num11] + _tmpNormals[num11] * (num10 + 1f);
				_tmpPoints[num11 * 4 + 1] = pts[num11] + _tmpNormals[num11] * num10;
				_tmpPoints[num11 * 4 + 2] = pts[num11] - _tmpNormals[num11] * num10;
				_tmpPoints[num11 * 4 + 3] = pts[num11] - _tmpNormals[num11] * (num10 + 1f);
			}
			for (int l = 0; l < num; l++)
			{
				int num12 = ((l + 1 != count) ? (l + 1) : 0);
				int num13 = ((l + 1 == count) ? VtxCount : (num6 + 4));
				float x2 = (_tmpNormals[l].X + _tmpNormals[num12].X) * 0.5f;
				float y2 = (_tmpNormals[l].Y + _tmpNormals[num12].Y) * 0.5f;
				FixNormal(ref x2, ref y2);
				float num14 = x2 * (num10 + 1f);
				float num15 = y2 * (num10 + 1f);
				float num16 = x2 * num10;
				float num17 = y2 * num10;
				_tmpPoints[num12 * 4] = new Vec2(pts[num12].X + num14, pts[num12].Y + num15);
				_tmpPoints[num12 * 4 + 1] = new Vec2(pts[num12].X + num16, pts[num12].Y + num17);
				_tmpPoints[num12 * 4 + 2] = new Vec2(pts[num12].X - num16, pts[num12].Y - num17);
				_tmpPoints[num12 * 4 + 3] = new Vec2(pts[num12].X - num14, pts[num12].Y - num15);
				I(num13 + 1, num6 + 1, num6 + 2);
				I(num6 + 2, num13 + 2, num13 + 1);
				I(num13 + 1, num6 + 1, num6);
				I(num6, num13, num13 + 1);
				I(num13 + 2, num6 + 2, num6 + 3);
				I(num6 + 3, num13 + 3, num13 + 2);
				num6 = num13;
			}
			for (int m = 0; m < count; m++)
			{
				V(_tmpPoints[m * 4].X, _tmpPoints[m * 4].Y, _whiteU, _whiteV, col2);
				V(_tmpPoints[m * 4 + 1].X, _tmpPoints[m * 4 + 1].Y, _whiteU, _whiteV, col);
				V(_tmpPoints[m * 4 + 2].X, _tmpPoints[m * 4 + 2].Y, _whiteU, _whiteV, col);
				V(_tmpPoints[m * 4 + 3].X, _tmpPoints[m * 4 + 3].Y, _whiteU, _whiteV, col2);
			}
		}

		public void AddText(Font font, Vec2 pos, uint col, string text, int start = 0, int end = -1, float wrapWidth = 0f)
		{
			if (text == null || col >> 24 == 0)
			{
				return;
			}
			if (end < 0)
			{
				end = text.Length;
			}
			RectF currentClip = CurrentClip;
			float num = (float)Math.Floor(pos.X);
			float num2 = (float)Math.Floor(pos.Y);
			float size = font.Size;
			float num3 = 1f / (float)font.Atlas.Width;
			int num4 = start;
			while (num4 <= end)
			{
				int num5 = text.IndexOf('\n', num4, end - num4);
				if (num5 < 0)
				{
					num5 = end;
				}
				int num6 = num4;
				do
				{
					int num7 = num5;
					if (wrapWidth > 0f)
					{
						num7 = font.WrapPosition(text, num6, num5, wrapWidth);
					}
					if (num2 > currentClip.Y1)
					{
						return;
					}
					if (num2 + size >= currentClip.Y0)
					{
						float num8 = num;
						for (int i = num6; i < num7; i++)
						{
							char c = text[i];
							switch (c)
							{
							case '\t':
								num8 += font.CharAdvance(c);
								continue;
							default:
							{
								Glyph glyph = font.GetGlyph(c);
								if (glyph.Visible && num8 + glyph.X0 <= currentClip.X1 && num8 + glyph.X1 >= currentClip.X0)
								{
									float num9 = 1f / (float)font.Atlas.Height;
									PrimRectUV(num8 + glyph.X0, num2 + glyph.Y0, num8 + glyph.X1, num2 + glyph.Y1, (float)glyph.AtlasX * num3, (float)glyph.AtlasY * num9, (float)(glyph.AtlasX + glyph.AtlasW) * num3, (float)(glyph.AtlasY + glyph.AtlasH) * num9, col);
								}
								num8 += glyph.AdvanceX;
								if (!(num8 > currentClip.X1) || !(wrapWidth <= 0f))
								{
									continue;
								}
								break;
							}
							case '\r':
								continue;
							}
							break;
						}
					}
					num2 += size;
					num6 = ((wrapWidth > 0f) ? Font.SkipBlanks(text, num7, num5) : num5);
				}
				while (num6 < num5);
				num4 = num5 + 1;
			}
		}
	}
	[Flags]
	public enum WindowFlags
	{
		None = 0,
		AutoResize = 1,
		NoBackground = 2,
		NoInputs = 4,
		Popup = 8,
		Tooltip = 0x10,
		NoScrollbar = 0x20,
		Child = 0x40,
		FrameStyle = 0x80
	}
	internal sealed class GroupData
	{
		public Vec2 BackupCursorPos;

		public Vec2 BackupCursorMaxPos;

		public float BackupIndent;

		public float BackupCurrLineHeight;

		public float BackupCurrLineTextBaseOffset;

		public bool Hovered;

		public bool Active;

		public bool Deactivated;

		public bool Edited;

		public bool ActivatedThisFrame;
	}
	internal sealed class Window
	{
		public uint Id;

		public string Name;

		public WindowFlags Flags;

		public Window Parent;

		public Window Root;

		public RectF Rect;

		public RectF InnerRect;

		public RectF ClipRect;

		public RectF WorkRect;

		public Vec2 Padding;

		public DrawList Dl;

		public DrawList BgDl;

		public Vec2 CursorPos;

		public Vec2 CursorPosPrevLine;

		public Vec2 CursorStartPos;

		public Vec2 CursorMaxPos;

		public float CurrLineHeight;

		public float PrevLineHeight;

		public float CurrLineTextBaseOffset;

		public float PrevLineTextBaseOffset;

		public bool IsSameLine;

		public float Indent;

		public float ItemWidthDefault;

		public readonly List<float> ItemWidthStack = new List<float>();

		public readonly List<float> TextWrapPosStack = new List<float>();

		public readonly List<GroupData> GroupStack = new List<GroupData>();

		public float ScrollY;

		public float ScrollMaxY;

		public float ContentHeight;

		public Vec2 ContentSize;

		public bool HasScrollbar;

		public float? ScrollTargetY;

		public float MaxHeight = float.MaxValue;

		public int LastFrameActive = -1;

		public int FirstFrame = -1;

		public bool Hidden;

		public int Order;

		public readonly List<Window> ChildrenThisFrame = new List<Window>();
	}
	internal struct PopupRef
	{
		public uint Id;

		public Vec2 OpenMousePos;

		public int OpenFrame;

		public Window Window;
	}
	public sealed class DrawData
	{
		public DrawVert[] Vtx = new DrawVert[4096];

		public int VtxCount;

		public int[] Idx = new int[8192];

		public int IdxCount;

		public readonly List<DrawCmd> Cmds = new List<DrawCmd>();

		public FontAtlas Atlas;

		internal void Clear()
		{
			VtxCount = 0;
			IdxCount = 0;
			Cmds.Clear();
		}

		internal void Append(DrawList dl)
		{
			if (dl.IdxCount == 0)
			{
				return;
			}
			if (VtxCount + dl.VtxCount > Vtx.Length)
			{
				Array.Resize(ref Vtx, Math.Max(Vtx.Length * 2, VtxCount + dl.VtxCount));
			}
			if (IdxCount + dl.IdxCount > Idx.Length)
			{
				Array.Resize(ref Idx, Math.Max(Idx.Length * 2, IdxCount + dl.IdxCount));
			}
			Array.Copy(dl.Vtx, 0, Vtx, VtxCount, dl.VtxCount);
			int vtxCount = VtxCount;
			for (int i = 0; i < dl.IdxCount; i++)
			{
				Idx[IdxCount + i] = dl.Idx[i] + vtxCount;
			}
			foreach (DrawCmd cmd in dl.Cmds)
			{
				if (cmd.IdxCount != 0)
				{
					RectF clip = cmd.Clip;
					if (!clip.IsEmpty)
					{
						Cmds.Add(new DrawCmd
						{
							Clip = cmd.Clip,
							IdxOffset = cmd.IdxOffset + IdxCount,
							IdxCount = cmd.IdxCount
						});
					}
				}
			}
			VtxCount += dl.VtxCount;
			IdxCount += dl.IdxCount;
		}
	}
	public sealed class Gui
	{
		public enum ButtonFlags
		{
			None = 0,
			PressedOnClick = 1,
			Repeat = 2,
			MouseRight = 4,
			AllowOverlap = 8
		}

		private sealed class TextEditState
		{
			public uint Id;

			public readonly StringBuilder Text = new StringBuilder();

			public string Initial = "";

			public int Cursor;

			public int Anchor;

			public float ScrollX;

			public float Blink;

			public bool Dragging;
		}

		public readonly Style Style = new Style();

		public readonly GuiIO IO = new GuiIO();

		public readonly DrawData DrawData = new DrawData();

		private readonly bool[] _mouseDownPrev = new bool[3];

		private readonly float[] _mouseDownDuration = new float[3] { -1f, -1f, -1f };

		private readonly float[] _mouseDownDurationPrev = new float[3] { -1f, -1f, -1f };

		private readonly double[] _mouseClickedTime = new double[3] { -10.0, -10.0, -10.0 };

		private readonly Vec2[] _mouseClickedPos = new Vec2[3];

		public readonly bool[] MouseClicked = new bool[3];

		public readonly bool[] MouseReleased = new bool[3];

		public readonly bool[] MouseDoubleClicked = new bool[3];

		private Vec2 _mousePosPrev = new Vec2(-10000f, -10000f);

		private float _mouseStationaryTimer;

		private readonly Dictionary<GuiKey, float> _keyDownDuration = new Dictionary<GuiKey, float>();

		private readonly Dictionary<GuiKey, float> _keyDownDurationPrev = new Dictionary<GuiKey, float>();

		private uint _hoveredIdPrevFrame;

		private float _hoveredIdTimer;

		private uint _activeIdPrevFrame;

		private bool _activeIdIsAlive;

		private bool _activeIdJustActivated;

		private Window _activeIdWindow;

		public Vec2 ActiveIdClickOffset;

		private bool _lastItemHovered;

		private bool _lastItemHoveredRaw;

		private bool _lastItemEdited;

		private uint _keyboardOwner;

		private readonly Dictionary<uint, Window> _windows = new Dictionary<uint, Window>();

		private readonly List<Window> _windowStack = new List<Window>();

		private readonly List<Window> _rootsThisFrame = new List<Window>();

		private List<Window> _rootsPrevFrame = new List<Window>();

		private Window _current;

		private Window _hoveredWindow;

		private Window _hoveredRoot;

		private bool _blockInputThisFrame;

		private readonly List<DrawList> _freeLists = new List<DrawList>();

		private readonly List<DrawList> _usedLists = new List<DrawList>();

		private readonly List<PopupRef> _openPopups = new List<PopupRef>();

		private readonly List<uint> _beginPopupStack = new List<uint>();

		private readonly List<uint> _idStack = new List<uint>();

		private readonly Dictionary<uint, bool> _boolStorage = new Dictionary<uint, bool>();

		private readonly Dictionary<uint, float> _floatStorage = new Dictionary<uint, float>();

		private int _disabledDepth;

		private float _disabledAlphaBackup;

		private float _nextItemWidth = float.NaN;

		private bool? _nextItemOpen;

		private string _pendingTooltip;

		private uint _tooltipItem;

		private readonly List<bool> _disabledStack = new List<bool>();

		private DrawList _foregroundList;

		private int _foregroundFrame = -1;

		private readonly TextEditState _edit = new TextEditState();

		private readonly List<KeyValuePair<StyleCol, uint>> _colorStack = new List<KeyValuePair<StyleCol, uint>>();

		public Font Font { get; private set; }

		public FontAtlas Atlas { get; }

		public float FontSize => Font.Size;

		public int FrameCount { get; private set; }

		public double Time { get; private set; }

		public Vec2 MouseDelta { get; private set; }

		public uint HoveredId { get; private set; }

		public uint ActiveId { get; private set; }

		public uint LastItemId { get; private set; }

		public RectF LastItemRect { get; private set; }

		public bool IsActiveIdJustActivated => _activeIdJustActivated;

		public bool IsAnyItemActive => ActiveId != 0;

		public bool IsAnyWindowHovered => _hoveredRoot != null;

		public bool IsAnyPopupOpen => _openPopups.Count > 0;

		public bool IsDisabled => _disabledDepth > 0;

		internal DrawList WindowDrawList => _current.Dl;

		public Gui(FontAtlas atlas)
		{
			Atlas = atlas;
		}

		public void SetFont(Font font)
		{
			Font = font;
		}

		public void NewFrame()
		{
			if (Font == null)
			{
				throw new InvalidOperationException("SetFont before NewFrame");
			}
			FrameCount++;
			Time += IO.DeltaTime;
			MouseDelta = ((IsMousePosValid(IO.MousePos) && IsMousePosValid(_mousePosPrev)) ? (IO.MousePos - _mousePosPrev) : Vec2.Zero);
			if (Math.Abs(MouseDelta.X) > 0.5f || Math.Abs(MouseDelta.Y) > 0.5f)
			{
				_mouseStationaryTimer = 0f;
			}
			else
			{
				_mouseStationaryTimer += IO.DeltaTime;
			}
			_mousePosPrev = IO.MousePos;
			for (int i = 0; i < 3; i++)
			{
				bool flag = IO.MouseDown[i];
				MouseClicked[i] = flag && !_mouseDownPrev[i];
				MouseReleased[i] = !flag && _mouseDownPrev[i];
				_mouseDownDurationPrev[i] = _mouseDownDuration[i];
				_mouseDownDuration[i] = ((!flag) ? (-1f) : ((_mouseDownDuration[i] < 0f) ? 0f : (_mouseDownDuration[i] + IO.DeltaTime)));
				MouseDoubleClicked[i] = false;
				if (MouseClicked[i])
				{
					Vec2 vec = IO.MousePos - _mouseClickedPos[i];
					if (Time - _mouseClickedTime[i] < (double)IO.MouseDoubleClickTime && vec.X * vec.X + vec.Y * vec.Y < IO.MouseDoubleClickMaxDist * IO.MouseDoubleClickMaxDist)
					{
						MouseDoubleClicked[i] = true;
						_mouseClickedTime[i] = -10.0;
					}
					else
					{
						_mouseClickedTime[i] = Time;
					}
					_mouseClickedPos[i] = IO.MousePos;
				}
				_mouseDownPrev[i] = flag;
			}
			_keyDownDurationPrev.Clear();
			foreach (KeyValuePair<GuiKey, float> item in _keyDownDuration)
			{
				_keyDownDurationPrev[item.Key] = item.Value;
			}
			foreach (GuiKey item2 in new List<GuiKey>(_keyDownDuration.Keys))
			{
				if (!IO.KeysDown.Contains(item2))
				{
					_keyDownDuration.Remove(item2);
				}
			}
			foreach (GuiKey item3 in IO.KeysDown)
			{
				_keyDownDuration[item3] = (_keyDownDuration.TryGetValue(item3, out var value) ? (value + IO.DeltaTime) : 0f);
			}
			if (HoveredId != 0 && HoveredId == _hoveredIdPrevFrame)
			{
				_hoveredIdTimer += IO.DeltaTime;
			}
			else
			{
				_hoveredIdTimer = 0f;
			}
			_hoveredIdPrevFrame = HoveredId;
			HoveredId = 0u;
			_activeIdPrevFrame = ActiveId;
			_activeIdIsAlive = false;
			_activeIdJustActivated = false;
			_rootsPrevFrame = new List<Window>(_rootsThisFrame);
			_rootsThisFrame.Clear();
			_blockInputThisFrame = false;
			UpdateHoveredWindow();
			if ((MouseClicked[0] || MouseClicked[1]) && _openPopups.Count > 0)
			{
				int num = -1;
				for (int num2 = _openPopups.Count - 1; num2 >= 0; num2--)
				{
					Window window = _openPopups[num2].Window;
					if (window != null && _hoveredRoot == window)
					{
						num = num2;
						break;
					}
				}
				if (num < _openPopups.Count - 1)
				{
					_openPopups.RemoveRange(num + 1, _openPopups.Count - num - 1);
					if (num < 0)
					{
						_blockInputThisFrame = true;
						UpdateHoveredWindow();
					}
				}
			}
			_freeLists.AddRange(_usedLists);
			_usedLists.Clear();
			_idStack.Clear();
			_idStack.Add(2654435769u);
			_pendingTooltip = null;
			if (_disabledDepth > 0)
			{
				Style.Alpha = _disabledAlphaBackup;
			}
			_disabledDepth = 0;
			_disabledStack.Clear();
			LastItemId = 0u;
			IO.WantCaptureMouse = _hoveredRoot != null;
		}

		private static bool IsMousePosValid(Vec2 p)
		{
			if (p.X > -9000f)
			{
				return p.Y > -9000f;
			}
			return false;
		}

		private void UpdateHoveredWindow()
		{
			_hoveredWindow = null;
			_hoveredRoot = null;
			if (_blockInputThisFrame)
			{
				return;
			}
			Vec2 mousePos = IO.MousePos;
			for (int num = _rootsPrevFrame.Count - 1; num >= 0; num--)
			{
				Window window = _rootsPrevFrame[num];
				if ((window.Flags & WindowFlags.NoInputs) == 0 && !window.Hidden && (_openPopups.Count <= 0 || IsOpenPopupWindow(window)) && window.Rect.Contains(mousePos))
				{
					_hoveredRoot = window;
					_hoveredWindow = DeepestChildAt(window, mousePos);
					break;
				}
			}
		}

		private bool IsOpenPopupWindow(Window w)
		{
			foreach (PopupRef openPopup in _openPopups)
			{
				if (openPopup.Window == w)
				{
					return true;
				}
			}
			return false;
		}

		private static Window DeepestChildAt(Window w, Vec2 mouse)
		{
			for (int num = w.ChildrenThisFrame.Count - 1; num >= 0; num--)
			{
				Window window = w.ChildrenThisFrame[num];
				if (window.ClipRect.Contains(mouse) || window.Rect.Intersect(w.ClipRect).Contains(mouse))
				{
					return DeepestChildAt(window, mouse);
				}
			}
			return w;
		}

		public DrawData Render()
		{
			if (_pendingTooltip != null)
			{
				DrawTooltipWindow(_pendingTooltip);
			}
			if (ActiveId != 0 && !_activeIdIsAlive)
			{
				ClearActiveId();
			}
			for (int num = _openPopups.Count - 1; num >= 0; num--)
			{
				PopupRef popupRef = _openPopups[num];
				if (popupRef.OpenFrame < FrameCount && (popupRef.Window == null || popupRef.Window.LastFrameActive != FrameCount))
				{
					_openPopups.RemoveAt(num);
				}
			}
			DrawData.Clear();
			DrawData.Atlas = Atlas;
			for (int i = 0; i < _rootsThisFrame.Count; i++)
			{
				Window window = _rootsThisFrame[i];
				if (!window.Hidden)
				{
					DrawData.Append(window.BgDl);
					DrawData.Append(window.Dl);
				}
			}
			if (_foregroundList != null && _foregroundFrame == FrameCount)
			{
				DrawData.Append(_foregroundList);
			}
			IO.WantTextInput = _keyboardOwner != 0 && _keyboardOwner == ActiveId;
			IO.EndOfFrameReset();
			return DrawData;
		}

		private DrawList RentList()
		{
			DrawList drawList;
			if (_freeLists.Count > 0)
			{
				drawList = _freeLists[_freeLists.Count - 1];
				_freeLists.RemoveAt(_freeLists.Count - 1);
			}
			else
			{
				drawList = new DrawList();
			}
			drawList.Reset(Atlas, new RectF(0f, 0f, IO.DisplaySize.X, IO.DisplaySize.Y));
			_usedLists.Add(drawList);
			return drawList;
		}

		public bool IsMouseDown(int b)
		{
			return IO.MouseDown[b];
		}

		public bool IsMouseClicked(int b, bool repeat = false)
		{
			if (MouseClicked[b])
			{
				return true;
			}
			if (!repeat || !IO.MouseDown[b])
			{
				return false;
			}
			return RepeatAmount(_mouseDownDurationPrev[b], _mouseDownDuration[b]) > 0;
		}

		public bool IsMouseHoveringRect(RectF r)
		{
			return r.Contains(IO.MousePos);
		}

		public bool IsKeyDown(GuiKey k)
		{
			return IO.KeysDown.Contains(k);
		}

		public bool IsKeyPressed(GuiKey k, bool repeat = true)
		{
			if (!_keyDownDuration.TryGetValue(k, out var value))
			{
				return false;
			}
			if (value == 0f)
			{
				return true;
			}
			if (!repeat)
			{
				return false;
			}
			float value2;
			float tPrev = (_keyDownDurationPrev.TryGetValue(k, out value2) ? value2 : (-1f));
			return RepeatAmount(tPrev, value) > 0;
		}

		private int RepeatAmount(float tPrev, float t)
		{
			float keyRepeatDelay = IO.KeyRepeatDelay;
			float keyRepeatRate = IO.KeyRepeatRate;
			if (t == 0f)
			{
				return 1;
			}
			if (tPrev < 0f || t <= keyRepeatDelay)
			{
				return 0;
			}
			int num = ((tPrev < keyRepeatDelay) ? (-1) : ((int)((tPrev - keyRepeatDelay) / keyRepeatRate)));
			return (int)((t - keyRepeatDelay) / keyRepeatRate) - num;
		}

		public uint GetId(string label)
		{
			return Hash(label, _idStack[_idStack.Count - 1]);
		}

		public uint GetId(int n)
		{
			return HashInt(n, _idStack[_idStack.Count - 1]);
		}

		public void PushId(string s)
		{
			_idStack.Add(GetId(s));
		}

		public void PushId(int n)
		{
			_idStack.Add(GetId(n));
		}

		public void PopId()
		{
			_idStack.RemoveAt(_idStack.Count - 1);
		}

		private static uint Hash(string s, uint seed)
		{
			int num = 0;
			int num2 = s.IndexOf("###", StringComparison.Ordinal);
			if (num2 >= 0)
			{
				num = num2;
			}
			uint num3 = 0x811C9DC5u ^ seed;
			for (int i = num; i < s.Length; i++)
			{
				num3 ^= s[i];
				num3 *= 16777619;
			}
			if (num3 != 0)
			{
				return num3;
			}
			return 1u;
		}

		private static uint HashInt(int n, uint seed)
		{
			uint num = 0x811C9DC5u ^ seed;
			for (int i = 0; i < 4; i++)
			{
				num ^= (uint)((n >> i * 8) & 0xFF);
				num *= 16777619;
			}
			if (num != 0)
			{
				return num;
			}
			return 1u;
		}

		public static string LabelText(string label)
		{
			int num = label.IndexOf("##", StringComparison.Ordinal);
			if (num >= 0)
			{
				return label.Substring(0, num);
			}
			return label;
		}

		public bool GetBool(uint id, bool def)
		{
			if (!_boolStorage.TryGetValue(id, out var value))
			{
				return def;
			}
			return value;
		}

		public void SetBool(uint id, bool v)
		{
			_boolStorage[id] = v;
		}

		public float GetFloat(uint id, float def)
		{
			if (!_floatStorage.TryGetValue(id, out var value))
			{
				return def;
			}
			return value;
		}

		public void SetFloat(uint id, float v)
		{
			_floatStorage[id] = v;
		}

		public void SetActiveId(uint id)
		{
			ActiveId = id;
			_activeIdJustActivated = true;
			_activeIdIsAlive = true;
			_activeIdWindow = _current;
		}

		public void ClearActiveId()
		{
			ActiveId = 0u;
			_activeIdWindow = null;
			_keyboardOwner = 0u;
		}

		public void KeepAliveId(uint id)
		{
			if (ActiveId == id)
			{
				_activeIdIsAlive = true;
			}
		}

		public void MarkItemEdited(uint id)
		{
			_lastItemEdited = true;
			foreach (GroupData item in _current.GroupStack)
			{
				item.Edited = true;
			}
		}

		public bool IsItemHovered()
		{
			return _lastItemHovered;
		}

		public bool IsItemHoveredForTooltip()
		{
			if (!_lastItemHoveredRaw)
			{
				return false;
			}
			if (ActiveId != 0 && ActiveId != LastItemId)
			{
				return false;
			}
			if (_mouseStationaryTimer < Style.HoverStationaryDelay)
			{
				return false;
			}
			return true;
		}

		public bool IsItemActive()
		{
			if (LastItemId != 0)
			{
				return ActiveId == LastItemId;
			}
			return false;
		}

		public bool IsItemEdited()
		{
			return _lastItemEdited;
		}

		public bool IsItemClicked(int button = 0)
		{
			if (_lastItemHovered)
			{
				return MouseClicked[button];
			}
			return false;
		}

		public bool IsItemDeactivated()
		{
			if (LastItemId != 0 && _activeIdPrevFrame == LastItemId)
			{
				return ActiveId != LastItemId;
			}
			return false;
		}

		public bool IsWindowHovered()
		{
			if (_hoveredWindow != null && _current != null)
			{
				return _hoveredWindow.Root == _current.Root;
			}
			return false;
		}

		internal bool ItemHoverable(RectF bb, uint id)
		{
			if (_blockInputThisFrame)
			{
				return false;
			}
			if (_hoveredWindow != _current)
			{
				return false;
			}
			if (!bb.Intersect(_current.ClipRect).Contains(IO.MousePos))
			{
				return false;
			}
			if (ActiveId != 0 && ActiveId != id)
			{
				return false;
			}
			if (_disabledDepth > 0)
			{
				return false;
			}
			if (id != 0)
			{
				HoveredId = id;
			}
			return true;
		}

		private bool ItemHoveredRaw(RectF bb)
		{
			if (_blockInputThisFrame)
			{
				return false;
			}
			if (_hoveredWindow != _current)
			{
				return false;
			}
			return bb.Intersect(_current.ClipRect).Contains(IO.MousePos);
		}

		internal bool ItemAdd(RectF bb, uint id)
		{
			LastItemId = id;
			LastItemRect = bb;
			_lastItemEdited = false;
			_lastItemHoveredRaw = ItemHoveredRaw(bb);
			_lastItemHovered = _lastItemHoveredRaw && (ActiveId == 0 || ActiveId == id) && _disabledDepth == 0;
			if (id != 0)
			{
				KeepAliveId(id);
				foreach (GroupData item in _current.GroupStack)
				{
					if (_lastItemHovered)
					{
						item.Hovered = true;
					}
					if (ActiveId == id)
					{
						item.Active = true;
					}
					if (_activeIdPrevFrame == id && ActiveId != id)
					{
						item.Deactivated = true;
					}
				}
			}
			else if (_lastItemHovered)
			{
				foreach (GroupData item2 in _current.GroupStack)
				{
					item2.Hovered = true;
				}
			}
			if (!bb.Overlaps(_current.ClipRect))
			{
				if (id != 0)
				{
					if (id != ActiveId)
					{
						return id == _activeIdPrevFrame;
					}
					return true;
				}
				return false;
			}
			return true;
		}

		internal void ItemUpdateStatus(uint id)
		{
			_lastItemHovered = _lastItemHoveredRaw && (ActiveId == 0 || ActiveId == id) && _disabledDepth == 0;
			foreach (GroupData item in _current.GroupStack)
			{
				if (ActiveId == id && id != 0)
				{
					item.Active = true;
					if (_activeIdJustActivated)
					{
						item.ActivatedThisFrame = true;
					}
				}
				if (_lastItemHovered)
				{
					item.Hovered = true;
				}
			}
		}

		internal bool ButtonBehavior(RectF bb, uint id, out bool hovered, out bool held, ButtonFlags flags = ButtonFlags.None)
		{
			int num = (((flags & ButtonFlags.MouseRight) != 0) ? 1 : 0);
			hovered = ItemHoverable(bb, id);
			bool result = false;
			if (hovered && MouseClicked[num])
			{
				SetActiveId(id);
				ActiveIdClickOffset = IO.MousePos - bb.Min;
				if ((flags & ButtonFlags.PressedOnClick) != ButtonFlags.None || (flags & ButtonFlags.Repeat) != ButtonFlags.None)
				{
					result = true;
				}
			}
			if ((((flags & ButtonFlags.Repeat) != ButtonFlags.None && ActiveId == id && !MouseClicked[num]) & hovered) && IsMouseClicked(num, repeat: true))
			{
				result = true;
			}
			held = false;
			if (ActiveId == id)
			{
				if (IO.MouseDown[num])
				{
					held = true;
				}
				else
				{
					if (hovered && (flags & (ButtonFlags)3) == 0)
					{
						result = true;
					}
					ClearActiveId();
				}
			}
			ItemUpdateStatus(id);
			return result;
		}

		private Window GetOrCreateWindow(string name, uint id, WindowFlags flags)
		{
			if (!_windows.TryGetValue(id, out var value))
			{
				value = new Window
				{
					Id = id,
					Name = name,
					FirstFrame = FrameCount
				};
				_windows[id] = value;
			}
			value.Flags = flags;
			return value;
		}

		public void BeginWindow(string name, RectF rect, WindowFlags flags = WindowFlags.None, Vec2? padding = null)
		{
			uint id = Hash(name, 1374496523u);
			Window orCreateWindow = GetOrCreateWindow(name, id, flags);
			orCreateWindow.Parent = null;
			orCreateWindow.Root = orCreateWindow;
			orCreateWindow.Padding = padding ?? Style.WindowPadding;
			orCreateWindow.MaxHeight = float.MaxValue;
			orCreateWindow.Hidden = false;
			if ((flags & WindowFlags.AutoResize) != WindowFlags.None)
			{
				orCreateWindow.Hidden = orCreateWindow.LastFrameActive < FrameCount - 1;
				Vec2 vec = orCreateWindow.ContentSize + orCreateWindow.Padding * 2f;
				rect = new RectF(rect.X0, rect.Y0, rect.X0 + Math.Max(rect.Width, vec.X), rect.Y0 + vec.Y);
			}
			BeginRootCommon(orCreateWindow, rect);
		}

		private void BeginRootCommon(Window w, RectF rect)
		{
			w.Rect = rect;
			w.Dl = RentList();
			w.BgDl = RentList();
			w.LastFrameActive = FrameCount;
			w.ChildrenThisFrame.Clear();
			w.Order = _rootsThisFrame.Count;
			_rootsThisFrame.Add(w);
			SetupWindowLayout(w);
			DrawWindowBackground(w);
			w.Dl.PushClipRect(w.ClipRect, intersect: false);
			_windowStack.Add(w);
			_current = w;
			_idStack.Add(w.Id);
		}

		private void SetupWindowLayout(Window w)
		{
			float num = (((w.Flags & WindowFlags.Child) == 0) ? (((w.Flags & (WindowFlags.Popup | WindowFlags.Tooltip)) != WindowFlags.None) ? Style.PopupBorderSize : 0f) : (((w.Flags & WindowFlags.NoBackground) != WindowFlags.None) ? 0f : Style.ChildBorderSize));
			w.ScrollMaxY = Math.Max(0f, w.ContentHeight + w.Padding.Y * 2f - w.Rect.Height);
			w.HasScrollbar = (w.Flags & WindowFlags.NoScrollbar) == 0 && w.ScrollMaxY > 0f;
			if (w.ScrollTargetY.HasValue)
			{
				w.ScrollY = w.ScrollTargetY.Value;
				w.ScrollTargetY = null;
			}
			if (w.ScrollY > w.ScrollMaxY)
			{
				w.ScrollY = w.ScrollMaxY;
			}
			if (w.ScrollY < 0f)
			{
				w.ScrollY = 0f;
			}
			w.ScrollY = (float)Math.Round(w.ScrollY);
			float num2 = (w.HasScrollbar ? Style.ScrollbarSize : 0f);
			w.InnerRect = new RectF(w.Rect.X0 + num, w.Rect.Y0 + num, w.Rect.X1 - num - num2, w.Rect.Y1 - num);
			float num3 = Math.Max(0f, (float)Math.Floor(w.Padding.X * 0.5f) - num);
			w.ClipRect = new RectF((float)Math.Round(w.InnerRect.X0 + num3), (float)Math.Round(w.InnerRect.Y0), (float)Math.Round(w.InnerRect.X1 - (w.HasScrollbar ? 0f : num3)), (float)Math.Round(w.InnerRect.Y1));
			if (w.Parent != null)
			{
				w.ClipRect = w.ClipRect.Intersect(w.Parent.ClipRect);
			}
			w.WorkRect = new RectF(w.InnerRect.X0 + w.Padding.X - num, w.InnerRect.Y0 + w.Padding.Y - num, w.InnerRect.X1 - w.Padding.X + num, w.InnerRect.Y1 - w.Padding.Y + num);
			if (w.HasScrollbar)
			{
				w.WorkRect.X1 = w.InnerRect.X1 - w.Padding.X + ((num > 0f) ? num : 0f);
			}
			w.CursorStartPos = new Vec2((float)Math.Round(w.Rect.X0 + w.Padding.X), (float)Math.Round(w.Rect.Y0 + w.Padding.Y - w.ScrollY));
			w.CursorPos = w.CursorStartPos;
			w.CursorPosPrevLine = w.CursorPos;
			w.CursorMaxPos = w.CursorStartPos;
			w.CurrLineHeight = (w.PrevLineHeight = 0f);
			w.CurrLineTextBaseOffset = (w.PrevLineTextBaseOffset = 0f);
			w.IsSameLine = false;
			w.Indent = 0f;
			w.ItemWidthStack.Clear();
			w.TextWrapPosStack.Clear();
			w.GroupStack.Clear();
			w.ItemWidthDefault = (((w.Flags & (WindowFlags.AutoResize | WindowFlags.Popup | WindowFlags.Tooltip)) != WindowFlags.None) ? ((float)Math.Floor(FontSize * 16f)) : ((float)Math.Max(1.0, Math.Floor(w.Rect.Width * 0.65f))));
		}

		private void DrawWindowBackground(Window w)
		{
			if ((w.Flags & WindowFlags.NoBackground) == 0)
			{
				DrawList drawList = (((w.Flags & WindowFlags.Child) != WindowFlags.None) ? w.Dl : w.BgDl);
				uint color;
				float rounding;
				if ((w.Flags & WindowFlags.Child) != WindowFlags.None)
				{
					color = GetColor(((w.Flags & WindowFlags.FrameStyle) != WindowFlags.None) ? StyleCol.FrameBg : StyleCol.ChildBg);
					rounding = (((w.Flags & WindowFlags.FrameStyle) != WindowFlags.None) ? Style.FrameRounding : Style.ChildRounding);
				}
				else if ((w.Flags & (WindowFlags.Popup | WindowFlags.Tooltip)) != WindowFlags.None)
				{
					color = GetColor(StyleCol.PopupBg);
					rounding = Style.PopupRounding;
				}
				else
				{
					color = GetColor(StyleCol.WindowBg);
					rounding = Style.WindowRounding;
				}
				drawList.AddRectFilled(w.Rect, color, rounding);
				if (((w.Flags & WindowFlags.Child) != WindowFlags.None && (w.Flags & WindowFlags.FrameStyle) == 0 && Style.ChildBorderSize > 0f) || ((w.Flags & (WindowFlags.Popup | WindowFlags.Tooltip)) != WindowFlags.None && Style.PopupBorderSize > 0f))
				{
					drawList.AddRect(w.Rect, GetColor(StyleCol.Border), rounding);
				}
			}
		}

		public void EndWindow()
		{
			Window current = _current;
			FinishWindowContent(current);
			current.Dl.PopClipRect();
			if (current.HasScrollbar)
			{
				Scrollbar(current);
			}
			_windowStack.RemoveAt(_windowStack.Count - 1);
			_idStack.RemoveAt(_idStack.Count - 1);
			_current = ((_windowStack.Count > 0) ? _windowStack[_windowStack.Count - 1] : null);
		}

		private void FinishWindowContent(Window w)
		{
			float val = w.CursorMaxPos.Y - w.CursorStartPos.Y;
			float val2 = w.CursorMaxPos.X - w.CursorStartPos.X;
			w.ContentHeight = Math.Max(0f, val);
			w.ContentSize = new Vec2(Math.Max(0f, val2), Math.Max(0f, val));
			if (IO.MouseWheel != 0f && !IO.KeyCtrl && _hoveredWindow == w)
			{
				Window window = w;
				while (window != null && (window.ScrollMaxY <= 0f || (window.Flags & WindowFlags.NoScrollbar) != WindowFlags.None))
				{
					window = window.Parent;
				}
				if (window != null)
				{
					float num = (float)Math.Floor(Math.Min(5f * FontSize, window.InnerRect.Height * 0.67f));
					window.ScrollTargetY = Math.Max(0f, Math.Min(window.ScrollMaxY, window.ScrollY - IO.MouseWheel * num));
					IO.MouseWheel = 0f;
				}
			}
		}

		private void Scrollbar(Window w)
		{
			uint num = Hash("#SCROLLY", w.Id);
			RectF r = new RectF(w.InnerRect.X1, w.InnerRect.Y0, w.InnerRect.X1 + Style.ScrollbarSize, w.InnerRect.Y1);
			DrawList dl = w.Dl;
			dl.PushClipRect(r.Expand(1f), intersect: false);
			dl.AddRectFilled(r, GetColor(StyleCol.ScrollbarBg), Style.WindowRounding);
			float scrollbarPadding = Style.ScrollbarPadding;
			RectF rectF = new RectF(r.X0 + scrollbarPadding, r.Y0 + scrollbarPadding, r.X1 - scrollbarPadding, r.Y1 - scrollbarPadding);
			float height = w.InnerRect.Height;
			float num2 = Math.Max(height, w.ContentHeight + w.Padding.Y * 2f);
			float num3 = Math.Max(Math.Min(Style.GrabMinSize, rectF.Height), rectF.Height * height / num2);
			float num4 = Math.Max(1f, w.ScrollMaxY);
			Window current = _current;
			_current = w;
			bool flag = !_blockInputThisFrame && _hoveredWindow == w && r.Contains(IO.MousePos) && (ActiveId == 0 || ActiveId == num);
			if (flag && MouseClicked[0])
			{
				SetActiveId(num);
				float num5 = rectF.Y0 + (rectF.Height - num3) * (w.ScrollY / num4);
				ActiveIdClickOffset = ((IO.MousePos.Y >= num5 && IO.MousePos.Y < num5 + num3) ? new Vec2(0f, IO.MousePos.Y - num5) : new Vec2(0f, num3 * 0.5f));
			}
			bool flag2 = false;
			if (ActiveId == num)
			{
				KeepAliveId(num);
				if (IO.MouseDown[0])
				{
					flag2 = true;
					float num6 = (IO.MousePos.Y - ActiveIdClickOffset.Y - rectF.Y0) / Math.Max(1f, rectF.Height - num3);
					if (num6 < 0f)
					{
						num6 = 0f;
					}
					if (num6 > 1f)
					{
						num6 = 1f;
					}
					w.ScrollTargetY = (float)Math.Round(num6 * w.ScrollMaxY);
				}
				else
				{
					ClearActiveId();
				}
			}
			_current = current;
			float num7 = w.ScrollTargetY ?? w.ScrollY;
			float num8 = rectF.Y0 + (rectF.Height - num3) * (num7 / num4);
			dl.AddRectFilled(col: GetColor(flag2 ? StyleCol.ScrollbarGrabActive : (flag ? StyleCol.ScrollbarGrabHovered : StyleCol.ScrollbarGrab)), r: new RectF(rectF.X0, num8, rectF.X1, num8 + num3), rounding: Style.ScrollbarRounding);
			dl.PopClipRect();
		}

		public bool BeginChild(string strId, Vec2 size, bool border, WindowFlags extra = WindowFlags.None, Vec2? padding = null)
		{
			Window current = _current;
			uint id = GetId(strId);
			Vec2 contentRegionAvail = GetContentRegionAvail();
			if (size.X <= 0f)
			{
				size.X = Math.Max(4f, contentRegionAvail.X + size.X);
			}
			if (size.Y <= 0f)
			{
				size.Y = Math.Max(4f, contentRegionAvail.Y + size.Y);
			}
			Vec2 cursorPos = current.CursorPos;
			RectF rectF = new RectF((float)Math.Round(cursorPos.X), (float)Math.Round(cursorPos.Y), (float)Math.Round(cursorPos.X + size.X), (float)Math.Round(cursorPos.Y + size.Y));
			ItemSize(rectF.Size);
			ItemAdd(rectF, 0u);
			WindowFlags flags = (WindowFlags)((int)(WindowFlags.Child | extra) | ((!border) ? 2 : 0));
			Window orCreateWindow = GetOrCreateWindow(strId, id, flags);
			orCreateWindow.Parent = current;
			orCreateWindow.Root = current.Root;
			orCreateWindow.Padding = ((border || (extra & WindowFlags.FrameStyle) != WindowFlags.None) ? Style.WindowPadding : Vec2.Zero);
			if ((extra & WindowFlags.FrameStyle) != WindowFlags.None)
			{
				orCreateWindow.Padding = Style.FramePadding;
			}
			if (padding.HasValue)
			{
				orCreateWindow.Padding = padding.Value;
			}
			orCreateWindow.Rect = rectF;
			orCreateWindow.Dl = current.Dl;
			orCreateWindow.BgDl = null;
			orCreateWindow.LastFrameActive = FrameCount;
			orCreateWindow.ChildrenThisFrame.Clear();
			orCreateWindow.Hidden = false;
			current.ChildrenThisFrame.Add(orCreateWindow);
			SetupWindowLayout(orCreateWindow);
			DrawWindowBackground(orCreateWindow);
			orCreateWindow.Dl.PushClipRect(orCreateWindow.ClipRect, intersect: false);
			_windowStack.Add(orCreateWindow);
			_current = orCreateWindow;
			_idStack.Add(id);
			return rectF.Overlaps(current.ClipRect);
		}

		public void EndChild()
		{
			Window current = _current;
			FinishWindowContent(current);
			current.Dl.PopClipRect();
			if (current.HasScrollbar)
			{
				Scrollbar(current);
			}
			_windowStack.RemoveAt(_windowStack.Count - 1);
			_idStack.RemoveAt(_idStack.Count - 1);
			_current = _windowStack[_windowStack.Count - 1];
		}

		public void SetScrollHereY(float ratio = 0f)
		{
			Window current = _current;
			float num = current.CursorPosPrevLine.Y - Style.ItemSpacing.Y * 0.5f + current.ScrollY - current.CursorStartPos.Y;
			float num2 = current.InnerRect.Height - current.Padding.Y * 2f;
			current.ScrollTargetY = Math.Max(0f, num - num2 * ratio);
		}

		public float GetScrollY()
		{
			return _current.ScrollY;
		}

		public void SetScrollY(float y)
		{
			_current.ScrollTargetY = y;
		}

		public void OpenPopup(string strId)
		{
			uint id = GetId(strId);
			for (int i = 0; i < _openPopups.Count; i++)
			{
				if (_openPopups[i].Id == id)
				{
					_openPopups.RemoveRange(i + 1, _openPopups.Count - i - 1);
					PopupRef value = _openPopups[i];
					value.OpenMousePos = IO.MousePos;
					value.OpenFrame = FrameCount;
					_openPopups[i] = value;
					return;
				}
			}
			int count = _beginPopupStack.Count;
			if (_openPopups.Count > count)
			{
				_openPopups.RemoveRange(count, _openPopups.Count - count);
			}
			_openPopups.Add(new PopupRef
			{
				Id = id,
				OpenMousePos = IO.MousePos,
				OpenFrame = FrameCount
			});
		}

		public bool IsPopupOpen(string strId)
		{
			uint id = GetId(strId);
			foreach (PopupRef openPopup in _openPopups)
			{
				if (openPopup.Id == id)
				{
					return true;
				}
			}
			return false;
		}

		public void CloseCurrentPopup()
		{
			if (_beginPopupStack.Count == 0)
			{
				return;
			}
			uint num = _beginPopupStack[_beginPopupStack.Count - 1];
			for (int i = 0; i < _openPopups.Count; i++)
			{
				if (_openPopups[i].Id == num)
				{
					_openPopups.RemoveRange(i, _openPopups.Count - i);
					break;
				}
			}
		}

		public void CloseAllPopups()
		{
			_openPopups.Clear();
		}

		public bool BeginPopup(string strId, Vec2? pos = null, float minWidth = 0f, float maxHeight = float.MaxValue)
		{
			uint id = GetId(strId);
			int num = -1;
			for (int i = 0; i < _openPopups.Count; i++)
			{
				if (_openPopups[i].Id == id)
				{
					num = i;
					break;
				}
			}
			if (num < 0)
			{
				return false;
			}
			PopupRef value = _openPopups[num];
			Window orCreateWindow = GetOrCreateWindow(strId, id, WindowFlags.Popup);
			orCreateWindow.Parent = null;
			orCreateWindow.Root = orCreateWindow;
			orCreateWindow.Padding = Style.WindowPadding;
			orCreateWindow.Hidden = orCreateWindow.LastFrameActive < FrameCount - 1;
			float num2 = orCreateWindow.ContentSize.Y + orCreateWindow.Padding.Y * 2f;
			float num3 = Math.Min(num2, maxHeight);
			float num4 = Math.Max(minWidth, orCreateWindow.ContentSize.X + orCreateWindow.Padding.X * 2f + ((num2 > maxHeight) ? Style.ScrollbarSize : 0f));
			Vec2 vec = pos ?? value.OpenMousePos;
			Vec2 displaySize = IO.DisplaySize;
			if (vec.X + num4 > displaySize.X - 3f)
			{
				vec.X = Math.Max(3f, displaySize.X - 3f - num4);
			}
			if (vec.Y + num3 > displaySize.Y - 3f)
			{
				float num5 = (pos.HasValue ? (pos.Value.Y - FrameHeight() - num3) : (-1f));
				vec.Y = ((num5 >= 3f) ? num5 : Math.Max(3f, displaySize.Y - 3f - num3));
			}
			RectF rect = new RectF((float)Math.Round(vec.X), (float)Math.Round(vec.Y), (float)Math.Round(vec.X + num4), (float)Math.Round(vec.Y + num3));
			value.Window = orCreateWindow;
			_openPopups[num] = value;
			_beginPopupStack.Add(id);
			BeginRootCommon(orCreateWindow, rect);
			return true;
		}

		public void EndPopup()
		{
			EndWindow();
			_beginPopupStack.RemoveAt(_beginPopupStack.Count - 1);
		}

		public bool BeginPopupContextItem(string strId)
		{
			if (_lastItemHoveredRaw && MouseReleased[1] && _disabledDepth == 0)
			{
				OpenPopup(strId);
			}
			return BeginPopup(strId);
		}

		public void SetItemTooltip(string text)
		{
			if (!string.IsNullOrEmpty(text) && IsItemHoveredForTooltip())
			{
				SetTooltip(text);
			}
		}

		public void SetTooltip(string text)
		{
			_pendingTooltip = text;
			_tooltipItem = LastItemId;
		}

		private void DrawTooltipWindow(string text)
		{
			Window orCreateWindow = GetOrCreateWindow("##Tooltip", 28673u, WindowFlags.NoInputs | WindowFlags.Tooltip);
			orCreateWindow.Parent = null;
			orCreateWindow.Root = orCreateWindow;
			orCreateWindow.Padding = Style.WindowPadding;
			orCreateWindow.Hidden = orCreateWindow.LastFrameActive < FrameCount - 1;
			Vec2 vec = orCreateWindow.ContentSize + orCreateWindow.Padding * 2f;
			Vec2 vec2 = IO.MousePos + new Vec2(16f, 10f);
			if (vec2.X + vec.X > IO.DisplaySize.X)
			{
				vec2.X = Math.Max(0f, IO.MousePos.X - vec.X - 4f);
			}
			if (vec2.Y + vec.Y > IO.DisplaySize.Y)
			{
				vec2.Y = Math.Max(0f, IO.MousePos.Y - vec.Y - 4f);
			}
			Window current = _current;
			List<Window> collection = new List<Window>(_windowStack);
			_windowStack.Clear();
			BeginRootCommon(orCreateWindow, new RectF((float)Math.Round(vec2.X), (float)Math.Round(vec2.Y), (float)Math.Round(vec2.X + vec.X), (float)Math.Round(vec2.Y + vec.Y)));
			PushTextWrapPos(FontSize * 35f);
			TextUnformatted(text);
			PopTextWrapPos();
			EndWindow();
			_windowStack.AddRange(collection);
			_current = current;
		}

		public void BeginDisabled(bool disabled = true)
		{
			_disabledStack.Add(disabled);
			if (disabled)
			{
				if (_disabledDepth == 0)
				{
					_disabledAlphaBackup = Style.Alpha;
					Style.Alpha *= Style.DisabledAlpha;
				}
				_disabledDepth++;
			}
		}

		public void EndDisabled()
		{
			bool num = _disabledStack[_disabledStack.Count - 1];
			_disabledStack.RemoveAt(_disabledStack.Count - 1);
			if (num)
			{
				_disabledDepth--;
				if (_disabledDepth == 0)
				{
					Style.Alpha = _disabledAlphaBackup;
				}
			}
		}

		public uint GetColor(StyleCol c)
		{
			return Col.MulAlpha(Style.Colors[(int)c], Style.Alpha);
		}

		public uint GetColor(uint c)
		{
			return Col.MulAlpha(c, Style.Alpha);
		}

		public DrawList GetWindowDrawList()
		{
			return _current.Dl;
		}

		public DrawList GetForegroundDrawList()
		{
			if (_foregroundList == null || _foregroundFrame != FrameCount)
			{
				_foregroundList = RentList();
				_foregroundFrame = FrameCount;
			}
			return _foregroundList;
		}

		public bool InputText(string label, ref string value, string hint = null, InputTextFlags flags = InputTextFlags.None, float width = -1f)
		{
			uint id = GetId(label);
			string text = LabelText(label);
			Vec2 vec = CalcTextSize(text);
			float num = ((width >= 0f) ? width : ConsumeItemWidth());
			Vec2 cursorPos = _current.CursorPos;
			RectF rectF = new RectF(cursorPos.X, cursorPos.Y, cursorPos.X + num, cursorPos.Y + FrameHeight());
			RectF rectF2 = new RectF(rectF.X0, rectF.Y0, rectF.X1 + ((vec.X > 0f) ? (Style.ItemInnerSpacing.X + vec.X) : 0f), rectF.Y1);
			ItemSize(rectF2.Size, Style.FramePadding.Y);
			if (!ItemAdd(rectF, id))
			{
				return false;
			}
			if (ItemHoverable(rectF, id) && MouseClicked[0] && ActiveId != id && (flags & InputTextFlags.ReadOnly) == 0)
			{
				StartTextEdit(id, value ?? "", (flags & InputTextFlags.AutoSelectAll) != 0);
				if ((flags & InputTextFlags.AutoSelectAll) == 0)
				{
					PlaceCursorFromMouse(rectF, extend: false);
				}
			}
			bool result = false;
			if (ActiveId == id && _edit.Id == id)
			{
				Func<char, bool> filter = (((flags & InputTextFlags.CharsNumeric) != InputTextFlags.None) ? new Func<char, bool>(NumericFilter) : null);
				bool flag = (flags & InputTextFlags.Live) != 0;
				if (InputTextCore(id, rectF, out var committed, out var result2, filter, flag) && (flag || committed) && result2 != (value ?? ""))
				{
					value = result2;
					result = true;
					MarkItemEdited(id);
				}
			}
			else
			{
				RenderFrame(rectF, GetColor(StyleCol.FrameBg));
				string text2 = value ?? "";
				Vec2 pos = new Vec2(rectF.X0 + Style.FramePadding.X, rectF.Y0 + Style.FramePadding.Y);
				_current.Dl.PushClipRect(rectF);
				if (text2.Length == 0 && !string.IsNullOrEmpty(hint))
				{
					_current.Dl.AddText(Font, pos, GetColor(StyleCol.TextDisabled), hint);
				}
				else
				{
					_current.Dl.AddText(Font, pos, GetColor(StyleCol.Text), text2);
				}
				_current.Dl.PopClipRect();
			}
			ItemUpdateStatus(id);
			if (vec.X > 0f)
			{
				RenderText(new Vec2(rectF.X1 + Style.ItemInnerSpacing.X, rectF.Y0 + Style.FramePadding.Y), text, GetColor(StyleCol.Text));
			}
			return result;
		}

		internal void StartTextEdit(uint id, string initial, bool selectAll)
		{
			SetActiveId(id);
			_keyboardOwner = id;
			_edit.Id = id;
			_edit.Text.Length = 0;
			_edit.Text.Append(initial);
			_edit.Initial = initial;
			_edit.Cursor = initial.Length;
			_edit.Anchor = ((!selectAll) ? initial.Length : 0);
			_edit.ScrollX = 0f;
			_edit.Blink = -0.3f;
			_edit.Dragging = !selectAll;
		}

		private void PlaceCursorFromMouse(RectF frame, bool extend)
		{
			float num = IO.MousePos.X - (frame.X0 + Style.FramePadding.X) + _edit.ScrollX;
			int i = 0;
			float num2 = 0f;
			for (string text = _edit.Text.ToString(); i < text.Length; i++)
			{
				float num3 = Font.CharAdvance(text[i]);
				if (num2 + num3 * 0.5f > num)
				{
					break;
				}
				num2 += num3;
			}
			_edit.Cursor = i;
			if (!extend)
			{
				_edit.Anchor = i;
			}
			_edit.Blink = -0.3f;
		}

		internal bool InputTextCore(uint id, RectF frame, out bool committed, out string result, Func<char, bool> filter, bool live = false)
		{
			committed = false;
			TextEditState edit = _edit;
			KeepAliveId(id);
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			edit.Blink += IO.DeltaTime;
			bool flag4 = !_blockInputThisFrame && frame.Intersect(_current.ClipRect).Contains(IO.MousePos) && _hoveredWindow == _current;
			if (MouseClicked[0])
			{
				if (flag4)
				{
					if (MouseDoubleClicked[0])
					{
						edit.Anchor = 0;
						edit.Cursor = edit.Text.Length;
						edit.Dragging = false;
					}
					else if (!_activeIdJustActivated)
					{
						PlaceCursorFromMouse(frame, IO.KeyShift);
						edit.Dragging = true;
					}
				}
				else
				{
					flag = true;
				}
			}
			else if (edit.Dragging && IO.MouseDown[0])
			{
				PlaceCursorFromMouse(frame, extend: true);
			}
			if (!IO.MouseDown[0])
			{
				edit.Dragging = false;
			}
			if (!flag)
			{
				bool keyCtrl = IO.KeyCtrl;
				bool keyShift = IO.KeyShift;
				foreach (char inputChar in IO.InputChars)
				{
					if (inputChar >= ' ' && inputChar != '\u007f' && (filter == null || filter(inputChar)))
					{
						DeleteSelection(edit);
						edit.Text.Insert(edit.Cursor, inputChar);
						edit.Cursor++;
						edit.Anchor = edit.Cursor;
						flag3 = true;
					}
				}
				if (IsKeyPressed(GuiKey.Left))
				{
					MoveCursor(edit, keyCtrl ? WordLeft(edit) : ((HasSelection(edit) && !keyShift) ? Math.Min(edit.Cursor, edit.Anchor) : Math.Max(0, edit.Cursor - 1)), keyShift);
				}
				if (IsKeyPressed(GuiKey.Right))
				{
					MoveCursor(edit, keyCtrl ? WordRight(edit) : ((HasSelection(edit) && !keyShift) ? Math.Max(edit.Cursor, edit.Anchor) : Math.Min(edit.Text.Length, edit.Cursor + 1)), keyShift);
				}
				if (IsKeyPressed(GuiKey.Home))
				{
					MoveCursor(edit, 0, keyShift);
				}
				if (IsKeyPressed(GuiKey.End))
				{
					MoveCursor(edit, edit.Text.Length, keyShift);
				}
				if (IsKeyPressed(GuiKey.Backspace))
				{
					if (HasSelection(edit))
					{
						flag3 |= DeleteSelection(edit);
					}
					else if (edit.Cursor > 0)
					{
						int num = (keyCtrl ? WordLeft(edit) : (edit.Cursor - 1));
						edit.Text.Remove(num, edit.Cursor - num);
						edit.Cursor = (edit.Anchor = num);
						flag3 = true;
					}
				}
				if (IsKeyPressed(GuiKey.Delete))
				{
					if (HasSelection(edit))
					{
						flag3 |= DeleteSelection(edit);
					}
					else if (edit.Cursor < edit.Text.Length)
					{
						int num2 = (keyCtrl ? WordRight(edit) : (edit.Cursor + 1));
						edit.Text.Remove(edit.Cursor, num2 - edit.Cursor);
						flag3 = true;
					}
				}
				if (keyCtrl && IsKeyPressed(GuiKey.A, repeat: false))
				{
					edit.Anchor = 0;
					edit.Cursor = edit.Text.Length;
				}
				if (keyCtrl && (IsKeyPressed(GuiKey.C, repeat: false) || IsKeyPressed(GuiKey.X, repeat: false)) && HasSelection(edit))
				{
					int num3 = Math.Min(edit.Cursor, edit.Anchor);
					int num4 = Math.Max(edit.Cursor, edit.Anchor);
					IO.SetClipboard(edit.Text.ToString(num3, num4 - num3));
					if (IsKeyPressed(GuiKey.X, repeat: false))
					{
						flag3 |= DeleteSelection(edit);
					}
				}
				if (keyCtrl && IsKeyPressed(GuiKey.V))
				{
					string obj = IO.GetClipboard() ?? "";
					StringBuilder stringBuilder = new StringBuilder();
					string text = obj;
					foreach (char c in text)
					{
						if (c != '\r' && c != '\n' && c >= ' ' && (filter == null || filter(c)))
						{
							stringBuilder.Append(c);
						}
					}
					if (stringBuilder.Length > 0)
					{
						DeleteSelection(edit);
						edit.Text.Insert(edit.Cursor, stringBuilder.ToString());
						edit.Cursor += stringBuilder.Length;
						edit.Anchor = edit.Cursor;
						flag3 = true;
					}
				}
				if (keyCtrl && IsKeyPressed(GuiKey.Z, repeat: false))
				{
					edit.Text.Length = 0;
					edit.Text.Append(edit.Initial);
					edit.Cursor = (edit.Anchor = edit.Text.Length);
					flag3 = true;
				}
				if (IsKeyPressed(GuiKey.Enter, repeat: false) || IsKeyPressed(GuiKey.Tab, repeat: false))
				{
					flag = true;
				}
				if (IsKeyPressed(GuiKey.Escape, repeat: false))
				{
					flag = true;
					flag2 = true;
				}
				if (flag3)
				{
					edit.Blink = -0.3f;
				}
			}
			result = edit.Text.ToString();
			if (flag)
			{
				if (flag2)
				{
					result = edit.Initial;
					committed = false;
				}
				else
				{
					committed = true;
				}
				ClearActiveId();
			}
			DrawList dl = _current.Dl;
			RenderFrame(frame, GetColor(StyleCol.FrameBg));
			Vec2 vec = new Vec2(frame.X0 + Style.FramePadding.X, frame.Y0 + Style.FramePadding.Y);
			float num5 = frame.Width - Style.FramePadding.X * 2f;
			string text2 = edit.Text.ToString();
			float num6 = Font.CalcTextWidth(text2, 0, Math.Min(edit.Cursor, text2.Length));
			if (num6 < edit.ScrollX)
			{
				edit.ScrollX = Math.Max(0f, num6 - num5 * 0.25f);
			}
			else if (num6 - edit.ScrollX > num5)
			{
				edit.ScrollX = num6 - num5;
			}
			dl.PushClipRect(frame);
			Vec2 pos = new Vec2(vec.X - edit.ScrollX, vec.Y);
			if (!flag && HasSelection(edit))
			{
				int end = Math.Min(edit.Cursor, edit.Anchor);
				int end2 = Math.Max(edit.Cursor, edit.Anchor);
				float num7 = Font.CalcTextWidth(text2, 0, end);
				float num8 = Font.CalcTextWidth(text2, 0, end2);
				dl.PrimRect(pos.X + num7, pos.Y - 1f, pos.X + num8, pos.Y + FontSize + 2f, GetColor(StyleCol.TextSelectedBg));
			}
			dl.AddText(Font, pos, GetColor(StyleCol.Text), flag ? result : text2);
			if (!flag && (edit.Blink <= 0f || edit.Blink % 1.2f <= 0.8f))
			{
				float num9 = (float)Math.Floor(pos.X + num6);
				dl.PrimRect(num9, pos.Y + 0.5f, num9 + 1f, pos.Y + FontSize - 1.5f, GetColor(StyleCol.Text));
			}
			dl.PopClipRect();
			return (flag3 && live) || flag;
		}

		private static bool HasSelection(TextEditState st)
		{
			return st.Cursor != st.Anchor;
		}

		private static bool DeleteSelection(TextEditState st)
		{
			if (!HasSelection(st))
			{
				return false;
			}
			int num = Math.Min(st.Cursor, st.Anchor);
			int num2 = Math.Max(st.Cursor, st.Anchor);
			st.Text.Remove(num, num2 - num);
			st.Cursor = (st.Anchor = num);
			return true;
		}

		private static void MoveCursor(TextEditState st, int to, bool select)
		{
			st.Cursor = Math.Max(0, Math.Min(st.Text.Length, to));
			if (!select)
			{
				st.Anchor = st.Cursor;
			}
			st.Blink = -0.3f;
		}

		private static bool IsWordChar(char c)
		{
			if (!char.IsLetterOrDigit(c))
			{
				return c == '_';
			}
			return true;
		}

		private static int WordLeft(TextEditState st)
		{
			int num = st.Cursor;
			while (num > 0 && !IsWordChar(st.Text[num - 1]))
			{
				num--;
			}
			while (num > 0 && IsWordChar(st.Text[num - 1]))
			{
				num--;
			}
			return num;
		}

		private static int WordRight(TextEditState st)
		{
			int i = st.Cursor;
			int length;
			for (length = st.Text.Length; i < length && IsWordChar(st.Text[i]); i++)
			{
			}
			for (; i < length && !IsWordChar(st.Text[i]); i++)
			{
			}
			return i;
		}

		public bool KeyBox(string label, ref string value)
		{
			uint id = GetId(label);
			string text = LabelText(label);
			Vec2 vec = CalcTextSize(text);
			float num = ConsumeItemWidth();
			Vec2 cursorPos = _current.CursorPos;
			RectF rectF = new RectF(cursorPos.X, cursorPos.Y, cursorPos.X + num, cursorPos.Y + FrameHeight());
			RectF rectF2 = new RectF(rectF.X0, rectF.Y0, rectF.X1 + ((vec.X > 0f) ? (Style.ItemInnerSpacing.X + vec.X) : 0f), rectF.Y1);
			ItemSize(rectF2.Size, Style.FramePadding.Y);
			if (!ItemAdd(rectF, id))
			{
				return false;
			}
			bool flag = ItemHoverable(rectF, id);
			bool flag2 = false;
			if (flag && MouseClicked[0] && ActiveId != id)
			{
				SetActiveId(id);
				_keyboardOwner = id;
			}
			bool flag3 = ActiveId == id;
			if (flag3)
			{
				KeepAliveId(id);
				if (MouseClicked[0] && !flag && !_activeIdJustActivated)
				{
					ClearActiveId();
					flag3 = false;
				}
				else if (IO.KeyCodePressed != null)
				{
					string keyCodePressed = IO.KeyCodePressed;
					if (!(keyCodePressed == "Escape"))
					{
						if (keyCodePressed == "Backspace")
						{
							if ((value ?? "") != "")
							{
								value = "";
								flag2 = true;
							}
						}
						else
						{
							StringBuilder stringBuilder = new StringBuilder(keyCodePressed);
							foreach (string modifierKeyCode in IO.ModifierKeyCodes)
							{
								stringBuilder.Append(" + ").Append(modifierKeyCode);
							}
							string text2 = stringBuilder.ToString();
							if (text2 != value)
							{
								value = text2;
								flag2 = true;
							}
						}
					}
					ClearActiveId();
					flag3 = false;
				}
			}
			if (flag2)
			{
				MarkItemEdited(id);
			}
			ItemUpdateStatus(id);
			RenderFrame(rectF, GetColor(flag3 ? StyleCol.FrameBgActive : StyleCol.FrameBg));
			Vec2 pos = new Vec2(rectF.X0 + Style.FramePadding.X, rectF.Y0 + Style.FramePadding.Y);
			DrawList dl = _current.Dl;
			dl.PushClipRect(rectF);
			if (flag3)
			{
				dl.AddText(Font, pos, GetColor(StyleCol.TextDisabled), "Press a key... (Backspace clears, Esc cancels)");
			}
			else if (string.IsNullOrEmpty(value))
			{
				dl.AddText(Font, pos, GetColor(StyleCol.TextDisabled), "Click to set keyboard shortcut");
			}
			else
			{
				dl.AddText(Font, pos, GetColor(StyleCol.Text), value);
			}
			dl.PopClipRect();
			if (vec.X > 0f)
			{
				RenderText(new Vec2(rectF.X1 + Style.ItemInnerSpacing.X, rectF.Y0 + Style.FramePadding.Y), text, GetColor(StyleCol.Text));
			}
			if (!flag3 && flag && IsItemHoveredForTooltip())
			{
				SetTooltip("Click in the field and press any key to change the shortcut to that key or press backspace to remove the shortcut.");
			}
			return flag2;
		}

		public float FrameHeight()
		{
			return (float)Math.Round(FontSize + Style.FramePadding.Y * 2f);
		}

		public float FrameHeightWithSpacing()
		{
			return FrameHeight() + Style.ItemSpacing.Y;
		}

		public float TextLineHeight()
		{
			return FontSize;
		}

		public float TextLineHeightWithSpacing()
		{
			return FontSize + Style.ItemSpacing.Y;
		}

		public void ItemSize(Vec2 size, float textBaselineY = -1f)
		{
			Window current = _current;
			float num = ((textBaselineY >= 0f) ? Math.Max(0f, current.CurrLineTextBaseOffset - textBaselineY) : 0f);
			float num2 = (current.IsSameLine ? current.CursorPosPrevLine.Y : current.CursorPos.Y);
			float num3 = Math.Max(current.CurrLineHeight, current.CursorPos.Y - num2 + size.Y + num);
			current.CursorPosPrevLine = new Vec2(current.CursorPos.X + size.X, num2);
			current.CursorPos = new Vec2((float)Math.Round(current.Rect.X0 + current.Padding.X + current.Indent), (float)Math.Round(num2 + num3 + Style.ItemSpacing.Y));
			current.CursorMaxPos = new Vec2(Math.Max(current.CursorMaxPos.X, current.CursorPosPrevLine.X), Math.Max(current.CursorMaxPos.Y, current.CursorPos.Y - Style.ItemSpacing.Y));
			current.PrevLineHeight = num3;
			current.PrevLineTextBaseOffset = Math.Max(current.CurrLineTextBaseOffset, textBaselineY);
			current.CurrLineHeight = 0f;
			current.CurrLineTextBaseOffset = 0f;
			current.IsSameLine = false;
		}

		public void SameLine(float offsetFromStartX = 0f, float spacing = -1f)
		{
			Window current = _current;
			if (offsetFromStartX != 0f)
			{
				if (spacing < 0f)
				{
					spacing = 0f;
				}
				current.CursorPos = new Vec2(current.Rect.X0 + offsetFromStartX + spacing, current.CursorPosPrevLine.Y);
			}
			else
			{
				if (spacing < 0f)
				{
					spacing = Style.ItemSpacing.X;
				}
				current.CursorPos = new Vec2(current.CursorPosPrevLine.X + spacing, current.CursorPosPrevLine.Y);
			}
			current.CurrLineHeight = current.PrevLineHeight;
			current.CurrLineTextBaseOffset = current.PrevLineTextBaseOffset;
			current.IsSameLine = true;
		}

		public void NewLine()
		{
			if (_current.CurrLineHeight > 0f)
			{
				ItemSize(Vec2.Zero);
			}
			else
			{
				ItemSize(new Vec2(0f, FontSize));
			}
		}

		public void Spacing()
		{
			ItemSize(Vec2.Zero);
		}

		public void Dummy(Vec2 size)
		{
			RectF bb = RectF.FromSize(_current.CursorPos.X, _current.CursorPos.Y, size.X, size.Y);
			ItemSize(size);
			ItemAdd(bb, 0u);
		}

		public void Indent(float w = 0f)
		{
			_current.Indent += ((w > 0f) ? w : Style.IndentSpacing);
		}

		public void Unindent(float w = 0f)
		{
			_current.Indent -= ((w > 0f) ? w : Style.IndentSpacing);
			_current.CursorPos.X = (float)Math.Round(_current.Rect.X0 + _current.Padding.X + _current.Indent);
		}

		public Vec2 GetCursorScreenPos()
		{
			return _current.CursorPos;
		}

		public void SetCursorScreenPos(Vec2 p)
		{
			_current.CursorPos = p;
			_current.CursorMaxPos = new Vec2(Math.Max(_current.CursorMaxPos.X, p.X), Math.Max(_current.CursorMaxPos.Y, p.Y));
			_current.IsSameLine = false;
		}

		public float GetCursorPosX()
		{
			return _current.CursorPos.X - _current.Rect.X0;
		}

		public RectF GetWindowRect()
		{
			return _current.Rect;
		}

		public float GetContentRegionMaxX()
		{
			return _current.WorkRect.X1 - _current.Rect.X0;
		}

		public float GetWindowWidth()
		{
			return _current.Rect.Width;
		}

		public Vec2 GetContentRegionAvail()
		{
			Window current = _current;
			return new Vec2(current.WorkRect.X1 - current.CursorPos.X, current.WorkRect.Y1 - current.ScrollY - current.CursorPos.Y);
		}

		public float CalcItemWidth()
		{
			Window current = _current;
			float num = ((!float.IsNaN(_nextItemWidth)) ? _nextItemWidth : ((current.ItemWidthStack.Count <= 0) ? current.ItemWidthDefault : current.ItemWidthStack[current.ItemWidthStack.Count - 1]));
			if (num < 0f)
			{
				num = Math.Max(1f, GetContentRegionAvail().X + num);
			}
			return (float)Math.Floor(num);
		}

		private float ConsumeItemWidth()
		{
			float result = CalcItemWidth();
			_nextItemWidth = float.NaN;
			return result;
		}

		public void SetNextItemWidth(float width)
		{
			_nextItemWidth = width;
		}

		public void PushItemWidth(float width)
		{
			_current.ItemWidthStack.Add((width == 0f) ? _current.ItemWidthDefault : width);
		}

		public void PopItemWidth()
		{
			_current.ItemWidthStack.RemoveAt(_current.ItemWidthStack.Count - 1);
		}

		public void PushTextWrapPos(float wrapWidth = 0f)
		{
			_current.TextWrapPosStack.Add(wrapWidth);
		}

		public void PopTextWrapPos()
		{
			_current.TextWrapPosStack.RemoveAt(_current.TextWrapPosStack.Count - 1);
		}

		private float CurrentWrapWidth()
		{
			Window current = _current;
			if (current.TextWrapPosStack.Count == 0)
			{
				return 0f;
			}
			float num = current.TextWrapPosStack[current.TextWrapPosStack.Count - 1];
			if (num < 0f)
			{
				return 0f;
			}
			if (num == 0f)
			{
				return Math.Max(1f, current.WorkRect.X1 - current.CursorPos.X);
			}
			return num;
		}

		public void AlignTextToFramePadding()
		{
			Window current = _current;
			current.CurrLineHeight = Math.Max(current.CurrLineHeight, FontSize + Style.FramePadding.Y * 2f);
			current.CurrLineTextBaseOffset = Math.Max(current.CurrLineTextBaseOffset, Style.FramePadding.Y);
		}

		public void SetNextItemOpen(bool open)
		{
			_nextItemOpen = open;
		}

		public void BeginGroup()
		{
			Window current = _current;
			current.GroupStack.Add(new GroupData
			{
				BackupCursorPos = current.CursorPos,
				BackupCursorMaxPos = current.CursorMaxPos,
				BackupIndent = current.Indent,
				BackupCurrLineHeight = current.CurrLineHeight,
				BackupCurrLineTextBaseOffset = current.CurrLineTextBaseOffset
			});
			current.Indent = current.CursorPos.X - current.Rect.X0 - current.Padding.X;
			current.CursorMaxPos = current.CursorPos;
			current.CurrLineHeight = 0f;
		}

		public GroupResult EndGroup()
		{
			Window current = _current;
			GroupData groupData = current.GroupStack[current.GroupStack.Count - 1];
			current.GroupStack.RemoveAt(current.GroupStack.Count - 1);
			RectF rectF = new RectF(groupData.BackupCursorPos, new Vec2(Math.Max(current.CursorMaxPos.X, groupData.BackupCursorPos.X), Math.Max(current.CursorMaxPos.Y, groupData.BackupCursorPos.Y)));
			current.CursorPos = groupData.BackupCursorPos;
			current.CursorMaxPos = new Vec2(Math.Max(groupData.BackupCursorMaxPos.X, current.CursorMaxPos.X), Math.Max(groupData.BackupCursorMaxPos.Y, current.CursorMaxPos.Y));
			current.Indent = groupData.BackupIndent;
			current.CurrLineHeight = groupData.BackupCurrLineHeight;
			current.CurrLineTextBaseOffset = Math.Max(groupData.BackupCurrLineTextBaseOffset, current.PrevLineTextBaseOffset);
			current.IsSameLine = false;
			ItemSize(rectF.Size);
			LastItemId = 0u;
			LastItemRect = rectF;
			_lastItemHoveredRaw = ItemHoveredRaw(rectF);
			_lastItemHovered = groupData.Hovered;
			_lastItemEdited = groupData.Edited;
			foreach (GroupData item in current.GroupStack)
			{
				item.Hovered |= groupData.Hovered;
				item.Active |= groupData.Active;
				item.Deactivated |= groupData.Deactivated;
				item.Edited |= groupData.Edited;
				item.ActivatedThisFrame |= groupData.ActivatedThisFrame;
			}
			return new GroupResult
			{
				Hovered = groupData.Hovered,
				Active = groupData.Active,
				Deactivated = groupData.Deactivated,
				Edited = groupData.Edited,
				Activated = groupData.ActivatedThisFrame,
				Rect = rectF
			};
		}

		public Vec2 CalcTextSize(string text, bool hideAfterDoubleHash = false, float wrapWidth = 0f)
		{
			if (string.IsNullOrEmpty(text))
			{
				return new Vec2(0f, FontSize);
			}
			int num = text.Length;
			if (hideAfterDoubleHash)
			{
				int num2 = text.IndexOf("##", StringComparison.Ordinal);
				if (num2 >= 0)
				{
					num = num2;
				}
			}
			if (wrapWidth <= 0f)
			{
				int num3 = 1;
				bool flag = false;
				for (int i = 0; i < num; i++)
				{
					if (text[i] == '\n')
					{
						num3++;
						flag = true;
					}
					else if (text[i] != '\r')
					{
						flag = false;
					}
				}
				if (flag)
				{
					num3--;
				}
				return new Vec2((float)Math.Ceiling(Font.CalcTextWidth(text, 0, num)), (float)Math.Max(1, num3) * FontSize);
			}
			float num4 = 0f;
			int num5 = 0;
			int num6 = 0;
			while (num6 <= num)
			{
				int num7 = text.IndexOf('\n', num6, num - num6);
				if (num7 < 0)
				{
					num7 = num;
				}
				int num8 = num6;
				do
				{
					int num9 = Font.WrapPosition(text, num8, num7, wrapWidth);
					if (num8 == num7)
					{
						num9 = num7;
					}
					num4 = Math.Max(num4, Font.CalcTextWidth(text, num8, TrimRight(text, num8, num9)));
					num5++;
					num8 = Font.SkipBlanks(text, num9, num7);
				}
				while (num8 < num7);
				if (num7 == num)
				{
					break;
				}
				num6 = num7 + 1;
			}
			return new Vec2((float)Math.Ceiling(num4), (float)num5 * FontSize);
		}

		private static int TrimRight(string text, int start, int end)
		{
			while (end > start && (text[end - 1] == ' ' || text[end - 1] == '\t'))
			{
				end--;
			}
			return end;
		}

		internal void RenderText(Vec2 pos, string text, uint col, int start = 0, int end = -1, float wrapWidth = 0f)
		{
			_current.Dl.AddText(Font, pos, col, text, start, end, wrapWidth);
		}

		internal void RenderTextClipped(RectF bb, string text, Vec2 align, uint col, RectF? clip = null)
		{
			int num = text.IndexOf("##", StringComparison.Ordinal);
			if (num < 0)
			{
				num = text.Length;
			}
			if (num == 0)
			{
				return;
			}
			Vec2 vec = new Vec2(Font.CalcTextWidth(text, 0, num), FontSize);
			Vec2 min = bb.Min;
			if (align.X > 0f)
			{
				min.X = Math.Max(min.X, min.X + (bb.Width - vec.X) * align.X);
			}
			if (align.Y > 0f)
			{
				min.Y = Math.Max(min.Y, min.Y + (bb.Height - vec.Y) * align.Y);
			}
			RectF r = clip ?? bb;
			int num2;
			if (!(min.X + vec.X > r.X1) && !(min.Y + vec.Y > r.Y1))
			{
				num2 = ((min.X < r.X0) ? 1 : 0);
				if (num2 == 0)
				{
					goto IL_010e;
				}
			}
			else
			{
				num2 = 1;
			}
			_current.Dl.PushClipRect(r);
			goto IL_010e;
			IL_010e:
			_current.Dl.AddText(Font, min, col, text, 0, num);
			if (num2 != 0)
			{
				_current.Dl.PopClipRect();
			}
		}

		internal void RenderFrame(RectF bb, uint col, bool border = false, float rounding = -1f)
		{
			if (rounding < 0f)
			{
				rounding = Style.FrameRounding;
			}
			_current.Dl.AddRectFilled(bb, col, rounding);
		}

		internal void RenderArrow(DrawList dl, Vec2 pos, uint col, Dir dir, float scale = 1f)
		{
			float fontSize = FontSize;
			float num = fontSize * 0.4f * scale;
			Vec2 vec = pos + new Vec2(fontSize * 0.5f, fontSize * 0.5f * scale);
			Vec2 vec2;
			Vec2 vec3;
			Vec2 vec4;
			if ((uint)(dir - 2) <= 1u)
			{
				if (dir == Dir.Up)
				{
					num = 0f - num;
				}
				vec2 = new Vec2(0f, 0.75f) * num;
				vec3 = new Vec2(-0.866f, -0.75f) * num;
				vec4 = new Vec2(0.866f, -0.75f) * num;
			}
			else
			{
				if (dir == Dir.Left)
				{
					num = 0f - num;
				}
				vec2 = new Vec2(0.75f, 0f) * num;
				vec3 = new Vec2(-0.75f, 0.866f) * num;
				vec4 = new Vec2(-0.75f, -0.866f) * num;
			}
			dl.AddTriangleFilled(vec + vec2, vec + vec3, vec + vec4, col);
		}

		internal void RenderCheckMark(DrawList dl, Vec2 pos, uint col, float sz)
		{
			float num = Math.Max(sz / 5f, 1f);
			sz -= num * 0.5f;
			pos += new Vec2(num * 0.25f, num * 0.25f);
			float num2 = sz / 3f;
			float num3 = pos.X + num2;
			float num4 = pos.Y + sz - num2 * 0.5f;
			dl.PathLineTo(new Vec2(num3 - num2, num4 - num2));
			dl.PathLineTo(new Vec2(num3, num4));
			dl.PathLineTo(new Vec2(num3 + num2 * 2f, num4 - num2 * 2f));
			dl.PathStroke(col, closed: false, num);
		}

		internal void RenderBullet(DrawList dl, Vec2 pos, uint col)
		{
			dl.AddCircleFilled(pos, FontSize * 0.2f, col, (FontSize < 22f) ? 8 : ((FontSize < 40f) ? 12 : 0));
		}

		public void TextUnformatted(string text)
		{
			TextEx(text, GetColor(StyleCol.Text));
		}

		public void Text(string text)
		{
			TextEx(text, GetColor(StyleCol.Text));
		}

		public void TextDisabled(string text)
		{
			TextEx(text, GetColor(StyleCol.TextDisabled));
		}

		public void TextColored(uint col, string text)
		{
			TextEx(text, GetColor(col));
		}

		public void TextWrapped(string text)
		{
			PushTextWrapPos();
			TextEx(text, GetColor(StyleCol.Text));
			PopTextWrapPos();
		}

		public void TextWrappedColored(uint col, string text)
		{
			PushTextWrapPos();
			TextEx(text, GetColor(col));
			PopTextWrapPos();
		}

		private void TextEx(string text, uint col)
		{
			Window current = _current;
			float wrapWidth = CurrentWrapWidth();
			Vec2 pos = new Vec2(current.CursorPos.X, current.CursorPos.Y + current.CurrLineTextBaseOffset);
			Vec2 size = CalcTextSize(text ?? "", hideAfterDoubleHash: false, wrapWidth);
			RectF bb = RectF.FromSize(pos.X, pos.Y, size.X, size.Y);
			ItemSize(size, 0f);
			if (ItemAdd(bb, 0u))
			{
				current.Dl.AddText(Font, pos, col, text ?? "", 0, -1, wrapWidth);
			}
		}

		public void LabelText(string label, string value, float valueX)
		{
			TextUnformatted(label);
			SameLine(valueX);
			TextWrapped(value);
		}

		public void Bullet()
		{
			Window current = _current;
			float num = Math.Max(Math.Min(current.CurrLineHeight, FontSize + Style.FramePadding.Y * 2f), FontSize);
			RectF bb = RectF.FromSize(current.CursorPos.X, current.CursorPos.Y, FontSize, num);
			ItemSize(bb.Size);
			if (!ItemAdd(bb, 0u))
			{
				SameLine(0f, Style.FramePadding.X * 2f);
				return;
			}
			RenderBullet(current.Dl, new Vec2(bb.X0 + Style.FramePadding.X + FontSize * 0.5f, bb.Y0 + num * 0.5f), GetColor(StyleCol.Text));
			SameLine(0f, Style.FramePadding.X * 2f);
		}

		private Vec2 CalcItemSize(Vec2 size, float defaultW, float defaultH)
		{
			if (size.X == 0f)
			{
				size.X = defaultW;
			}
			else if (size.X < 0f)
			{
				size.X = Math.Max(4f, GetContentRegionAvail().X + size.X);
			}
			if (size.Y == 0f)
			{
				size.Y = defaultH;
			}
			else if (size.Y < 0f)
			{
				size.Y = Math.Max(4f, GetContentRegionAvail().Y + size.Y);
			}
			return size;
		}

		public bool Button(string label, Vec2 size = default(Vec2), ButtonFlags flags = ButtonFlags.None, Vec2? textAlign = null)
		{
			uint id = GetId(label);
			string text = LabelText(label);
			Vec2 vec = CalcTextSize(text);
			Vec2 cursorPos = _current.CursorPos;
			size = CalcItemSize(size, vec.X + Style.FramePadding.X * 2f, vec.Y + Style.FramePadding.Y * 2f);
			RectF bb = new RectF(cursorPos, cursorPos + size);
			ItemSize(size, Style.FramePadding.Y);
			if (!ItemAdd(bb, id))
			{
				return false;
			}
			bool hovered;
			bool held;
			bool result = ButtonBehavior(bb, id, out hovered, out held, flags);
			RenderFrame(col: GetColor((held && hovered) ? StyleCol.ButtonActive : (hovered ? StyleCol.ButtonHovered : StyleCol.Button)), bb: bb);
			RectF bb2 = new RectF(bb.X0 + Style.FramePadding.X, bb.Y0 + Style.FramePadding.Y, bb.X1 - Style.FramePadding.X, bb.Y1 - Style.FramePadding.Y);
			RenderTextClipped(bb2, text, textAlign ?? new Vec2(0.5f, 0.5f), GetColor(StyleCol.Text));
			return result;
		}

		public bool ToggleButton(string label, ref bool on, float width = 0f)
		{
			if (on)
			{
				PushColor(StyleCol.Button, Style.Colors[21]);
			}
			bool num = Button(label, new Vec2(width, 0f));
			if (on)
			{
				PopColor();
			}
			if (num)
			{
				on = !on;
			}
			return num;
		}

		public bool SmallButton(string label)
		{
			Vec2 framePadding = Style.FramePadding;
			Style.FramePadding = new Vec2(framePadding.X, 0f);
			bool result = Button(label);
			Style.FramePadding = framePadding;
			return result;
		}

		public bool ArrowButton(string strId, Dir dir, Vec2 size = default(Vec2), ButtonFlags flags = ButtonFlags.None)
		{
			uint id = GetId(strId);
			float num = FrameHeight();
			if (size.X <= 0f)
			{
				size = new Vec2(num, num);
			}
			Vec2 cursorPos = _current.CursorPos;
			RectF bb = new RectF(cursorPos, cursorPos + size);
			ItemSize(size, (size.Y >= FrameHeight()) ? Style.FramePadding.Y : (-1f));
			if (