Skip to content

Commit

Permalink
update splitter distances to percentage to fix issues on initializati…
Browse files Browse the repository at this point in the history
…on if window sizes do not match when the configuration was written
  • Loading branch information
nstlaurent committed Jul 14, 2023
1 parent 2ae5a10 commit 6a42a90
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
12 changes: 6 additions & 6 deletions DoomLauncher/Config/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ private void Refresh(bool throwErrors)
CleanTemp = Convert.ToBoolean(GetValue(config, "CleanTemp", "true"));

SetChildDirectories(config);
SplitTopBottom = Convert.ToInt32(GetValue(config, SplitTopBottomName, "475"));
SplitLeftRight = Convert.ToInt32(GetValue(config, SplitLeftRightName, "680"));
SplitTagSelect = Convert.ToInt32(GetValue(config, SplitTagSelectName, "300"));
SplitTopBottom = Convert.ToDouble(GetValue(config, SplitTopBottomName, "475"));
SplitLeftRight = Convert.ToDouble(GetValue(config, SplitLeftRightName, "680"));
SplitTagSelect = Convert.ToDouble(GetValue(config, SplitTagSelectName, "300"));
AppWidth = Convert.ToInt32(GetValue(config, AppWidthName, "1024"));
AppHeight = Convert.ToInt32(GetValue(config, AppHeightName, "768"));
AppX = Convert.ToInt32(GetValue(config, AppXName, "0"));
Expand Down Expand Up @@ -274,9 +274,9 @@ private void VerifyPath(LauncherPath path, bool throwErrors)
public string ApiPage { get; private set; }
public string MirrorUrl { get; private set; }
public bool CleanTemp { get; private set; }
public int SplitTopBottom { get; private set; }
public int SplitLeftRight { get; private set; }
public int SplitTagSelect { get; set; }
public double SplitTopBottom { get; private set; }
public double SplitLeftRight { get; private set; }
public double SplitTagSelect { get; set; }
public int AppWidth { get; private set; }
public int AppHeight { get; private set; }
public int AppX { get; private set; }
Expand Down
35 changes: 17 additions & 18 deletions DoomLauncher/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,25 @@ private void InitWindow()
titleBar.HandleWindowStateChange(AppConfiguration.WindowState);
}

// Save the height and set after splitter, otherwise splitter resizing will be incorrect
int saveWidth = Width;
int saveHeight = Height;

Width = AppConfiguration.AppWidth;
Height = AppConfiguration.AppHeight;
SetSplitters();
m_windowState = titleBar.WindowState;
}

splitTopBottom.SplitterDistance = AppConfiguration.SplitTopBottom;
splitLeftRight.SplitterDistance = AppConfiguration.SplitLeftRight;
splitTagSelect.SplitterDistance = AppConfiguration.SplitTagSelect;
private void SetSplitters()
{
splitTopBottom.SplitterDistance = GetSplitterDistancePixels(AppConfiguration.SplitTopBottom, Height);
splitLeftRight.SplitterDistance = GetSplitterDistancePixels(AppConfiguration.SplitLeftRight, Width);
splitTagSelect.SplitterDistance = GetSplitterDistancePixels(AppConfiguration.SplitTagSelect, Width);
}

// If the app was closed in the maximized state then the width and height are maxed out
// This causes the window to take up the full screen even when set to normal state
if (WindowState == FormWindowState.Maximized)
{
Width = saveWidth;
Height = saveHeight;
}
private int GetSplitterDistancePixels(double configValue, int windowDimension)
{
// Previous configurations were set in pixels
if (configValue > 1)
return (int)configValue;

m_windowState = titleBar.WindowState;
//New configuration is percentage 0 - 1
return Math.Max((int)(configValue * windowDimension), 32);
}

public IGameFileView GetCurrentViewControl()
Expand Down Expand Up @@ -1240,7 +1239,7 @@ private void DisplayTags()
m_tagSelectControl.ClearSelections();
m_tagPopup = new Popup(m_tagSelectControl)
{
Width = dpiScale.ScaleIntX(AppConfiguration.SplitTagSelect),
Width = dpiScale.ScaleIntX((int)(Width * AppConfiguration.SplitTagSelect)),
Height = Height - PointToClient(btnTags.PointToScreen(btnTags.Location)).Y - btnTags.Height - dpiScale.ScaleIntY(40)
};
m_tagPopup.Show(btnTags);
Expand Down
15 changes: 12 additions & 3 deletions DoomLauncher/Forms/MainForm_Config.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DoomLauncher.Interfaces;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;

Expand All @@ -17,9 +18,9 @@ private void HandleFormClosing()
if (titleBar.WindowState != FormWindowState.Minimized)
{
// Too many problems when the form is minimized, not supported
DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitTopBottomName, splitTopBottom.SplitterDistance.ToString());
DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitLeftRightName, splitLeftRight.SplitterDistance.ToString());
DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitTagSelectName, splitTagSelect.SplitterDistance.ToString());
DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitTopBottomName, GetSplitterPercent(splitTopBottom, Height).ToString(CultureInfo.InvariantCulture));
DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitLeftRightName, GetSplitterPercent(splitLeftRight, Width).ToString(CultureInfo.InvariantCulture));
DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitTagSelectName, GetSplitterPercent(splitTagSelect, Width).ToString(CultureInfo.InvariantCulture));

DataCache.Instance.UpdateConfig(config, AppConfiguration.AppWidthName, Size.Width.ToString());
DataCache.Instance.UpdateConfig(config, AppConfiguration.AppHeightName, Size.Height.ToString());
Expand All @@ -35,6 +36,14 @@ private void HandleFormClosing()
DataCache.Instance.UpdateConfig(config, AppConfiguration.TagSelectPinnedName, m_tagSelectControl.Pinned.ToString());
}

private static double GetSplitterPercent(SplitContainer splitter, int windowDimension)
{
if (windowDimension <= 0)
return 0.1;

return splitter.SplitterDistance / (double)windowDimension;
}

private void UpdateColumnConfig()
{
IEnumerable<IConfigurationData> config = DataSourceAdapter.GetConfiguration();
Expand Down

0 comments on commit 6a42a90

Please sign in to comment.