From 9237a398e956e4b8c6e17e84a6c85e5e4b426cfa Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 3 Jun 2020 02:07:35 -0400 Subject: [PATCH 1/7] Make ToolTip background transparent using IPopupImpl --- src/Avalonia.Controls/ToolTip.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Avalonia.Controls/ToolTip.cs b/src/Avalonia.Controls/ToolTip.cs index 2f11746891..4ad5a6e60d 100644 --- a/src/Avalonia.Controls/ToolTip.cs +++ b/src/Avalonia.Controls/ToolTip.cs @@ -238,6 +238,9 @@ namespace Avalonia.Controls _popup.ConfigurePosition(control, GetPlacement(control), new Point(GetHorizontalOffset(control), GetVerticalOffset(control))); + + WindowManagerAddShadowHintChanged(_popup, false); + _popup.Show(); } @@ -250,5 +253,13 @@ namespace Avalonia.Controls _popup = null; } } + + private void WindowManagerAddShadowHintChanged(IPopupHost host, bool hint) + { + if (host is PopupRoot pr) + { + pr.PlatformImpl.SetWindowManagerAddShadowHint(hint); + } + } } } From 7574a7506663759d2c973ea58c217c69bc6899b0 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 3 Jun 2020 03:06:58 -0400 Subject: [PATCH 2/7] Add tooltip fluent resources --- .../Accents/FluentBaseDark.xaml | 10 ++++++++++ .../Accents/FluentBaseLight.xaml | 10 ++++++++++ .../Accents/FluentControlResourcesDark.xaml | 11 +++++++++++ .../Accents/FluentControlResourcesLight.xaml | 11 +++++++++++ 4 files changed, 42 insertions(+) diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml index 7a715bbde7..a9369c569f 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml @@ -312,5 +312,15 @@ + + + 12 + 1 + + + + + + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml index 5c6286a0bc..731ac1d0c7 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml @@ -313,5 +313,15 @@ + + + 12 + 1 + + + + + + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml index 7364c339f1..d076df4cc9 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml @@ -343,5 +343,16 @@ + + + 12 + 1 + + + + + + + 8,5,8,7 diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml index 15e157f573..430e9f61cf 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml @@ -343,5 +343,16 @@ + + + 12 + 1 + + + + + + + 8,5,8,7 From 1fa96f049c85b24cab9e57ff10a21d4790c4e1b4 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 3 Jun 2020 03:07:28 -0400 Subject: [PATCH 3/7] Implement ToolTip :open pseudo class --- src/Avalonia.Controls/ToolTip.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/ToolTip.cs b/src/Avalonia.Controls/ToolTip.cs index 4ad5a6e60d..b458b15c64 100644 --- a/src/Avalonia.Controls/ToolTip.cs +++ b/src/Avalonia.Controls/ToolTip.cs @@ -204,13 +204,15 @@ namespace Avalonia.Controls private static void IsOpenChanged(AvaloniaPropertyChangedEventArgs e) { var control = (Control)e.Sender; + var newValue = (bool)e.NewValue; + ToolTip toolTip; - if ((bool)e.NewValue) + if (newValue) { var tip = GetTip(control); if (tip == null) return; - var toolTip = control.GetValue(ToolTipProperty); + toolTip = control.GetValue(ToolTipProperty); if (toolTip == null || (tip != toolTip && tip != toolTip.Content)) { toolTip?.Close(); @@ -223,9 +225,11 @@ namespace Avalonia.Controls } else { - var toolTip = control.GetValue(ToolTipProperty); + toolTip = control.GetValue(ToolTipProperty); toolTip?.Close(); } + + toolTip?.UpdatePseudoClasses(newValue); } private void Open(Control control) @@ -261,5 +265,10 @@ namespace Avalonia.Controls pr.PlatformImpl.SetWindowManagerAddShadowHint(hint); } } + + private void UpdatePseudoClasses(bool newValue) + { + PseudoClasses.Set(":open", newValue); + } } } From 5721702fadbd43619600d55fcfcd05c6be2956e6 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 3 Jun 2020 03:08:27 -0400 Subject: [PATCH 4/7] Fluent ToolTip style --- src/Avalonia.Themes.Fluent/ToolTip.xaml | 91 ++++++++++++++++++++----- 1 file changed, 74 insertions(+), 17 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/ToolTip.xaml b/src/Avalonia.Themes.Fluent/ToolTip.xaml index 1fc0202dd3..f3c4266f77 100644 --- a/src/Avalonia.Themes.Fluent/ToolTip.xaml +++ b/src/Avalonia.Themes.Fluent/ToolTip.xaml @@ -1,17 +1,74 @@ - \ No newline at end of file + + + + + Hover Here + + + + + + ToolTip + A control which pops up a hint when a control is hovered + + + ToolTip bottom placement + + + + + + + + + + From d2a5f525dafd7d8310947a169320b817511ace5f Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 4 Jun 2020 22:20:31 -0400 Subject: [PATCH 5/7] Add text wrapping to Fluent ToolTip --- src/Avalonia.Themes.Fluent/ToolTip.xaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/ToolTip.xaml b/src/Avalonia.Themes.Fluent/ToolTip.xaml index f3c4266f77..fa528ee6cf 100644 --- a/src/Avalonia.Themes.Fluent/ToolTip.xaml +++ b/src/Avalonia.Themes.Fluent/ToolTip.xaml @@ -8,7 +8,7 @@ Background="{DynamicResource ThemeAccentBrush}" Margin="5" Padding="50" - ToolTip.Tip="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."> + ToolTip.Tip="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."> Hover Here - + + + From bcd215e3db09e8c5a67774ff4b78599b2b9cf38b Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 4 Jun 2020 22:31:40 -0400 Subject: [PATCH 6/7] 150 ms opacity transition duration for ToolTip --- src/Avalonia.Themes.Fluent/ToolTip.xaml | 76 ++++++++++++------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/ToolTip.xaml b/src/Avalonia.Themes.Fluent/ToolTip.xaml index fa528ee6cf..cf6f32f9bc 100644 --- a/src/Avalonia.Themes.Fluent/ToolTip.xaml +++ b/src/Avalonia.Themes.Fluent/ToolTip.xaml @@ -1,39 +1,39 @@ - - + + Hover Here + + - Hover Here - - - - - - ToolTip - A control which pops up a hint when a control is hovered - - - ToolTip bottom placement - - + Grid.Row="0" + IsChecked="{Binding ElementName=Border, Path=(ToolTip.IsOpen)}" + Content="ToolTip Open" /> + + + + ToolTip + A control which pops up a hint when a control is hovered + + + ToolTip bottom placement + + - + - + From 53cb9d266d4f87789c30b37b55e6c5bf7cc095ae Mon Sep 17 00:00:00 2001 From: Max Katz Date: Fri, 5 Jun 2020 03:46:02 -0400 Subject: [PATCH 7/7] Add ToolTip :open pseudo class tests --- .../ToolTipTests.cs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/ToolTipTests.cs b/tests/Avalonia.Controls.UnitTests/ToolTipTests.cs index dc5b574db7..34b37e7635 100644 --- a/tests/Avalonia.Controls.UnitTests/ToolTipTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ToolTipTests.cs @@ -102,5 +102,76 @@ namespace Avalonia.Controls.UnitTests Assert.True(ToolTip.GetIsOpen(target)); } } + + [Fact] + public void Open_Class_Should_Not_Initially_Be_Added() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var toolTip = new ToolTip(); + var window = new Window(); + + var decorator = new Decorator() + { + [ToolTip.TipProperty] = toolTip + }; + + window.Content = decorator; + + window.ApplyTemplate(); + window.Presenter.ApplyTemplate(); + + Assert.Empty(toolTip.Classes); + } + } + + [Fact] + public void Setting_IsOpen_Should_Add_Open_Class() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var toolTip = new ToolTip(); + var window = new Window(); + + var decorator = new Decorator() + { + [ToolTip.TipProperty] = toolTip + }; + + window.Content = decorator; + + window.ApplyTemplate(); + window.Presenter.ApplyTemplate(); + + ToolTip.SetIsOpen(decorator, true); + + Assert.Equal(new[] { ":open" }, toolTip.Classes); + } + } + + [Fact] + public void Clearing_IsOpen_Should_Remove_Open_Class() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var toolTip = new ToolTip(); + var window = new Window(); + + var decorator = new Decorator() + { + [ToolTip.TipProperty] = toolTip + }; + + window.Content = decorator; + + window.ApplyTemplate(); + window.Presenter.ApplyTemplate(); + + ToolTip.SetIsOpen(decorator, true); + ToolTip.SetIsOpen(decorator, false); + + Assert.Empty(toolTip.Classes); + } + } } }