-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
199 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Grid x:Class="PalCalc.UI.View.TraitCollectionView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:PalCalc.UI.View" | ||
xmlns:vm="clr-namespace:PalCalc.UI.ViewModel" | ||
mc:Ignorable="d" | ||
d:DataContext="{d:DesignInstance vm:TraitCollectionViewModel, IsDesignTimeCreatable=True}" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
</Grid> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using PalCalc.UI.ViewModel; | ||
using QuickGraph; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace PalCalc.UI.View | ||
{ | ||
/// <summary> | ||
/// Interaction logic for TraitCollectionView.xaml | ||
/// </summary> | ||
public partial class TraitCollectionView : Grid | ||
{ | ||
public TraitCollectionView() | ||
{ | ||
InitializeComponent(); | ||
|
||
DataContextChanged += TraitCollectionView_DataContextChanged; | ||
} | ||
|
||
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) | ||
{ | ||
base.OnRenderSizeChanged(sizeInfo); | ||
|
||
var vm = DataContext as TraitCollectionViewModel; | ||
if (vm == null) return; | ||
|
||
foreach (var child in Children) | ||
{ | ||
var traitView = child as TraitView; | ||
if (traitView == null) continue; | ||
|
||
// force child sizing (otherwise the '*' column sizing doesn't stay proportional) | ||
traitView.Width = (ActualWidth - vm.Spacing) / 2; | ||
} | ||
} | ||
|
||
private void TraitCollectionView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var newModel = e.NewValue as TraitCollectionViewModel; | ||
if (newModel == null) return; | ||
|
||
Children.Clear(); | ||
|
||
ColumnDefinitions.Clear(); | ||
foreach (var cdef in newModel.ColumnDefinitions) | ||
ColumnDefinitions.Add(cdef); | ||
|
||
RowDefinitions.Clear(); | ||
foreach (var rdef in newModel.RowDefinitions) | ||
RowDefinitions.Add(rdef); | ||
|
||
|
||
|
||
foreach (var vm in newModel.Traits) | ||
{ | ||
var traitView = new TraitView(); | ||
traitView.DataContext = vm; | ||
|
||
Grid.SetRow(traitView, newModel.RowIndexOf(vm)); | ||
Grid.SetColumn(traitView, newModel.ColumnIndexOf(vm)); | ||
|
||
Children.Add(traitView); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.Eventing.Reader; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace PalCalc.UI.ViewModel | ||
{ | ||
public class TraitCollectionViewModel | ||
{ | ||
// for XAML designer view | ||
public TraitCollectionViewModel() : this( | ||
new List<TraitViewModel>() | ||
{ | ||
new TraitViewModel(), | ||
new TraitViewModel(), | ||
new TraitViewModel(), | ||
}) | ||
{ | ||
} | ||
|
||
public TraitCollectionViewModel(List<TraitViewModel> traits) | ||
{ | ||
Traits = traits; | ||
|
||
RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); | ||
for (int i = 1; i < NumRows; i++) | ||
{ | ||
if (i % 2 == 1) | ||
{ | ||
RowDefinitions.Add(new RowDefinition() { Height = new GridLength(Spacing) }); | ||
} | ||
else | ||
{ | ||
RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); | ||
} | ||
} | ||
|
||
ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); | ||
ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(Spacing) }); | ||
ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); | ||
} | ||
|
||
public List<TraitViewModel> Traits { get; } | ||
|
||
public int Spacing => 3; | ||
|
||
public int EntriesPerRow => 2; | ||
|
||
public int NumRows | ||
{ | ||
get | ||
{ | ||
if (Traits.Count <= 2) return 1; | ||
else return 3; | ||
} | ||
} | ||
|
||
public List<RowDefinition> RowDefinitions { get; } = new List<RowDefinition>(); | ||
public List<ColumnDefinition> ColumnDefinitions { get; } = new List<ColumnDefinition>(); | ||
|
||
public int RowIndexOf(TraitViewModel trait) | ||
{ | ||
var mainRow = Traits.IndexOf(trait) / EntriesPerRow; | ||
if (mainRow == 0) return mainRow; | ||
else return mainRow + 1; | ||
} | ||
|
||
public int ColumnIndexOf(TraitViewModel trait) | ||
{ | ||
var mainColumn = Traits.IndexOf(trait) % EntriesPerRow; | ||
if (mainColumn == 0) return mainColumn; | ||
else return mainColumn + 1; | ||
} | ||
} | ||
} |