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); } } }