Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1648 - Prevent tab panels from disappearing #1651

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions FRBDK/Glue/Glue/Controls/MainPanelControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:plugins="clr-namespace:FlatRedBall.Glue.Plugins"
xmlns:controls1="clr-namespace:GlueFormsCore.Controls"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:converters="clr-namespace:FlatRedBall.Glue.Themes.Converters"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
PreviewKeyDown="UserControl_PreviewKeyDown"
Expand All @@ -28,16 +29,24 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Grid.Resources>
<converters:MinPanelConverter x:Key="MinPanelConverter"/>
</Grid.Resources>
<controls:ToolbarControl VerticalContentAlignment="Center" x:Name="ToolbarControl" Grid.Row="0"/>

<Grid Grid.Row="1" Margin="3">
<Grid.RowDefinitions>

<RowDefinition Height="{Binding TopPanelHeight, Mode=TwoWay}" />
<RowDefinition
Height="{Binding TopPanelHeight, Mode=TwoWay}"
MinHeight="{Binding TopTabItems.Count, Converter={StaticResource MinPanelConverter}}"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="{Binding BottomPanelHeight, Mode=TwoWay}" />
<RowDefinition
Height="{Binding BottomPanelHeight, Mode=TwoWay}"
MinHeight="{Binding BottomTabItems.Count, Converter={StaticResource MinPanelConverter}}"/>
</Grid.RowDefinitions>

<TabControl x:Name="TopTabControl"
Expand All @@ -58,11 +67,15 @@

<Grid Grid.Row="2" x:Name="CenterGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding LeftPanelWidth, Mode=TwoWay}" />
<ColumnDefinition
Width="{Binding LeftPanelWidth, Mode=TwoWay}"
MinWidth="{Binding LeftTabItems.Count, Converter={StaticResource MinPanelConverter}}" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="{Binding RightPanelWidth, Mode=TwoWay}" />
<ColumnDefinition
Width="{Binding RightPanelWidth, Mode=TwoWay}"
MinWidth="{Binding RightTabItems.Count, Converter={StaticResource MinPanelConverter}}"/>
</Grid.ColumnDefinitions>

<TabControl x:Name="LeftTabControl"
Expand Down
29 changes: 29 additions & 0 deletions FRBDK/Glue/Glue/Themes/Converters/MinPanelConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using FlatRedBall.Glue.Plugins;
using System.Globalization;
using System.Windows.Data;
using System.Windows;
using System;
using GlueFormsCore.Controls;
using GlueFormsCore.ViewModels;

namespace FlatRedBall.Glue.Themes.Converters;

/// <summary>
/// Used to determine the minimum length of a "panel" (grid section) in the main display
/// based on if it currently contains any tabs items.
/// </summary>
public class MinPanelConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not int count)
throw new InvalidOperationException();

return count > 0 ? 32 : 0; // Allow 0 (collapsed) for no tab items
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException("ConvertBack is not supported.");
}
}