Skip to content

Commit

Permalink
Improve setting the minimum window height
Browse files Browse the repository at this point in the history
In v0.10.0, a bug was introduced where the deckpicker class selector
would scroll down when selected if the main window was at its minimum
height. This required increasing the minimum height due to the
changes in ac125de which increased the size of the deck type selector.

The minimum window height now also updates when the deck search box
is visible. If this causes a change to the height of the window, this
is reversed when the search box is closed or the application is closed.

The minimum window height now also updates when the news status bar is
visible.
  • Loading branch information
dvide committed Apr 28, 2015
1 parent e0ec0ce commit 682339c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Hearthstone Deck Tracker/Controls/DeckPickerClassItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Hearthstone_Deck_Tracker.Controls
/// </summary>
public partial class DeckPickerClassItem
{
private const int Small = 36;
private const int Big = 48;
public const int Small = 36;
public const int Big = 48;

public DeckPickerClassItem()
{
Expand Down
23 changes: 12 additions & 11 deletions Hearthstone Deck Tracker/Controls/NewDeckPicker.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public partial class NewDeckPicker : INotifyPropertyChanged
private readonly ObservableCollection<DeckPickerClassItem> _classItems;
private readonly ObservableCollection<NewDeckPickerItem> _displayedDecks;
public bool ChangedSelection;
private bool _anyArchived;
private bool _clearingClasses;
private bool _ignoreSelectionChange;
private bool _refillingList;
Expand All @@ -48,6 +47,7 @@ public NewDeckPicker()
new ObservableCollection<DeckPickerClassItem>(
Enum.GetValues(typeof(HeroClassAll)).OfType<HeroClassAll>().Select(x => new DeckPickerClassItem {DataContext = x}));
_archivedClassItem = _classItems.ElementAt((int)HeroClassAll.Archived);
_classItems.Remove(_archivedClassItem);
ListViewClasses.ItemsSource = _classItems;
SelectedClasses = new ObservableCollection<HeroClassAll>();
_displayedDecks = new ObservableCollection<NewDeckPickerItem>();
Expand All @@ -61,10 +61,7 @@ public List<Deck> SelectedDecks

public ObservableCollection<HeroClassAll> SelectedClasses { get; private set; }

public double MinWindowHeight
{
get { return _anyArchived ? 649 : 603; }
}
public bool ArchivedClassVisible { get; set; }

public bool SearchBarVisibile { get; set; }

Expand Down Expand Up @@ -320,24 +317,28 @@ public void UpdateDecks(bool reselectActiveDeck = true, bool simpleRefill = true

public void UpdateArchivedClassVisibility()
{
_anyArchived = DeckList.Instance.Decks.Any(d => d.Archived);

if(_anyArchived)
if(DeckList.Instance.Decks.Any(d => d.Archived))
{
if(!_classItems.Contains(_archivedClassItem))
{
_classItems.Add(_archivedClassItem);
ArchivedClassVisible = true;

if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("MinWindowHeight"));
PropertyChanged(this, new PropertyChangedEventArgs("ArchivedClassVisible"));
}
}
else
{
var removed = _classItems.Remove(_archivedClassItem);

if(removed)
{
ArchivedClassVisible = false;

if(removed && PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("MinWindowHeight"));
if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("ArchivedClassVisible"));
}

SelectedClasses.Remove(HeroClassAll.Archived);
if(SelectedClasses.Count == 0)
Expand Down
4 changes: 2 additions & 2 deletions Hearthstone Deck Tracker/MainWindow/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
xmlns:hearthStats="clr-namespace:Hearthstone_Deck_Tracker.HearthStats.Controls"
xmlns:flyoutControls="clr-namespace:Hearthstone_Deck_Tracker.FlyoutControls"
Title="Hearthstone Deck Tracker" Height="603" Width="640"
MinHeight="{Binding ElementName=DeckPickerList, Path=MinWindowHeight}" MinWidth="640"
MinHeight="584" MinWidth="640"
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Closing="Window_Closing"
Icon="..\Images\HearthstoneDeckTracker.ico"
StateChanged="MetroWindow_StateChanged" Loaded="MetroWindow_Loaded"
BorderBrush="{DynamicResource AccentColorBrush}" BorderThickness="1" LocationChanged="MetroWindow_LocationChanged">
BorderBrush="{DynamicResource AccentColorBrush}" BorderThickness="1" LocationChanged="MetroWindow_LocationChanged" SizeChanged="MetroWindow_SizeChanged">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
36 changes: 35 additions & 1 deletion Hearthstone Deck Tracker/MainWindow/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public partial class MainWindow
private bool _update;
private Version _updatedVersion;

private double _heightChangeDueToSearchBox;
private const int SearchBoxHeight = 30;
private const int StatusBarNewsHeight = 20;
private const int ArchivedClassHeight = DeckPickerClassItem.Big;

public bool ShowToolTip
{
get { return Config.Instance.TrackerCardToolTips; }
Expand Down Expand Up @@ -323,6 +328,7 @@ public MainWindow()

Helper.SortCardCollection(ListViewDeck.Items, Config.Instance.CardSortingClassFirst);
//DeckPickerList.SortDecks();
DeckPickerList.PropertyChanged += DeckPickerList_PropertyChanged;
DeckPickerList.UpdateDecks();
DeckPickerList.UpdateArchivedClassVisibility();

Expand All @@ -342,7 +348,33 @@ public MainWindow()
PluginManager.Instance.StartUpdateAsync();
}

void DeckPickerList_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if(e.PropertyName == "ArchivedClassVisible")
MinHeight += DeckPickerList.ArchivedClassVisible ? ArchivedClassHeight : -ArchivedClassHeight;

if(e.PropertyName == "VisibilitySearchBar")
{
if(DeckPickerList.SearchBarVisibile)
{
var oldHeight = Height;
MinHeight += SearchBoxHeight;
_heightChangeDueToSearchBox = Height - oldHeight;
}
else
{
MinHeight -= SearchBoxHeight;
Height -= _heightChangeDueToSearchBox;
}
}
}

private void MetroWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
if(e.HeightChanged)
_heightChangeDueToSearchBox = 0;
}

public Thickness TitleBarMargin
{
get { return new Thickness(0, TitlebarHeight, 0, 0); }
Expand Down Expand Up @@ -421,6 +453,7 @@ private async void UpdateAsync()
{
TopRow.Height = new GridLength(20);
StatusBarNews.Visibility = Visibility.Visible;
MinHeight += StatusBarNewsHeight;
UpdateNews(0);
}
}
Expand Down Expand Up @@ -582,7 +615,7 @@ private async void Window_Closing(object sender, CancelEventArgs e)
Config.Instance.SelectedDeckPickerClasses = DeckPickerList.SelectedClasses.ToArray();

Config.Instance.WindowWidth = (int)(Width - (GridNewDeck.Visibility == Visibility.Visible ? GridNewDeck.ActualWidth : 0));
Config.Instance.WindowHeight = (int)Height;
Config.Instance.WindowHeight = (int)(Height - _heightChangeDueToSearchBox);
Config.Instance.TrackerWindowTop = (int)Top;
Config.Instance.TrackerWindowLeft = (int)(Left + (_movedLeft.HasValue ? _movedLeft.Value : 0));

Expand Down Expand Up @@ -1498,6 +1531,7 @@ private void BtnCloseNews_OnClick(object sender, RoutedEventArgs e)
Config.Instance.IgnoreNewsId = _currentNewsId;
Config.Save();
StatusBarNews.Visibility = Visibility.Collapsed;
MinHeight -= StatusBarNewsHeight;
TopRow.Height = new GridLength(0);
}

Expand Down

0 comments on commit 682339c

Please sign in to comment.