<commit_before>﻿using System;
using Terraria;
using Terraria.UI;
using HamstarHelpers.Classes.UI.Theme;


namespace HamstarHelpers.Classes.UI.Elements {
	/// <summary>
	/// Defines a UI dialog (stand-alone, centered panel) element. All dialogs are modal, and exclusively capture all
	/// interactions until closed.
	/// </summary>
	public abstract partial class UIDialog : UIThemedState {
		/// <summary>
		/// Intended to replace `Recalculate()` for technical reasons (accomodates 'backend' `UserInterface`). Recalculates
		/// positions of dialog elements.
		/// </summary>
		public virtual void RecalculateMe() {	// Call this instead of Recalculate
			if( this.Backend != null ) {
				this.Backend.Recalculate();
			} else {
				this.Recalculate();
			}
		}

		/// @private
		[Obsolete("use RecalculateMe()")]
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
		public sealed override void Recalculate() {
			if( this.OuterContainer != null ) {
				this.RefreshOuterContainerPosition();
			}

			base.Recalculate();
		}
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member


		////////////////

		/// <summary>
		/// Recalculates position of outer container
		/// </summary>
		public void RefreshOuterContainerPosition() {
			CalculatedStyle dim = this.OuterContainer.GetOuterDimensions();
			float offsetX = this.LeftPixels;
			float offsetY = this.TopPixels;

			offsetX -= dim.Width * this.OriginPercentHorizontal;
			offsetY -= dim.Height * this.OriginPercentVertical;
			
			this.OuterContainer.Left.Set( offsetX, this.LeftPercent );
			this.OuterContainer.Top.Set( offsetY, this.TopPercent );
		}


		////////////////

		/// <summary>
		/// Repositions the dialog horizontally (via standard `StyleDimension.Set(...)`).
		/// </summary>
		/// <param name="pixels">Pixel amount from the left.</param>
		/// <param name="percent">Percent amount from the left.</param>
		/// <param name="originPercent">Adjusts the position within the panel to align upon.</param>
		public void SetLeftPosition( float pixels, float percent, float originPercent = 0.5f ) {
			this.LeftPixels = pixels;
			this.LeftPercent = percent;
			this.OriginPercentHorizontal = originPercent;

			this.RefreshOuterContainerPosition();
			this.RecalculateMe();
		}

		/// <summary>
		/// Repositions the dialog vertically (via standard `StyleDimension.Set(...)`).
		/// </summary>
		/// <param name="pixels">Pixel amount from the top.</param>
		/// <param name="percent">Percent amount from the top.</param>
		/// <param name="originPercent">Adjusts the position within the panel to align upon.</param>
		public void SetTopPosition( float pixels, float percent, float originPercent = 0.5f ) {
			this.TopPixels = pixels;
			this.TopPercent = percent;
			this.OriginPercentVertical = originPercent;

			this.RefreshOuterContainerPosition();
			this.RecalculateMe();
		}
	}
}<commit_msg>v5.7.4 - Removed recalc from UIDialog.SetLeftPosition, SetTopPosition<commit_after>﻿using System;
using Terraria;
using Terraria.UI;
using HamstarHelpers.Classes.UI.Theme;


namespace HamstarHelpers.Classes.UI.Elements {
	/// <summary>
	/// Defines a UI dialog (stand-alone, centered panel) element. All dialogs are modal, and exclusively capture all
	/// interactions until closed.
	/// </summary>
	public abstract partial class UIDialog : UIThemedState {
		/// <summary>
		/// Intended to replace `Recalculate()` for technical reasons (accomodates 'backend' `UserInterface`). Recalculates
		/// positions of dialog elements.
		/// </summary>
		public virtual void RecalculateMe() {	// Call this instead of Recalculate
			if( this.Backend != null ) {
				this.Backend.Recalculate();
			} else {
				this.Recalculate();
			}
		}

		/// @private
		[Obsolete("use RecalculateMe()")]
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
		public sealed override void Recalculate() {
			if( this.OuterContainer != null ) {
				this.RefreshOuterContainerPosition();
			}

			base.Recalculate();
		}
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member


		////////////////

		/// <summary>
		/// Recalculates position of outer container
		/// </summary>
		public void RefreshOuterContainerPosition() {
			CalculatedStyle dim = this.OuterContainer.GetOuterDimensions();
			float offsetX = this.LeftPixels;
			float offsetY = this.TopPixels;

			offsetX -= dim.Width * this.OriginPercentHorizontal;
			offsetY -= dim.Height * this.OriginPercentVertical;
			
			this.OuterContainer.Left.Set( offsetX, this.LeftPercent );
			this.OuterContainer.Top.Set( offsetY, this.TopPercent );
		}


		////////////////

		/// <summary>
		/// Repositions the dialog horizontally (via standard `StyleDimension.Set(...)`). Dialog layout is not recalculated.
		/// </summary>
		/// <param name="pixels">Pixel amount from the left.</param>
		/// <param name="percent">Percent amount from the left.</param>
		/// <param name="originPercent">Adjusts the position within the panel to align upon.</param>
		public void SetLeftPosition( float pixels, float percent, float originPercent = 0.5f ) {
			this.LeftPixels = pixels;
			this.LeftPercent = percent;
			this.OriginPercentHorizontal = originPercent;
		}

		/// <summary>
		/// Repositions the dialog vertically (via standard `StyleDimension.Set(...)`). Dialog layout is not recalculated.
		/// </summary>
		/// <param name="pixels">Pixel amount from the top.</param>
		/// <param name="percent">Percent amount from the top.</param>
		/// <param name="originPercent">Adjusts the position within the panel to align upon.</param>
		public void SetTopPosition( float pixels, float percent, float originPercent = 0.5f ) {
			this.TopPixels = pixels;
			this.TopPercent = percent;
			this.OriginPercentVertical = originPercent;
		}
	}
}
{'fraction_non_alphanumeric': 0.1350841057329214, 'fraction_numerical': 0.004634397528321318, 'mean_word_length': 3.4110522331566995, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6944709', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1661, 'n_words': 469}