Skip to content

Commit d1ceba7

Browse files
committed
Adjust Inforbar
1 parent 43330db commit d1ceba7

File tree

3 files changed

+307
-3
lines changed

3 files changed

+307
-3
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<UserControl
2+
x:Class="Flow.Launcher.Resources.Controls.InfoBar"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:ui="http://schemas.modernwpf.com/2019"
9+
d:DesignHeight="45"
10+
d:DesignWidth="400"
11+
mc:Ignorable="d">
12+
<UserControl.Resources />
13+
<Grid>
14+
<Border
15+
x:Name="PART_Border"
16+
MinHeight="48"
17+
Padding="18 18 18 18"
18+
Background="{DynamicResource InfoBarInfoBG}"
19+
BorderBrush="{DynamicResource Color03B}"
20+
BorderThickness="1"
21+
CornerRadius="5">
22+
<Grid>
23+
<Grid.ColumnDefinitions>
24+
<ColumnDefinition Width="Auto" />
25+
<ColumnDefinition Width="*" />
26+
<ColumnDefinition Width="Auto" MinWidth="24" />
27+
</Grid.ColumnDefinitions>
28+
<StackPanel Grid.Column="0" Orientation="Horizontal">
29+
<Border
30+
x:Name="Part_IconBorder"
31+
Width="16" VerticalAlignment="Top"
32+
Height="16"
33+
Margin="0 0 12 0"
34+
CornerRadius="10">
35+
<ui:FontIcon
36+
x:Name="PART_Icon"
37+
Margin="1 0 0 1"
38+
VerticalAlignment="Center"
39+
FontFamily="Segoe MDL2 Assets"
40+
FontSize="13"
41+
Foreground="{DynamicResource Color01B}"
42+
Visibility="Visible" />
43+
</Border>
44+
45+
</StackPanel>
46+
<StackPanel
47+
x:Name="PART_StackPanel"
48+
Grid.Column="1"
49+
VerticalAlignment="Center"
50+
Orientation="Horizontal">
51+
<TextBlock
52+
x:Name="PART_Title"
53+
Margin="0 0 12 0"
54+
FontWeight="SemiBold"
55+
Foreground="{DynamicResource Color05B}"
56+
Text="{Binding Title}" />
57+
<TextBlock
58+
x:Name="PART_Message"
59+
Foreground="{DynamicResource Color05B}"
60+
Text="{Binding Message}"
61+
TextWrapping="Wrap" />
62+
</StackPanel>
63+
64+
<Button
65+
x:Name="PART_CloseButton"
66+
Grid.Column="2"
67+
Width="32"
68+
Height="32"
69+
VerticalAlignment="Center"
70+
Click="PART_CloseButton_Click"
71+
Content="&#xE10A;"
72+
FontFamily="Segoe MDL2 Assets"
73+
FontSize="12"
74+
Visibility="Visible" />
75+
</Grid>
76+
</Border>
77+
</Grid>
78+
</UserControl>
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
using System.Windows.Media;
4+
5+
namespace Flow.Launcher.Resources.Controls
6+
{
7+
public partial class InfoBar : UserControl
8+
{
9+
public InfoBar()
10+
{
11+
InitializeComponent();
12+
Loaded += InfoBar_Loaded;
13+
}
14+
15+
private void InfoBar_Loaded(object sender, RoutedEventArgs e)
16+
{
17+
UpdateStyle();
18+
UpdateTitleVisibility();
19+
UpdateMessageVisibility();
20+
UpdateOrientation();
21+
UpdateIconAlignmentAndMargin();
22+
23+
// DataContext 설정 (예시)
24+
this.DataContext = this; // InfoBar 자체를 DataContext로 사용
25+
}
26+
27+
public static readonly DependencyProperty TypeProperty =
28+
DependencyProperty.Register(nameof(Type), typeof(InfoBarType), typeof(InfoBar), new PropertyMetadata(InfoBarType.Info, OnTypeChanged));
29+
30+
public InfoBarType Type
31+
{
32+
get => (InfoBarType)GetValue(TypeProperty);
33+
set => SetValue(TypeProperty, value);
34+
}
35+
36+
private static void OnTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
37+
{
38+
if (d is InfoBar infoBar)
39+
{
40+
infoBar.UpdateStyle();
41+
}
42+
}
43+
44+
public static readonly DependencyProperty MessageProperty =
45+
DependencyProperty.Register(nameof(Message), typeof(string), typeof(InfoBar), new PropertyMetadata(string.Empty, OnMessageChanged));
46+
47+
public string Message
48+
{
49+
get => (string)GetValue(MessageProperty);
50+
set
51+
{
52+
SetValue(MessageProperty, value);
53+
UpdateMessageVisibility(); // Message 속성 변경 시 Visibility 업데이트
54+
}
55+
}
56+
57+
private static void OnMessageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
58+
{
59+
if (d is InfoBar infoBar)
60+
{
61+
infoBar.UpdateMessageVisibility();
62+
}
63+
}
64+
65+
private void UpdateMessageVisibility()
66+
{
67+
PART_Message.Visibility = string.IsNullOrEmpty(Message) ? Visibility.Collapsed : Visibility.Visible;
68+
}
69+
70+
public static readonly DependencyProperty TitleProperty =
71+
DependencyProperty.Register(nameof(Title), typeof(string), typeof(InfoBar), new PropertyMetadata(string.Empty, OnTitleChanged));
72+
73+
public string Title
74+
{
75+
get => (string)GetValue(TitleProperty);
76+
set
77+
{
78+
SetValue(TitleProperty, value);
79+
UpdateTitleVisibility(); // Title 속성 변경 시 Visibility 업데이트
80+
}
81+
}
82+
83+
private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
84+
{
85+
if (d is InfoBar infoBar)
86+
{
87+
infoBar.UpdateTitleVisibility();
88+
}
89+
}
90+
91+
private void UpdateTitleVisibility()
92+
{
93+
PART_Title.Visibility = string.IsNullOrEmpty(Title) ? Visibility.Collapsed : Visibility.Visible;
94+
}
95+
96+
public static readonly DependencyProperty IsIconVisibleProperty =
97+
DependencyProperty.Register(nameof(IsIconVisible), typeof(bool), typeof(InfoBar), new PropertyMetadata(true, OnIsIconVisibleChanged));
98+
99+
public bool IsIconVisible
100+
{
101+
get => (bool)GetValue(IsIconVisibleProperty);
102+
set => SetValue(IsIconVisibleProperty, value);
103+
}
104+
105+
public static readonly DependencyProperty LengthProperty =
106+
DependencyProperty.Register(nameof(Length), typeof(InfoBarLength), typeof(InfoBar), new PropertyMetadata(InfoBarLength.Short, OnLengthChanged));
107+
108+
public InfoBarLength Length
109+
{
110+
get { return (InfoBarLength)GetValue(LengthProperty); }
111+
set { SetValue(LengthProperty, value); }
112+
}
113+
114+
private static void OnLengthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
115+
{
116+
if (d is InfoBar infoBar)
117+
{
118+
infoBar.UpdateOrientation();
119+
infoBar.UpdateIconAlignmentAndMargin();
120+
}
121+
}
122+
123+
private void UpdateOrientation()
124+
{
125+
PART_StackPanel.Orientation = Length == InfoBarLength.Long ? Orientation.Vertical : Orientation.Horizontal;
126+
}
127+
128+
private void UpdateIconAlignmentAndMargin()
129+
{
130+
if (Length == InfoBarLength.Short)
131+
{
132+
Part_IconBorder.VerticalAlignment = VerticalAlignment.Center;
133+
Part_IconBorder.Margin = new Thickness(0, 0, 12, 0);
134+
}
135+
else
136+
{
137+
Part_IconBorder.VerticalAlignment = VerticalAlignment.Top;
138+
Part_IconBorder.Margin = new Thickness(0, 2, 12, 0);
139+
}
140+
}
141+
142+
public static readonly DependencyProperty ClosableProperty =
143+
DependencyProperty.Register(nameof(Closable), typeof(bool), typeof(InfoBar), new PropertyMetadata(true, OnClosableChanged));
144+
145+
public bool Closable
146+
{
147+
get => (bool)GetValue(ClosableProperty);
148+
set => SetValue(ClosableProperty, value);
149+
}
150+
151+
private void PART_CloseButton_Click(object sender, RoutedEventArgs e)
152+
{
153+
Visibility = Visibility.Collapsed;
154+
}
155+
156+
private void UpdateStyle()
157+
{
158+
switch (Type)
159+
{
160+
case InfoBarType.Info:
161+
PART_Border.Background = (Brush)FindResource("InfoBarInfoBG");
162+
Part_IconBorder.Background = (Brush)FindResource("InfoBarInfoIcon");
163+
PART_Icon.Glyph = "\xF13F";
164+
break;
165+
case InfoBarType.Success:
166+
PART_Border.Background = (Brush)FindResource("InfoBarSuccessBG");
167+
Part_IconBorder.Background = (Brush)FindResource("InfoBarSuccessIcon");
168+
PART_Icon.Glyph = "\xF13E";
169+
break;
170+
case InfoBarType.Warning:
171+
PART_Border.Background = (Brush)FindResource("InfoBarWarningBG");
172+
Part_IconBorder.Background = (Brush)FindResource("InfoBarWarningIcon");
173+
PART_Icon.Glyph = "\xF13C";
174+
break;
175+
case InfoBarType.Error:
176+
PART_Border.Background = (Brush)FindResource("InfoBarErrorBG");
177+
Part_IconBorder.Background = (Brush)FindResource("InfoBarErrorIcon");
178+
PART_Icon.Glyph = "\xF13D";
179+
break;
180+
}
181+
}
182+
183+
private static void OnIsIconVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
184+
{
185+
var infoBar = (InfoBar)d;
186+
infoBar.UpdateIconVisibility();
187+
}
188+
189+
private static void OnClosableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
190+
{
191+
var infoBar = (InfoBar)d;
192+
infoBar.UpdateCloseButtonVisibility();
193+
}
194+
195+
private void UpdateIconVisibility()
196+
{
197+
Part_IconBorder.Visibility = IsIconVisible ? Visibility.Visible : Visibility.Collapsed;
198+
}
199+
200+
private void UpdateCloseButtonVisibility()
201+
{
202+
PART_CloseButton.Visibility = Closable ? Visibility.Visible : Visibility.Collapsed;
203+
}
204+
}
205+
206+
public enum InfoBarType
207+
{
208+
Info,
209+
Success,
210+
Warning,
211+
Error
212+
}
213+
214+
public enum InfoBarLength
215+
{
216+
Short,
217+
Long
218+
}
219+
}

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@
3232
Title="Test"
3333
Closable="False"
3434
IsIconVisible="True"
35-
Length="Long"
35+
Length="Short"
3636
Message="This is a success message."
3737
Type="Info" />
3838
<cc:InfoBar
3939
Closable="True"
4040
IsIconVisible="True"
41-
Length="Long"
41+
Length="Short"
4242
Message="This is a success message."
4343
Type="Success" />
4444
<cc:InfoBar
4545
Title="Test"
4646
Closable="False"
4747
IsIconVisible="True"
4848
Length="Long"
49-
Message="This is a success message."
49+
Message="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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Curabitur pretium"
5050
Type="Warning" />
5151
<cc:InfoBar
5252
Title="Test"
@@ -55,6 +55,13 @@
5555
Length="Short"
5656
Message="This is a success message."
5757
Type="Error" />
58+
<cc:InfoBar
59+
Title="Test"
60+
Closable="False"
61+
IsIconVisible="False"
62+
Length="Short"
63+
Message="This is a success message."
64+
Type="Error" />
5865
<cc:ExCard
5966
Title="{DynamicResource startFlowLauncherOnSystemStartup}"
6067
Margin="0 8 0 0"

0 commit comments

Comments
 (0)