Browse Source

Added Deck control.

pull/58/head
Steven Kirk 11 years ago
parent
commit
d591f0691e
  1. 44
      Perspex.Controls/Deck.cs
  2. 25
      Perspex.Controls/DeckItem.cs
  3. 2
      Perspex.Controls/Perspex.Controls.csproj
  4. 38
      Perspex.Themes.Default/DeckItemStyle.cs
  5. 54
      Perspex.Themes.Default/DeckStyle.cs
  6. 2
      Perspex.Themes.Default/DefaultTheme.cs
  7. 7
      Perspex.Themes.Default/ListBoxItemStyle.cs
  8. 2
      Perspex.Themes.Default/Perspex.Themes.Default.csproj
  9. 57
      TestApplication/Program.cs
  10. 18
      Tests/Perspex.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

44
Perspex.Controls/Deck.cs

@ -0,0 +1,44 @@
// -----------------------------------------------------------------------
// <copyright file="Deck.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
using System.Collections;
using Perspex.Controls.Generators;
using Perspex.Controls.Primitives;
using Perspex.Controls.Utils;
/// <summary>
/// A selecting items control that displays a single item that fills the control.
/// </summary>
public class Deck : SelectingItemsControl
{
private static readonly ItemsPanelTemplate PanelTemplate =
new ItemsPanelTemplate(() => new Panel());
static Deck()
{
ItemsPanelProperty.OverrideDefaultValue(typeof(Deck), PanelTemplate);
}
protected override ItemContainerGenerator CreateItemContainerGenerator()
{
return new TypedItemContainerGenerator<DeckItem>(this);
}
protected override void ItemsChanged(IEnumerable oldValue, IEnumerable newValue)
{
base.ItemsChanged(oldValue, newValue);
var items = this.Items;
if (items != null && items.Count() > 0)
{
this.SelectedIndex = 0;
}
}
}
}

25
Perspex.Controls/DeckItem.cs

@ -0,0 +1,25 @@
// -----------------------------------------------------------------------
// <copyright file="DeckItem.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
public class DeckItem : ContentControl, ISelectable
{
public static readonly PerspexProperty<bool> IsSelectedProperty =
PerspexProperty.Register<DeckItem, bool>("IsSelected");
static DeckItem()
{
Control.PseudoClass(IsSelectedProperty, ":selected");
}
public bool IsSelected
{
get { return this.GetValue(IsSelectedProperty); }
set { this.SetValue(IsSelectedProperty, value); }
}
}
}

2
Perspex.Controls/Perspex.Controls.csproj

@ -41,6 +41,8 @@
<Compile Include="IContentControl.cs" />
<Compile Include="IItemsPanel.cs" />
<Compile Include="INavigablePanel.cs" />
<Compile Include="DeckItem.cs" />
<Compile Include="Deck.cs" />
<Compile Include="Platform\IPopupImpl.cs" />
<Compile Include="Platform\ITopLevelImpl.cs" />
<Compile Include="Popup.cs" />

38
Perspex.Themes.Default/DeckItemStyle.cs

@ -0,0 +1,38 @@
// -----------------------------------------------------------------------
// <copyright file="DeckItemStyle.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Themes.Default
{
using Perspex.Controls;
using Perspex.Controls.Presenters;
using Perspex.Styling;
using System.Linq;
public class DeckItemStyle : Styles
{
public DeckItemStyle()
{
this.AddRange(new[]
{
new Style(x => x.OfType<DeckItem>())
{
Setters = new[]
{
new Setter(DeckItem.TemplateProperty, ControlTemplate.Create<DeckItem>(this.Template)),
},
},
});
}
private Control Template(DeckItem control)
{
return new ContentPresenter
{
[~ContentPresenter.ContentProperty] = control[~DeckItem.ContentProperty],
};
}
}
}

54
Perspex.Themes.Default/DeckStyle.cs

@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="DeckStyle.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Themes.Default
{
using Perspex.Controls;
using Perspex.Controls.Presenters;
using Perspex.Styling;
using System.Linq;
public class DeckStyle : Styles
{
public DeckStyle()
{
this.AddRange(new[]
{
new Style(x => x.OfType<Deck>())
{
Setters = new[]
{
new Setter(Deck.TemplateProperty, ControlTemplate.Create<Deck>(this.Template)),
},
},
new Style(x => x.OfType<Deck>().Descendent().Is<DeckItem>())
{
Setters = new[]
{
new Setter(Control.IsVisibleProperty, false),
},
},
new Style(x => x.OfType<Deck>().Descendent().Is<DeckItem>().Class(":selected"))
{
Setters = new[]
{
new Setter(Control.IsVisibleProperty, true),
},
}
});
}
private Control Template(Deck control)
{
return new ItemsPresenter
{
Id = "itemsPresenter",
[~ItemsPresenter.ItemsProperty] = control[~Deck.ItemsProperty],
[~ItemsPresenter.ItemsPanelProperty] = control[~Deck.ItemsPanelProperty],
};
}
}
}

2
Perspex.Themes.Default/DefaultTheme.cs

@ -22,6 +22,8 @@ namespace Perspex.Themes.Default
this.Add(new ItemsControlStyle());
this.Add(new ListBoxStyle());
this.Add(new ListBoxItemStyle());
this.Add(new DeckStyle());
this.Add(new DeckItemStyle());
this.Add(new PopupRootStyle());
this.Add(new RadioButtonStyle());
this.Add(new ScrollBarStyle());

7
Perspex.Themes.Default/ListBoxItemStyle.cs

@ -6,14 +6,11 @@
namespace Perspex.Themes.Default
{
using System.Linq;
using Perspex.Controls;
using Perspex.Layout;
using Perspex.Controls.Presenters;
using Perspex.Media;
using Perspex.Controls.Shapes;
using Perspex.Styling;
using Perspex.Controls.Presenters;
using Perspex.Controls.Primitives;
using System.Linq;
public class ListBoxItemStyle : Styles
{

2
Perspex.Themes.Default/Perspex.Themes.Default.csproj

@ -72,6 +72,8 @@
<ItemGroup>
<Compile Include="FocusAdornerStyle.cs" />
<Compile Include="DropDownStyle.cs" />
<Compile Include="DeckItemStyle.cs" />
<Compile Include="DeckStyle.cs" />
<Compile Include="RadioButtonStyle.cs" />
<Compile Include="ToggleButtonStyle.cs" />
<Compile Include="ListBoxStyle.cs" />

57
TestApplication/Program.cs

@ -106,8 +106,9 @@ namespace TestApplication
static void Main(string[] args)
{
//LogManager.Enable(new TestLogger());
LogManager.Enable(new TestLogger());
//LogManager.Instance.LogLayoutMessages = true;
LogManager.Instance.LogPropertyMessages = true;
// The version of ReactiveUI currently included is for WPF and so expects a WPF
// dispatcher. This makes sure it's initialized.
@ -176,14 +177,14 @@ namespace TestApplication
DevTools.Attach(window);
var renderer = ((IRenderRoot)window).Renderer;
var last = renderer.RenderCount;
DispatcherTimer.Run(() =>
{
fps.Text = "FPS: " + (renderer.RenderCount - last);
last = renderer.RenderCount;
return true;
}, TimeSpan.FromSeconds(1));
//var renderer = ((IRenderRoot)window).Renderer;
//var last = renderer.RenderCount;
//DispatcherTimer.Run(() =>
//{
// fps.Text = "FPS: " + (renderer.RenderCount - last);
// last = renderer.RenderCount;
// return true;
//}, TimeSpan.FromSeconds(1));
window.Show();
Application.Current.Run(window);
@ -383,6 +384,8 @@ namespace TestApplication
private static TabItem ListsTab()
{
ListBox listBox;
return new TabItem
{
Header = "Lists",
@ -411,10 +414,16 @@ namespace TestApplication
Id = "treeView",
Items = treeData,
},
new ListBox
(listBox = new ListBox
{
Items = listBoxData,
SelectedIndex = 0,
MaxHeight = 300,
}),
new Deck
{
Items = listBoxData,
[!Deck.SelectedItemProperty] = listBox[!ListBox.SelectedItemProperty],
},
new DropDown
{
@ -565,20 +574,20 @@ namespace TestApplication
}
};
var start = Animate.Stopwatch.Elapsed;
var degrees = Animate.Timer
.Select(x =>
{
var elapsed = (x - start).TotalSeconds;
var cycles = elapsed / 4;
var progress = cycles % 1;
return 360.0 * progress;
});
border1.RenderTransform.Bind(
RotateTransform.AngleProperty,
degrees,
BindingPriority.Animation);
//var start = Animate.Stopwatch.Elapsed;
//var degrees = Animate.Timer
// .Select(x =>
// {
// var elapsed = (x - start).TotalSeconds;
// var cycles = elapsed / 4;
// var progress = cycles % 1;
// return 360.0 * progress;
// });
//border1.RenderTransform.Bind(
// RotateTransform.AngleProperty,
// degrees,
// BindingPriority.Animation);
return result;
}

18
Tests/Perspex.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -14,6 +14,24 @@ namespace Perspex.Controls.Primitives.UnitTests
public class SelectingItemsControlTests
{
[Fact]
public void SelectedIndex_Should_Initially_Be_Minus_1()
{
var items = new[]
{
new Item(),
new Item(),
};
var target = new Target
{
Items = items,
Template = this.Template(),
};
Assert.Equal(-1, target.SelectedIndex);
}
[Fact]
public void Item_IsSelected_Should_Initially_Be_False()
{

Loading…
Cancel
Save