Skip to content

Commit 870f53a

Browse files
authored
Merge pull request #345 from garstenauer/fix-completionlist-style
Fix: CompletionList style is broken.
2 parents e3c7751 + 6b9480f commit 870f53a

File tree

6 files changed

+54
-61
lines changed

6 files changed

+54
-61
lines changed

src/AvaloniaEdit.Demo/App.xaml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
<Application xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:cc="clr-namespace:AvaloniaEdit.CodeCompletion;assembly=AvaloniaEdit"
43
x:Class="AvaloniaEdit.Demo.App"
54
RequestedThemeVariant="Dark">
65
<Application.Styles>
76
<FluentTheme />
87
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
98

10-
<!--Code completion-->
11-
<Style Selector="cc|CompletionList">
12-
<Setter Property="Template">
13-
<ControlTemplate>
14-
<cc:CompletionListBox Name="PART_ListBox" Background="Gray" BorderThickness="1" BorderBrush="LightGray" >
15-
<cc:CompletionListBox.ItemTemplate>
16-
<DataTemplate x:DataType="cc:ICompletionData">
17-
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Height="18">
18-
<Image Source="{Binding Image}"
19-
Width="15"
20-
Height="15" />
21-
<TextBlock VerticalAlignment="Center" Margin="10,0,0,0" Text="{Binding Content}" FontSize="15" FontFamily="Consolas" Foreground="#eeeeee"/>
22-
</StackPanel>
23-
</DataTemplate>
24-
</cc:CompletionListBox.ItemTemplate>
25-
</cc:CompletionListBox>
26-
</ControlTemplate>
27-
</Setter>
28-
</Style>
299
<!--
3010
<Style Selector="TextBlock.h1">
3111
<Setter Property="Foreground"
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<Styles xmlns="https://github.com/avaloniaui"
2-
32
xmlns:cc="clr-namespace:AvaloniaEdit.CodeCompletion;assembly=AvaloniaEdit"
4-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
x:CompileBindings="False">
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
64

75
<Style Selector="cc|CompletionList">
86
<Setter Property="Template">
97
<ControlTemplate>
10-
<cc:CompletionListBox Name="PART_ListBox" FontSize="11">
8+
<cc:CompletionListBox Name="PART_ListBox">
119
<cc:CompletionListBox.ItemTemplate>
1210
<DataTemplate x:DataType="cc:ICompletionData">
1311
<StackPanel Orientation="Horizontal" Margin="0">
@@ -24,26 +22,25 @@
2422
</Setter>
2523
</Style>
2624

27-
<Style Selector="cc|CompletionList > ListBox">
28-
<Setter Property="Padding" Value="0"/>
29-
30-
</Style>
25+
<Style Selector="cc|CompletionList > ListBox">
26+
<Setter Property="Padding" Value="0" />
27+
</Style>
28+
29+
<Style Selector="cc|CompletionList > ListBox > ListBoxItem">
30+
<Setter Property="Padding" Value="4,2" />
31+
</Style>
3132

32-
<Style Selector="cc|CompletionList > ListBox > ListBoxItem">
33-
<Setter Property="Padding" Value="4, 0, 0, 0"/>
34-
<Setter Property="Height" Value="20"/>
35-
</Style>
36-
3733
<Style Selector="ContentControl.ToolTip">
38-
<Setter Property="MinHeight" Value="22"/>
39-
<Setter Property="BorderThickness"
40-
Value="1" />
34+
<Setter Property="BorderThickness"
35+
Value="{DynamicResource CompletionToolTipBorderThickness}" />
4136
<Setter Property="BorderBrush"
42-
Value="Black" />
37+
Value="{DynamicResource CompletionToolTipBorderBrush}" />
4338
<Setter Property="Background"
44-
Value="#eeeeee" />
39+
Value="{DynamicResource CompletionToolTipBackground}" />
40+
<Setter Property="Foreground"
41+
Value="{DynamicResource CompletionToolTipForeground}" />
4542
<Setter Property="Padding"
46-
Value="2" />
43+
Value="4,2" />
4744
</Style>
4845

4946
</Styles>

src/AvaloniaEdit/CodeCompletion/CompletionWindow.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public CompletionWindow(TextArea textArea) : base(textArea)
5353
Child = CompletionList;
5454
// prevent user from resizing window to 0x0
5555
MinHeight = 15;
56-
MinWidth = 30;
56+
MinWidth = 30;
5757

5858
_toolTipContent = new ContentControl();
5959
_toolTipContent.Classes.Add("ToolTip");
@@ -62,7 +62,7 @@ public CompletionWindow(TextArea textArea) : base(textArea)
6262
{
6363
IsLightDismissEnabled = true,
6464
PlacementTarget = this,
65-
Placement = PlacementMode.Right,
65+
Placement = PlacementMode.RightEdgeAlignedTop,
6666
Child = _toolTipContent,
6767
};
6868

@@ -104,25 +104,30 @@ private void CompletionList_SelectionChanged(object sender, SelectionChangedEven
104104
};
105105
}
106106
else
107-
{
107+
{
108108
_toolTipContent.Content = description;
109109
}
110110

111111
_toolTip.IsOpen = false; //Popup needs to be closed to change position
112112

113-
//Calculate offset for tooltip
113+
// Calculate offset for tooltip
114+
var popupRoot = Host as PopupRoot;
114115
if (CompletionList.CurrentList != null)
115116
{
116-
int index = CompletionList.CurrentList.IndexOf(item);
117-
int scrollIndex = (int)CompletionList.ListBox.Scroll.Offset.Y;
118-
int yoffset = index - scrollIndex;
119-
if (yoffset < 0) yoffset = 0;
120-
if ((yoffset+1) * 20 > MaxHeight) yoffset--;
121-
_toolTip.Offset = new PixelPoint(2, yoffset * 20); //Todo find way to measure item height
117+
double yOffset = 0;
118+
var itemContainer = CompletionList.ListBox.ContainerFromItem(item);
119+
if (popupRoot != null && itemContainer != null)
120+
{
121+
var position = itemContainer.TranslatePoint(new Point(0, 0), popupRoot);
122+
if (position.HasValue)
123+
yOffset = position.Value.Y;
124+
}
125+
126+
_toolTip.Offset = new Point(2, yOffset);
122127
}
123128

124-
_toolTip.PlacementTarget = this.Host as PopupRoot;
125-
_toolTip.IsOpen = true;
129+
_toolTip.PlacementTarget = popupRoot;
130+
_toolTip.IsOpen = true;
126131
}
127132
else
128133
{

src/AvaloniaEdit/CodeCompletion/PopupWithCustomPosition.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ namespace AvaloniaEdit.CodeCompletion
55
{
66
internal class PopupWithCustomPosition : Popup
77
{
8-
public static readonly AvaloniaProperty<Point> OffsetProperty =
9-
AvaloniaProperty.Register<PopupWithCustomPosition, Point>(nameof(Offset));
10-
11-
public PixelPoint Offset
8+
public Point Offset
129
{
1310
get
1411
{
15-
return new PixelPoint((int)HorizontalOffset, (int)VerticalOffset);
12+
return new Point(HorizontalOffset, VerticalOffset);
1613
}
1714
set
1815
{
@@ -21,6 +18,6 @@ public PixelPoint Offset
2118

2219
//this.Revalidate(VerticalOffsetProperty);
2320
}
24-
}
21+
}
2522
}
2623
}

src/AvaloniaEdit/Themes/Fluent/Base.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:sys="using:System">
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
43
<StaticResource x:Key="SearchPanelFontSize" ResourceKey="ControlContentThemeFontSize" />
54
<StaticResource x:Key="SearchPanelFontFamily" ResourceKey="ContentControlThemeFontFamily" />
65
<ResourceDictionary.ThemeDictionaries>
76
<ResourceDictionary x:Key="Default">
7+
<StaticResource x:Key="CompletionToolTipBackground" ResourceKey="ToolTipBackground" />
8+
<StaticResource x:Key="CompletionToolTipForeground" ResourceKey="ToolTipForeground" />
9+
<StaticResource x:Key="CompletionToolTipBorderBrush" ResourceKey="ToolTipBorderBrush" />
10+
<StaticResource x:Key="CompletionToolTipBorderThickness" ResourceKey="ToolTipBorderThemeThickness" />
811
<SolidColorBrush x:Key="SearchPanelBackgroundBrush" Color="{DynamicResource SystemChromeMediumColor}" />
912
<SolidColorBrush x:Key="SearchPanelBorderBrush" Color="{DynamicResource SystemBaseLowColor}" />
1013
</ResourceDictionary>
1114
<ResourceDictionary x:Key="Dark">
15+
<StaticResource x:Key="CompletionToolTipBackground" ResourceKey="ToolTipBackground" />
16+
<StaticResource x:Key="CompletionToolTipForeground" ResourceKey="ToolTipForeground" />
17+
<StaticResource x:Key="CompletionToolTipBorderBrush" ResourceKey="ToolTipBorderBrush" />
18+
<StaticResource x:Key="CompletionToolTipBorderThickness" ResourceKey="ToolTipBorderThemeThickness" />
1219
<SolidColorBrush x:Key="SearchPanelBackgroundBrush" Color="{DynamicResource SystemChromeMediumColor}" />
1320
<SolidColorBrush x:Key="SearchPanelBorderBrush" Color="{DynamicResource SystemBaseLowColor}" />
1421
</ResourceDictionary>

src/AvaloniaEdit/Themes/Simple/Base.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:sys="using:System">
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
43
<StaticResource x:Key="SearchPanelFontSize" ResourceKey="FontSizeNormal" />
54
<StaticResource x:Key="SearchPanelFontFamily" ResourceKey="ContentControlThemeFontFamily" />
65
<ResourceDictionary.ThemeDictionaries>
76
<ResourceDictionary x:Key="Default">
7+
<StaticResource x:Key="CompletionToolTipBackground" ResourceKey="ThemeBackgroundBrush" />
8+
<StaticResource x:Key="CompletionToolTipForeground" ResourceKey="ThemeForegroundColor" />
9+
<StaticResource x:Key="CompletionToolTipBorderBrush" ResourceKey="ThemeBorderMidBrush" />
10+
<StaticResource x:Key="CompletionToolTipBorderThickness" ResourceKey="ThemeBorderThickness" />
811
<SolidColorBrush x:Key="SearchPanelBackgroundBrush" Color="{DynamicResource ThemeBackgroundColor}" />
912
<SolidColorBrush x:Key="SearchPanelBorderBrush" Color="{DynamicResource ThemeBorderLowColor}" />
1013
</ResourceDictionary>
1114
<ResourceDictionary x:Key="Dark">
15+
<StaticResource x:Key="CompletionToolTipBackground" ResourceKey="ThemeBackgroundBrush" />
16+
<StaticResource x:Key="CompletionToolTipForeground" ResourceKey="ThemeForegroundColor" />
17+
<StaticResource x:Key="CompletionToolTipBorderBrush" ResourceKey="ThemeBorderMidBrush" />
18+
<StaticResource x:Key="CompletionToolTipBorderThickness" ResourceKey="ThemeBorderThickness" />
1219
<SolidColorBrush x:Key="SearchPanelBackgroundBrush" Color="{DynamicResource ThemeBackgroundColor}" />
1320
<SolidColorBrush x:Key="SearchPanelBorderBrush" Color="{DynamicResource ThemeBorderLowColor}" />
1421
</ResourceDictionary>

0 commit comments

Comments
 (0)