mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
TrySplitPanel now migrates PanelTitle to children
This commit is contained in:
@@ -248,7 +248,8 @@ namespace Terminal.Gui {
|
||||
/// is already a <see cref="SplitContainer"/> then returns false.
|
||||
/// </summary>
|
||||
/// <remarks>After successful splitting, the returned container's <see cref="Panel1"/>
|
||||
/// will contain the original content (if any) while <see cref="Panel2"/> will be empty and available
|
||||
/// will contain the original content and <see cref="Panel1Title"/> (if any) while
|
||||
/// <see cref="Panel2"/> will be empty and available for adding to.
|
||||
/// for adding to.</remarks>
|
||||
/// <param name="result">The new <see cref="SplitContainer"/> now showing in
|
||||
/// <see cref="Panel1"/> or the existing one if it was already been converted before.</param>
|
||||
@@ -257,10 +258,22 @@ namespace Terminal.Gui {
|
||||
/// <see cref="SplitContainer"/></returns>
|
||||
public bool TrySplitPanel1(out SplitContainer result)
|
||||
{
|
||||
return TrySplit (
|
||||
() => this.Panel1,
|
||||
(n) => this.Panel1 = n,
|
||||
// when splitting a panel into 2 sub panels we will need to migrate
|
||||
// the title too
|
||||
var title = Panel1Title;
|
||||
|
||||
bool returnValue = TrySplit (
|
||||
this.Panel1,
|
||||
(newSplitContainer) => {
|
||||
this.Panel1 = newSplitContainer;
|
||||
|
||||
// Move title to new container
|
||||
Panel1Title = string.Empty;
|
||||
newSplitContainer.Panel1Title = title;
|
||||
},
|
||||
out result);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -269,7 +282,8 @@ namespace Terminal.Gui {
|
||||
/// is already a <see cref="SplitContainer"/> then returns false.
|
||||
/// </summary>
|
||||
/// <remarks>After successful splitting, the returned container's <see cref="Panel1"/>
|
||||
/// will contain the original content (if any) while <see cref="Panel2"/> will be empty and available
|
||||
/// will contain the original content and <see cref="Panel2Title"/> (if any) while
|
||||
/// <see cref="Panel2"/> will be empty and available for adding to.
|
||||
/// for adding to.</remarks>
|
||||
/// <param name="result">The new <see cref="SplitContainer"/> now showing in
|
||||
/// <see cref="Panel2"/> or the existing one if it was already been converted before.</param>
|
||||
@@ -278,19 +292,31 @@ namespace Terminal.Gui {
|
||||
/// <see cref="SplitContainer"/></returns>
|
||||
public bool TrySplitPanel2 (out SplitContainer result)
|
||||
{
|
||||
return TrySplit (
|
||||
() => this.Panel2,
|
||||
(n) => this.Panel2 = n,
|
||||
// when splitting a panel into 2 sub panels we will need to migrate
|
||||
// the title too
|
||||
var title = Panel2Title;
|
||||
|
||||
bool returnValue = TrySplit (
|
||||
this.Panel2,
|
||||
(newSplitContainer) => {
|
||||
this.Panel2 = newSplitContainer;
|
||||
|
||||
// Move title to new container
|
||||
Panel2Title = string.Empty;
|
||||
|
||||
// Content always goes into Panel1 of the new container
|
||||
// so that is where the title goes too
|
||||
newSplitContainer.Panel1Title = title;
|
||||
},
|
||||
out result);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
private bool TrySplit(
|
||||
Func<View> getter,
|
||||
View toMove,
|
||||
Action<SplitContainer> newSplitContainerSetter,
|
||||
out SplitContainer result)
|
||||
{
|
||||
// Get the current panel contents (Panel1 or Panel2)
|
||||
var toMove = getter();
|
||||
|
||||
if (toMove is SplitContainer existing) {
|
||||
result = existing;
|
||||
return false;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using Terminal.Gui;
|
||||
using Terminal.Gui.Graphs;
|
||||
|
||||
@@ -174,8 +175,9 @@ namespace UICatalog.Scenarios {
|
||||
|
||||
panelsCreated++;
|
||||
|
||||
// we can split Panel1
|
||||
SetPanelTitles (newContainer, panelsCreated);
|
||||
// During splitting the old Title will have been migrated to Panel1 so we only need
|
||||
// to set the Title on Panel2 (the one that gets our new TextView)
|
||||
newContainer.Panel2Title = cbTitles.Checked ? $"Panel {panelsCreated}" : string.Empty;
|
||||
|
||||
// Flip orientation
|
||||
newContainer.Orientation = newContainer.Orientation == Orientation.Vertical ?
|
||||
@@ -185,12 +187,6 @@ namespace UICatalog.Scenarios {
|
||||
newContainer.Panel2.Add (CreateTextView (panelsCreated));
|
||||
}
|
||||
|
||||
private void SetPanelTitles (SplitContainer container, int containerNumber)
|
||||
{
|
||||
container.Panel1Title = cbTitles.Checked ? $"Panel {containerNumber}" : string.Empty;
|
||||
container.Panel2Title = cbTitles.Checked ? $"Panel {containerNumber + 1}" : string.Empty;
|
||||
}
|
||||
|
||||
private SplitContainer CreateSplitContainer (int titleNumber, Orientation orientation)
|
||||
{
|
||||
var toReturn = new SplitContainer {
|
||||
@@ -200,7 +196,8 @@ namespace UICatalog.Scenarios {
|
||||
Orientation = orientation
|
||||
};
|
||||
|
||||
SetPanelTitles (toReturn, titleNumber);
|
||||
toReturn.Panel1Title = cbTitles.Checked ? $"Panel {titleNumber}" : string.Empty;
|
||||
toReturn.Panel2Title = cbTitles.Checked ? $"Panel {titleNumber + 1}" : string.Empty;
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user