Skip to content

Commit a92ebf5

Browse files
committed
Dynamic Height and Dynamic Icon Size
1 parent c0f46f2 commit a92ebf5

File tree

5 files changed

+156
-61
lines changed

5 files changed

+156
-61
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace Flow.Launcher.Converters
7+
{
8+
public class DiameterToCenterPointConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
if (value is double d)
13+
{
14+
return new Point(d / 2, d / 2);
15+
}
16+
17+
return new Point(0, 0);
18+
}
19+
20+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
21+
{
22+
throw new NotSupportedException();
23+
}
24+
}
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using Windows.Devices.PointOfService;
5+
6+
namespace Flow.Launcher.Converters
7+
{
8+
public class IconRadiusConverter : IMultiValueConverter
9+
{
10+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
if (values.Length != 2)
13+
throw new ArgumentException("IconRadiusConverter must have 2 parameters");
14+
15+
return values[1] switch
16+
{
17+
true => (double)values[0] / 2,
18+
false => (double)values[0],
19+
_ => throw new ArgumentException("The second argument should be boolean", nameof(values))
20+
};
21+
}
22+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
23+
{
24+
throw new NotSupportedException();
25+
}
26+
}
27+
}

Flow.Launcher/ResultListBox.xaml

Lines changed: 95 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<ListBox
2-
x:Class="Flow.Launcher.ResultListBox"
1+
<ListBox x:Class="Flow.Launcher.ResultListBox"
32
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
43
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
54
xmlns:converter="clr-namespace:Flow.Launcher.Converters"
@@ -31,6 +30,10 @@
3130
mc:Ignorable="d">
3231
<!-- IsSynchronizedWithCurrentItem: http://stackoverflow.com/a/7833798/2833083 -->
3332

33+
<ListBox.Resources>
34+
<converter:IconRadiusConverter x:Key="IconRadiusConverter" />
35+
<converter:DiameterToCenterPointConverter x:Key="DiameterToCenterPointConverter" />
36+
</ListBox.Resources>
3437
<ListBox.ItemTemplate>
3538
<DataTemplate>
3639
<Button HorizontalAlignment="Stretch">
@@ -40,8 +43,7 @@
4043
</ControlTemplate>
4144
</Button.Template>
4245
<Button.Content>
43-
<Grid
44-
Margin="0"
46+
<Grid Margin="0"
4547
HorizontalAlignment="Stretch"
4648
VerticalAlignment="Stretch"
4749
Cursor="Hand"
@@ -54,28 +56,30 @@
5456
<Grid.ColumnDefinitions>
5557
<ColumnDefinition Width="60" />
5658
<ColumnDefinition Width="9*" />
57-
<ColumnDefinition Width="Auto" MinWidth="8" />
59+
<ColumnDefinition Width="Auto"
60+
MinWidth="8" />
5861
</Grid.ColumnDefinitions>
59-
<StackPanel
60-
x:Name="HotkeyArea"
62+
<StackPanel x:Name="HotkeyArea"
6163
Grid.Column="2"
6264
Margin="0,0,10,0"
6365
VerticalAlignment="Center"
6466
Visibility="{Binding ShowOpenResultHotkey}">
65-
<TextBlock
66-
x:Name="Hotkey"
67+
<TextBlock x:Name="Hotkey"
6768
Margin="12,0,12,0"
6869
Padding="0,0,0,0"
6970
HorizontalAlignment="Right"
7071
VerticalAlignment="Center"
7172
Style="{DynamicResource ItemHotkeyStyle}">
7273
<TextBlock.Visibility>
73-
<Binding Converter="{StaticResource ResourceKey=OpenResultHotkeyVisibilityConverter}" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}" />
74+
<Binding
75+
Converter="{StaticResource ResourceKey=OpenResultHotkeyVisibilityConverter}"
76+
RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}" />
7477
</TextBlock.Visibility>
7578
<TextBlock.Text>
7679
<MultiBinding StringFormat="{}{0}+{1}">
7780
<Binding Path="OpenResultModifiers" />
78-
<Binding Converter="{StaticResource ResourceKey=OrdinalConverter}" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}" />
81+
<Binding Converter="{StaticResource ResourceKey=OrdinalConverter}"
82+
RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}" />
7983
</MultiBinding>
8084
</TextBlock.Text>
8185
</TextBlock>
@@ -87,20 +91,16 @@
8791
<ColumnDefinition />
8892
</Grid.ColumnDefinitions>
8993

90-
<Border
91-
x:Name="Bullet"
94+
<Border x:Name="Bullet"
9295
Grid.Column="0"
9396
Style="{DynamicResource BulletStyle}" />
9497

95-
<Border
96-
Grid.Column="1"
98+
<Border Grid.Column="1"
9799
Margin="9,0,0,0"
98100
BorderBrush="Transparent"
99101
BorderThickness="1">
100-
<Image
101-
x:Name="ImageIcon"
102-
Width="{Binding IconXY}"
103-
Height="{Binding IconXY}"
102+
<Image x:Name="ImageIcon"
103+
Style="{DynamicResource ImageIconStyle}"
104104
Margin="0,0,0,0"
105105
HorizontalAlignment="Center"
106106
IsHitTestVisible="False"
@@ -110,19 +110,30 @@
110110
Visibility="{Binding ShowIcon}">
111111
<Image.Clip>
112112
<EllipseGeometry
113-
Center="16 16"
114-
RadiusX="{Binding IconRadius}"
115-
RadiusY="{Binding IconRadius}" />
113+
Center="{Binding ElementName=ImageIcon, Path=ActualWidth, Converter={StaticResource DiameterToCenterPointConverter}}">
114+
<EllipseGeometry.RadiusX>
115+
<MultiBinding Converter="{StaticResource IconRadiusConverter}">
116+
<Binding ElementName="ImageIcon"
117+
Path="ActualWidth" />
118+
<Binding Path="Result.RoundedIcon" />
119+
</MultiBinding>
120+
</EllipseGeometry.RadiusX>
121+
<EllipseGeometry.RadiusY>
122+
<MultiBinding Converter="{StaticResource IconRadiusConverter}">
123+
<Binding ElementName="ImageIcon"
124+
Path="ActualWidth" />
125+
<Binding Path="Result.RoundedIcon" />
126+
</MultiBinding>
127+
</EllipseGeometry.RadiusY>
128+
</EllipseGeometry>
116129
</Image.Clip>
117130
</Image>
118131
</Border>
119-
<Border
120-
Grid.Column="1"
132+
<Border Grid.Column="1"
121133
Margin="9,0,0,0"
122134
BorderBrush="Transparent"
123135
BorderThickness="0">
124-
<TextBlock
125-
x:Name="GlyphIcon"
136+
<TextBlock x:Name="GlyphIcon"
126137
HorizontalAlignment="Center"
127138
VerticalAlignment="Center"
128139
FontFamily="{Binding Glyph.FontFamily}"
@@ -132,33 +143,35 @@
132143
</Border>
133144
</Grid>
134145

135-
<Grid
136-
Grid.Column="1"
146+
<Grid Grid.Column="1"
137147
Margin="6,0,10,0"
138148
HorizontalAlignment="Stretch"
139149
VerticalAlignment="Center">
140150
<Grid.RowDefinitions>
141151
<RowDefinition Height="Auto" />
142-
<RowDefinition x:Name="SubTitleRowDefinition" Height="Auto" />
152+
<RowDefinition x:Name="SubTitleRowDefinition"
153+
Height="Auto" />
143154
</Grid.RowDefinitions>
144-
<ProgressBar
145-
x:Name="progressbarResult"
155+
<ProgressBar x:Name="progressbarResult"
146156
Grid.Row="0"
147157
Foreground="{Binding Result.ProgressBarColor}"
148158
Value="{Binding ResultProgress, Mode=OneWay}">
149159
<ProgressBar.Style>
150-
<Style BasedOn="{StaticResource ProgressBarResult}" TargetType="ProgressBar">
151-
<Setter Property="Visibility" Value="Visible" />
160+
<Style BasedOn="{StaticResource ProgressBarResult}"
161+
TargetType="ProgressBar">
162+
<Setter Property="Visibility"
163+
Value="Visible" />
152164
<Style.Triggers>
153-
<DataTrigger Binding="{Binding Result.ProgressBar}" Value="{x:Null}">
154-
<Setter Property="Visibility" Value="Collapsed" />
165+
<DataTrigger Binding="{Binding Result.ProgressBar}"
166+
Value="{x:Null}">
167+
<Setter Property="Visibility"
168+
Value="Collapsed" />
155169
</DataTrigger>
156170
</Style.Triggers>
157171
</Style>
158172
</ProgressBar.Style>
159173
</ProgressBar>
160-
<TextBlock
161-
x:Name="Title"
174+
<TextBlock x:Name="Title"
162175
Grid.Row="0"
163176
VerticalAlignment="Center"
164177
DockPanel.Dock="Left"
@@ -175,8 +188,7 @@
175188
</MultiBinding>
176189
</vm:ResultsViewModel.FormattedText>
177190
</TextBlock>
178-
<TextBlock
179-
x:Name="SubTitle"
191+
<TextBlock x:Name="SubTitle"
180192
Grid.Row="1"
181193
IsEnabled="False"
182194
Style="{DynamicResource ItemSubTitleStyle}"
@@ -191,53 +203,76 @@
191203
</Button>
192204
<!-- a result item height is 52 including margin -->
193205
<DataTemplate.Triggers>
194-
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
195-
<Setter TargetName="Bullet" Property="Style" Value="{DynamicResource ItemBulletSelectedStyle}" />
196-
<Setter TargetName="Title" Property="Style" Value="{DynamicResource ItemTitleSelectedStyle}" />
197-
<Setter TargetName="SubTitle" Property="Style" Value="{DynamicResource ItemSubTitleSelectedStyle}" />
198-
<Setter TargetName="Hotkey" Property="Style" Value="{DynamicResource ItemHotkeySelectedStyle}" />
199-
<Setter TargetName="ImageIcon" Property="Style" Value="{DynamicResource ItemImageSelectedStyle}" />
200-
<Setter TargetName="GlyphIcon" Property="Style" Value="{DynamicResource ItemGlyphSelectedStyle}" />
206+
<DataTrigger
207+
Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"
208+
Value="True">
209+
<Setter TargetName="Bullet"
210+
Property="Style"
211+
Value="{DynamicResource ItemBulletSelectedStyle}" />
212+
<Setter TargetName="Title"
213+
Property="Style"
214+
Value="{DynamicResource ItemTitleSelectedStyle}" />
215+
<Setter TargetName="SubTitle"
216+
Property="Style"
217+
Value="{DynamicResource ItemSubTitleSelectedStyle}" />
218+
<Setter TargetName="Hotkey"
219+
Property="Style"
220+
Value="{DynamicResource ItemHotkeySelectedStyle}" />
221+
<Setter TargetName="ImageIcon"
222+
Property="Style"
223+
Value="{DynamicResource ItemImageSelectedStyle}" />
224+
<Setter TargetName="GlyphIcon"
225+
Property="Style"
226+
Value="{DynamicResource ItemGlyphSelectedStyle}" />
201227
</DataTrigger>
202228
</DataTemplate.Triggers>
203229
</DataTemplate>
204230
</ListBox.ItemTemplate>
205231
<!-- http://stackoverflow.com/questions/16819577/setting-background-color-or-wpf-4-0-listbox-windows-8/#16820062 -->
206232
<ListBox.ItemContainerStyle>
207233
<Style TargetType="{x:Type ListBoxItem}">
208-
<EventSetter Event="MouseEnter" Handler="OnMouseEnter" />
209-
<EventSetter Event="MouseMove" Handler="OnMouseMove" />
210-
<Setter Property="Height" Value="52" />
211-
<Setter Property="Margin" Value="0" />
212-
<Setter Property="Padding" Value="0" />
213-
<Setter Property="BorderThickness" Value="0" />
234+
<EventSetter Event="MouseEnter"
235+
Handler="OnMouseEnter" />
236+
<EventSetter Event="MouseMove"
237+
Handler="OnMouseMove" />
238+
<Setter Property="Height"
239+
Value="{DynamicResource ResultItemHeight}" />
240+
<Setter Property="Margin"
241+
Value="0" />
242+
<Setter Property="Padding"
243+
Value="0" />
244+
<Setter Property="BorderThickness"
245+
Value="0" />
214246
<Setter Property="Template">
215247
<Setter.Value>
216248
<ControlTemplate TargetType="{x:Type ListBoxItem}">
217-
<Border
218-
x:Name="Bd"
249+
<Border x:Name="Bd"
219250
Margin="{DynamicResource ItemMargin}"
220251
Background="{TemplateBinding Background}"
221252
BorderBrush="{TemplateBinding BorderBrush}"
222253
CornerRadius="{DynamicResource ItemRadius}"
223254
SnapsToDevicePixels="True">
224-
<ContentPresenter
225-
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
255+
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
226256
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
227257
Content="{TemplateBinding Content}"
228258
ContentStringFormat="{TemplateBinding ContentStringFormat}"
229259
ContentTemplate="{TemplateBinding ContentTemplate}"
230260
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
231261
</Border>
232262
<ControlTemplate.Triggers>
233-
<Trigger Property="IsSelected" Value="True">
234-
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource ItemSelectedBackgroundColor}" />
235-
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource ItemSelectedBackgroundColor}" />
263+
<Trigger Property="IsSelected"
264+
Value="True">
265+
<Setter TargetName="Bd"
266+
Property="Background"
267+
Value="{DynamicResource ItemSelectedBackgroundColor}" />
268+
<Setter TargetName="Bd"
269+
Property="BorderBrush"
270+
Value="{DynamicResource ItemSelectedBackgroundColor}" />
236271
</Trigger>
237272
</ControlTemplate.Triggers>
238273
</ControlTemplate>
239274
</Setter.Value>
240275
</Setter>
241276
</Style>
242277
</ListBox.ItemContainerStyle>
243-
</ListBox>
278+
</ListBox>

Flow.Launcher/Themes/Base.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<Thickness x:Key="ResultMargin">0</Thickness>
99
<!-- Further font customisations are dynamically loaded in Theme.cs -->
1010

11+
<system:Double x:Key="ResultItemHeight">52</system:Double>
12+
1113
<Style x:Key="BaseBulletStyle" TargetType="{x:Type Border}" />
1214
<Style
1315
x:Key="BulletStyle"
@@ -17,6 +19,12 @@
1719
x:Key="ItemBulletSelectedStyle"
1820
BasedOn="{StaticResource BaseBulletStyle}"
1921
TargetType="{x:Type Border}" />
22+
<Style
23+
x:Key="ImageIconStyle"
24+
TargetType="{x:Type Image}">
25+
<Setter Property="Height" Value="32"/>
26+
<Setter Property="Width" Value="32"/>
27+
</Style>
2028

2129
<Style x:Key="BaseQueryBoxStyle" TargetType="{x:Type TextBox}">
2230
<Setter Property="BorderThickness" Value="0" />

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public ResultsViewModel(Settings settings) : this()
4343

4444
#region Properties
4545

46-
public int MaxHeight => MaxResults * 52;
46+
public double MaxHeight => MaxResults * (double)Application.Current.FindResource("ResultItemHeight")!;
4747

4848
public int SelectedIndex { get; set; }
4949

0 commit comments

Comments
 (0)