From 2c7bacd4c9fb5314d1b3794bf65fda6b115a31f8 Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Sat, 19 Sep 2015 12:57:03 -0400 Subject: [PATCH 1/6] Fixing PushOpacity for Cairo and landing TabStyle changes for Gallery --- samples/TestApplication/App.cs | 3 +- samples/TestApplication/GalleryStyle.cs | 120 ++++++++++++++++++ .../TestApplication/TestApplication.csproj | 5 + src/Gtk/Perspex.Cairo/Media/DrawingContext.cs | 9 +- .../Media/SolidColorBrushImpl.cs | 8 +- 5 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 samples/TestApplication/GalleryStyle.cs diff --git a/samples/TestApplication/App.cs b/samples/TestApplication/App.cs index 8f3a2451d9..6c3ae2f2b7 100644 --- a/samples/TestApplication/App.cs +++ b/samples/TestApplication/App.cs @@ -12,8 +12,9 @@ namespace TestApplication public App() { RegisterServices(); - InitializeSubsystems((int)Environment.OSVersion.Platform); + InitializeSubsystems((int)Environment.OSVersion.Platform); Styles = new DefaultTheme(); + Styles.Add(new SampleTabStyle()); } } } diff --git a/samples/TestApplication/GalleryStyle.cs b/samples/TestApplication/GalleryStyle.cs new file mode 100644 index 0000000000..3497275772 --- /dev/null +++ b/samples/TestApplication/GalleryStyle.cs @@ -0,0 +1,120 @@ +using Perspex; +using Perspex.Controls; +using Perspex.Controls.Presenters; +using Perspex.Controls.Primitives; +using Perspex.Controls.Templates; +using Perspex.Media; +using Perspex.Styling; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TestApplication +{ + internal class SampleTabStyle : Styles + { + public SampleTabStyle() + { + this.AddRange(new[] + { + new Style (s => s.Class(":container").OfType ()) + { + Setters = new[] + { + new Setter (TemplatedControl.TemplateProperty, new ControlTemplate (TabControlTemplate)) + } + }, + + new Style(s => s.Class(":container").OfType().Child().Child().Child().Child().OfType()) + { + Setters = new[] + { + new Setter (TemplatedControl.TemplateProperty, new ControlTemplate (TabItemTemplate)), + } + }, + + new Style(s => s.Class(":container").Child().Child().Child().Child().OfType()) + { + Setters = new[] + { + new Setter(TemplatedControl.FontSizeProperty, 14.0), + new Setter(TemplatedControl.ForegroundProperty, Brushes.White) + } + }, + + new Style(s => s.Class(":container").Child().Child().Child().Child().OfType().Class("selected")) + { + Setters = new[] + { + new Setter(TemplatedControl.ForegroundProperty, Brushes.White), + new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(Colors.White) { Opacity = 0.1 }), + }, + }, + }); + } + + public static Control TabItemTemplate(TabItem control) + { + return new ContentPresenter + { + DataTemplates = new DataTemplates + { + new DataTemplate(x => new Border + { + [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], + Padding = new Thickness(10), + Child = new TextBlock + { + VerticalAlignment = Perspex.Layout.VerticalAlignment.Center, + Text = x + } + }) + }, + Name = "headerPresenter", + [~ContentPresenter.ContentProperty] = control[~HeaderedContentControl.HeaderProperty], + }; + } + + public static Control TabControlTemplate(TabControl control) + { + return new Grid + { + ColumnDefinitions = new ColumnDefinitions + { + new ColumnDefinition(GridLength.Auto), + new ColumnDefinition(new GridLength(1, GridUnitType.Star)), + }, + Children = new Controls + { + new Border + { + Width = 170, + Background = SolidColorBrush.Parse("#373749"), + Child = new TabStrip + { + ItemsPanel = new FuncTemplate(() => new StackPanel { Orientation = Orientation.Vertical, Gap = 4 }), + Margin = new Thickness(0, 10, 0, 0), + Name = "containerTabStrip", + [!ItemsControl.ItemsProperty] = control[!ItemsControl.ItemsProperty], + [!!SelectingItemsControl.SelectedItemProperty] = control[!!SelectingItemsControl.SelectedItemProperty], + } + }, + new Deck + { + Name = "deck", + DataTemplates = new DataTemplates + { + new DataTemplate(x => (Control)control.MaterializeDataTemplate(x.Content)), + }, + [~Deck.TransitionProperty] = control[~TabControl.TransitionProperty], + [!ItemsControl.ItemsProperty] = control[!ItemsControl.ItemsProperty], + [!SelectingItemsControl.SelectedItemProperty] = control[!SelectingItemsControl.SelectedItemProperty], + [Grid.ColumnProperty] = 1, + } + } + }; + } + } +} \ No newline at end of file diff --git a/samples/TestApplication/TestApplication.csproj b/samples/TestApplication/TestApplication.csproj index 480572df6f..43320dcef5 100644 --- a/samples/TestApplication/TestApplication.csproj +++ b/samples/TestApplication/TestApplication.csproj @@ -72,6 +72,7 @@ + @@ -80,6 +81,10 @@ + + {fb05ac90-89ba-4f2f-a924-f37875fb547c} + Perspex.Cairo + {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation diff --git a/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs b/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs index 324ba136e1..c769aea518 100644 --- a/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs +++ b/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs @@ -203,11 +203,14 @@ namespace Perspex.Cairo.Media /// A disposable used to undo the opacity. public IDisposable PushOpacity(double opacity) { - opacityOverride = opacity; + var tmp = opacityOverride; + + if (opacity < 1.0f) + opacityOverride = opacity; return Disposable.Create(() => { - opacityOverride = 1.0f; + opacityOverride = tmp; }); } @@ -254,7 +257,7 @@ namespace Perspex.Cairo.Media } else { - impl = new SolidColorBrushImpl(null, 1.0f); + impl = new SolidColorBrushImpl(null, opacityOverride); } _context.SetSource(impl.PlatformBrush); diff --git a/src/Gtk/Perspex.Cairo/Media/SolidColorBrushImpl.cs b/src/Gtk/Perspex.Cairo/Media/SolidColorBrushImpl.cs index 53db187a0a..10e63f0382 100644 --- a/src/Gtk/Perspex.Cairo/Media/SolidColorBrushImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/SolidColorBrushImpl.cs @@ -9,11 +9,13 @@ namespace Perspex.Cairo { var color = brush?.Color.ToCairo() ?? new Color(); - if (brush != null && brush.Opacity > 1) + if (brush != null) color.A = Math.Min(brush.Opacity, color.A); - color.A = Math.Min(opacityOverride, color.A); - this.PlatformBrush = new SolidPattern(brush?.Color.ToCairo() ?? new Color()); + if (opacityOverride < 1.0f) + color.A = Math.Min(opacityOverride, color.A); + + this.PlatformBrush = new SolidPattern(color); } } } From 13c3f00b8783a4930c6c7dc708449d0334293580 Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Sat, 19 Sep 2015 13:01:01 -0400 Subject: [PATCH 2/6] Cleaning up TestApplication --- samples/TestApplication/Item.cs | 8 ++ samples/TestApplication/Node.cs | 16 +++ samples/TestApplication/Program.cs | 136 ++---------------- .../TestApplication/TestApplication.csproj | 2 + 4 files changed, 35 insertions(+), 127 deletions(-) create mode 100644 samples/TestApplication/Item.cs create mode 100644 samples/TestApplication/Node.cs diff --git a/samples/TestApplication/Item.cs b/samples/TestApplication/Item.cs new file mode 100644 index 0000000000..4898274686 --- /dev/null +++ b/samples/TestApplication/Item.cs @@ -0,0 +1,8 @@ +namespace TestApplication +{ + internal class Item + { + public string Name { get; set; } + public string Value { get; set; } + } +} diff --git a/samples/TestApplication/Node.cs b/samples/TestApplication/Node.cs new file mode 100644 index 0000000000..2856598ad6 --- /dev/null +++ b/samples/TestApplication/Node.cs @@ -0,0 +1,16 @@ +using Perspex.Collections; + +namespace TestApplication +{ + internal class Node + { + public Node() + { + Children = new PerspexList(); + } + + public string Name { get; set; } + public PerspexList Children { get; set; } + } + +} diff --git a/samples/TestApplication/Program.cs b/samples/TestApplication/Program.cs index 54f7686e8c..85d560a1b7 100644 --- a/samples/TestApplication/Program.cs +++ b/samples/TestApplication/Program.cs @@ -23,23 +23,6 @@ using ReactiveUI; namespace TestApplication { - internal class Item - { - public string Name { get; set; } - public string Value { get; set; } - } - - internal class Node - { - public Node() - { - Children = new PerspexList(); - } - - public string Name { get; set; } - public PerspexList Children { get; set; } - } - internal class Program { private static readonly PerspexList s_treeData = new PerspexList @@ -94,12 +77,6 @@ namespace TestApplication private static void Main(string[] args) { - //Log.Logger = new LoggerConfiguration() - // .Filter.ByIncludingOnly(Matching.WithProperty("Area", "Layout")) - // .MinimumLevel.Verbose() - // .WriteTo.Trace(outputTemplate: "[{Id:X8}] [{SourceContext}] {Message}") - // .CreateLogger(); - // The version of ReactiveUI currently included is for WPF and so expects a WPF // dispatcher. This makes sure it's initialized. System.Windows.Threading.Dispatcher foo = System.Windows.Threading.Dispatcher.CurrentDispatcher; @@ -120,10 +97,13 @@ namespace TestApplication var testCommand = ReactiveCommand.Create(); testCommand.Subscribe(_ => System.Diagnostics.Debug.WriteLine("Test command executed.")); + TabControl container; + Window window = new Window { Title = "Perspex Test Application", - SizeToContent = SizeToContent.WidthAndHeight, + Width = 800, + Height = 300, Content = new Grid { ColumnDefinitions = new ColumnDefinitions @@ -139,84 +119,9 @@ namespace TestApplication }, Children = new Controls { - new Menu - { - Items = new[] - { - new MenuItem - { - Header = "_File", - Items = new[] - { - new MenuItem - { - Header = "_Open...", - Icon = new Image - { - Source = new Bitmap("github_icon.png"), - }, - }, - new MenuItem - { - Header = "_Save", - Items = new[] - { - new MenuItem - { - Header = "Sub Item _1", - }, - new MenuItem - { - Header = "Sub Item _2", - }, - } - }, - new MenuItem - { - Header = "Save _As", - Items = new[] - { - new MenuItem - { - Header = "Sub Item _1", - }, - new MenuItem - { - Header = "Sub Item _2", - }, - } - }, - new MenuItem - { - Header = "E_xit", - Command = testCommand, - }, - } - }, - new MenuItem - { - Header = "_Edit", - Items = new[] - { - new MenuItem - { - Header = "Cu_t", - }, - new MenuItem - { - Header = "_Copy", - }, - new MenuItem - { - Header = "_Paste", - }, - } - } - }, - [Grid.ColumnSpanProperty] = 2, - }, - new TabControl + (container = new TabControl { + Padding = new Thickness(5), Items = new[] { ButtonsTab(), @@ -227,38 +132,15 @@ namespace TestApplication LayoutTab(), AnimationsTab(), }, - Transition = new PageSlide(TimeSpan.FromSeconds(0.25)), + Transition = new CrossFade(TimeSpan.FromSeconds(0.25)), [Grid.RowProperty] = 1, [Grid.ColumnSpanProperty] = 2, - }, - (fps = new TextBlock - { - HorizontalAlignment = HorizontalAlignment.Left, - Margin = new Thickness(2), - [Grid.RowProperty] = 2, - }), - new TextBlock - { - Text = "Press F12 for Dev Tools", - HorizontalAlignment = HorizontalAlignment.Right, - Margin = new Thickness(2), - [Grid.ColumnProperty] = 1, - [Grid.RowProperty] = 2, - }, + }) } }, }; - 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)); + container.Classes.Add(":container"); window.Show(); Application.Current.Run(window); diff --git a/samples/TestApplication/TestApplication.csproj b/samples/TestApplication/TestApplication.csproj index 43320dcef5..efef472229 100644 --- a/samples/TestApplication/TestApplication.csproj +++ b/samples/TestApplication/TestApplication.csproj @@ -73,6 +73,8 @@ + + From b491c0ec25cf390e7b53bbc222fd7e99ccebb840 Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Sat, 19 Sep 2015 15:58:47 -0400 Subject: [PATCH 3/6] WIP --- samples/TestApplication/GalleryStyle.cs | 25 ++- samples/TestApplication/Program.cs | 215 +++++++++++--------- src/Perspex.Themes.Default/ButtonStyle.cs | 17 +- src/Perspex.Themes.Default/CheckBoxStyle.cs | 4 +- src/Perspex.Themes.Default/TabItemStyle.cs | 2 +- 5 files changed, 139 insertions(+), 124 deletions(-) diff --git a/samples/TestApplication/GalleryStyle.cs b/samples/TestApplication/GalleryStyle.cs index 3497275772..15cbb5749b 100644 --- a/samples/TestApplication/GalleryStyle.cs +++ b/samples/TestApplication/GalleryStyle.cs @@ -27,7 +27,7 @@ namespace TestApplication } }, - new Style(s => s.Class(":container").OfType().Child().Child().Child().Child().OfType()) + new Style(s => s.Class(":container").OfType().Child().Child().Child().Child().Child().OfType()) { Setters = new[] { @@ -35,7 +35,7 @@ namespace TestApplication } }, - new Style(s => s.Class(":container").Child().Child().Child().Child().OfType()) + new Style(s => s.Name("internalStrip").OfType().Child().OfType()) { Setters = new[] { @@ -44,7 +44,7 @@ namespace TestApplication } }, - new Style(s => s.Class(":container").Child().Child().Child().Child().OfType().Class("selected")) + new Style(s => s.Name("internalStrip").OfType().Child().OfType().Class("selected")) { Setters = new[] { @@ -90,15 +90,18 @@ namespace TestApplication { new Border { - Width = 170, - Background = SolidColorBrush.Parse("#373749"), - Child = new TabStrip + Width = 190, + Background = SolidColorBrush.Parse("#1976D2"), + Child = new ScrollViewer { - ItemsPanel = new FuncTemplate(() => new StackPanel { Orientation = Orientation.Vertical, Gap = 4 }), - Margin = new Thickness(0, 10, 0, 0), - Name = "containerTabStrip", - [!ItemsControl.ItemsProperty] = control[!ItemsControl.ItemsProperty], - [!!SelectingItemsControl.SelectedItemProperty] = control[!!SelectingItemsControl.SelectedItemProperty], + Content = new TabStrip + { + ItemsPanel = new FuncTemplate(() => new StackPanel { Orientation = Orientation.Vertical, Gap = 4 }), + Margin = new Thickness(0, 10, 0, 0), + Name = "internalStrip", + [!ItemsControl.ItemsProperty] = control[!ItemsControl.ItemsProperty], + [!!SelectingItemsControl.SelectedItemProperty] = control[!!SelectingItemsControl.SelectedItemProperty], + } } }, new Deck diff --git a/samples/TestApplication/Program.cs b/samples/TestApplication/Program.cs index 85d560a1b7..8bab0b157a 100644 --- a/samples/TestApplication/Program.cs +++ b/samples/TestApplication/Program.cs @@ -155,97 +155,67 @@ namespace TestApplication var result = new TabItem { - Header = "Buttons", + Header = "Button", Content = new StackPanel { + Margin = new Thickness(10), Orientation = Orientation.Vertical, - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - Gap = 8, - MinWidth = 120, + Gap = 4, Children = new Controls { - (showDialogButton = new Button - { - Content = "Button", - Command = showDialog, - [ToolTip.TipProperty] = "Hello World!", - }), - new Button + new TextBlock { - Content = "Button", - Background = new SolidColorBrush(0xcc119eda), - [ToolTip.TipProperty] = "Goodbye Cruel World!", + Text = "Button", + FontWeight = FontWeight.Medium, + FontSize = 22, + Foreground = SolidColorBrush.Parse("#212121"), }, - (defaultButton = new Button - { - Content = "Default", - IsDefault = true, - }), - new Button + new TextBlock { - Content = "Disabled", - IsEnabled = false, + Text = "A button control", + FontSize = 14, + Foreground = SolidColorBrush.Parse("#727272"), + Margin = new Thickness(0, 0, 0, 10) }, new Button { - Content = "Disabled", - IsEnabled = false, - Background = new SolidColorBrush(0xcc119eda), - }, - new ToggleButton - { - Content = "Toggle", + Width = 150, + Content = "Button" }, - new ToggleButton + new Button { + Width = 150, Content = "Disabled", IsEnabled = false, }, - new CheckBox - { - Content = "Checkbox", - }, - new RadioButton + new TabControl { - Content = "RadioButton 1", - IsChecked = true, - }, - new RadioButton - { - Content = "RadioButton 2", - }, - } - }, - }; - - defaultButton.Click += (s, e) => - { - defaultButton.Content = ((string)defaultButton.Content == "Default") ? "Clicked" : "Default"; - }; - - showDialog.Subscribe(async _ => - { - var close = ReactiveCommand.Create(); + Margin = new Thickness(0, 20, 0, 0), - var dialog = new Window - { - Content = new StackPanel - { - Width = 200, - Height = 200, - Children = new Controls - { - new Button { Content = "Yes", Command = close, CommandParameter = "Yes" }, - new Button { Content = "No", Command = close, CommandParameter = "No" }, + Items = new [] + { + new TabItem + { + Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "CSHARP" }, + Content = new HtmlLabel + { + Text = "CSHRP CODEZ" + } + }, + new TabItem + { + Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "XAML" }, + Content = new HtmlLabel + { + Text = "XAML CODEZ" + } + } + } } } - }; - - close.Subscribe(x => dialog.Close(x)); - - showDialogButton.Content = await dialog.ShowDialog(); - }); + }, + }; + return result; } @@ -257,7 +227,7 @@ namespace TestApplication .ReadToEnd(); return new TabItem { - Header = "Html", + Header = "HTML Label", Content = new ScrollViewer() { Width = 600, @@ -278,50 +248,99 @@ namespace TestApplication { return new TabItem { - Header = "Text", + Header = "Input", Content = new StackPanel { + Margin = new Thickness(10), Orientation = Orientation.Vertical, - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - Gap = 8, - Width = 120, + Gap = 4, Children = new Controls { new TextBlock { - Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt.", - TextWrapping = TextWrapping.Wrap, - TextAlignment = TextAlignment.Center, + Text = "Check box", + FontWeight = FontWeight.Medium, + FontSize = 22, + Foreground = SolidColorBrush.Parse("#212121"), }, new TextBlock { - Text = "Italic text.", - FontStyle = FontStyle.Italic, - TextAlignment = TextAlignment.Left, + Text = "A check box control", + FontSize = 14, + Foreground = SolidColorBrush.Parse("#373749"), + Margin = new Thickness(0, 0, 0, 10) }, - new TextBlock + new CheckBox { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Checked" }, + new CheckBox { IsChecked = false, Content = "Unchecked" }, + new TabControl { - Text = "Bold text.", - FontWeight = FontWeight.Bold, - TextAlignment = TextAlignment.Right, + Margin = new Thickness(0, 20, 0, 0), + + Items = new [] + { + new TabItem + { + Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "CSHARP" }, + Content = new HtmlLabel + { + Text = "CSHRP CODEZ" + } + }, + new TabItem + { + Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "XAML" }, + Content = new HtmlLabel + { + Text = "XAML CODEZ" + } + } + } }, - new TextBox + new TextBlock { - Text = "A non-wrapping text box. Lorem ipsum dolor sit amet.", - TextWrapping = TextWrapping.NoWrap, + Margin = new Thickness(0, 40, 0, 0), + Text = "Radio button", + FontWeight = FontWeight.Medium, + FontSize = 22, + Foreground = SolidColorBrush.Parse("#373749"), }, - new TextBox + new TextBlock { - AcceptsReturn = true, - Text = "A wrapping text box. " + - "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt. " + - "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt.", - TextWrapping = TextWrapping.Wrap, - MaxHeight = 100, + Text = "A radio button control", + FontSize = 14, + Foreground = SolidColorBrush.Parse("#373749"), + Margin = new Thickness(0, 0, 0, 10) }, + + new RadioButton { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Option 1" }, + new RadioButton { IsChecked = false, Content = "Option 2" }, + new RadioButton { IsChecked = false, Content = "Option 3" }, + new TabControl + { + Margin = new Thickness(0, 20, 0, 0), + + Items = new [] + { + new TabItem + { + Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "CSHARP" }, + Content = new HtmlLabel + { + Text = "CSHRP CODEZ" + } + }, + new TabItem + { + Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "XAML" }, + Content = new HtmlLabel + { + Text = "XAML CODEZ" + } + } + } + } } - }, + } }; } diff --git a/src/Perspex.Themes.Default/ButtonStyle.cs b/src/Perspex.Themes.Default/ButtonStyle.cs index fc9f9917a8..fb383100e8 100644 --- a/src/Perspex.Themes.Default/ButtonStyle.cs +++ b/src/Perspex.Themes.Default/ButtonStyle.cs @@ -30,8 +30,8 @@ namespace Perspex.Themes.Default { Setters = new[] { - new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffdddddd)), - new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff707070)), + new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffaaaaaa)), + new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xffaaaaaa)), new Setter(TemplatedControl.BorderThicknessProperty, 2), new Setter(TemplatedControl.ForegroundProperty, new SolidColorBrush(0xff000000)), new Setter(Control.FocusAdornerProperty, new FuncTemplate(FocusAdornerTemplate)), @@ -44,22 +44,15 @@ namespace Perspex.Themes.Default { Setters = new[] { - new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffbee6fd)), - new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff3c7fb1)), + new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff888888)), }, }, new Style(x => x.OfType