Skip to content

Commit

Permalink
Add a close button to popups
Browse files Browse the repository at this point in the history
Make popups movable
  • Loading branch information
rampaa committed Feb 17, 2024
1 parent 445faf7 commit 9e7e9d4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
26 changes: 22 additions & 4 deletions JL.Windows/GUI/PopupWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,45 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="PopupWindow" PreviewMouseDown="Window_PreviewMouseDown"
Width="Auto" Height="Auto" SizeToContent="Height" MaxWidth="700" MaxHeight="520"
Width="Auto" Height="Auto" SizeToContent="Height" MaxWidth="700" MaxHeight="520" ResizeMode="NoResize"
Topmost="True" WindowStyle="None" AllowsTransparency="true" ShowInTaskbar="False" ContextMenuOpening="Window_ContextMenuOpening"
PreviewKeyDown="Window_PreviewKeyDown" Closing="Window_Closing" MouseEnter="OnMouseEnter" MouseLeave="OnMouseLeave"
x:ClassModifier="internal">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Name="TextBlockMiningModeReminder" FontSize="13" Padding="5,1,0,1"
<Grid Grid.Row="0" Name="TitleBarGrid" Visibility="Collapsed">
<Rectangle Name="TitleBar" VerticalAlignment="Top" MouseLeftButtonDown="TitleBar_MouseLeftButtonDown"
HorizontalAlignment="Stretch" Height="15" Opacity="1" Margin="0"
Fill="{Binding Path=Background,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
</Rectangle>

<Button x:Name="CloseButton" HorizontalAlignment="Right" Margin="0,0,10,0" Click="CloseButton_Click"
Content="x" VerticalAlignment="Top" Padding="0" BorderThickness="0" VerticalContentAlignment="Top"
Background="{Binding Path=Background,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
Foreground="{Binding Path=Foreground,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
ToolTip="Close" FontFamily="Meiryo UI" FontSize="14" Height="15">
</Button>
</Grid>

<TextBlock Grid.Row="1" Name="TextBlockMiningModeReminder" FontSize="13" Padding="5,0,0,0"
Visibility="Collapsed" TextWrapping="Wrap"
Background="{Binding Path=Background,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
Foreground="{Binding Path=Foreground,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
</TextBlock>

<ItemsControl Grid.Row="1" Name="ItemsControlButtons" Visibility="Collapsed"
<ItemsControl Grid.Row="2" Name="ItemsControlButtons" Visibility="Collapsed"
Background="{Binding Path=Background,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
<ItemsControl.ItemsPanel>
Expand All @@ -35,7 +53,7 @@
</ItemsControl.ItemsPanel>
</ItemsControl>

<ListView Grid.Row="2" VirtualizingStackPanel.VirtualizationMode="Recycling" Focusable="False"
<ListView Grid.Row="3" VirtualizingStackPanel.VirtualizationMode="Recycling" Focusable="False"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
VirtualizingPanel.IsVirtualizingWhenGrouping="True" VirtualizingPanel.ScrollUnit="Pixel"
BorderThickness="0" ScrollViewer.CanContentScroll="True" VirtualizingPanel.IsVirtualizing="True"
Expand Down
16 changes: 16 additions & 0 deletions JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,8 @@ public void EnableMiningMode()
{
MiningMode = true;

TitleBarGrid.Visibility = Visibility.Visible;

if (ConfigManager.ShowMiningModeReminder && Owner == MainWindow.Instance)
{
TextBlockMiningModeReminder.Visibility = Visibility.Visible;
Expand Down Expand Up @@ -1723,6 +1725,7 @@ public void HidePopup()
}

MiningMode = false;
TitleBarGrid.Visibility = Visibility.Collapsed;
TextBlockMiningModeReminder.Visibility = Visibility.Collapsed;
ItemsControlButtons.Visibility = Visibility.Collapsed;
ItemsControlButtons.ItemsSource = null;
Expand Down Expand Up @@ -1804,4 +1807,17 @@ private void PopupListView_MouseLeave(object sender, MouseEventArgs e)

return selectedDefinitions;
}

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
HidePopup();
}

private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton is MouseButtonState.Pressed)
{
DragMove();
}
}
}

0 comments on commit 9e7e9d4

Please sign in to comment.