From 8b1aa725ab579fbbbf3844438bdce53ee21a630f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szil=C3=A1gyi=20D=C3=A1niel?= Date: Thu, 29 Sep 2022 16:13:38 +0200 Subject: [PATCH] FlightData: Left panel hiding v1 FlightData: Left panel hiding subscribed to events FlightData: Left panel hiding method documentation --- GCSViews/FlightData.Designer.cs | 6 ++++++ GCSViews/FlightData.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/GCSViews/FlightData.Designer.cs b/GCSViews/FlightData.Designer.cs index 9f7396cb8e..ce472c417b 100644 --- a/GCSViews/FlightData.Designer.cs +++ b/GCSViews/FlightData.Designer.cs @@ -295,6 +295,8 @@ private void InitializeComponent() // SubMainLeft.Panel1 // this.SubMainLeft.Panel1.Controls.Add(this.hud1); + this.SubMainLeft.Panel1.ControlAdded += (sender, e) => ManageLeftPanelVisibility(); + this.SubMainLeft.Panel1.ControlRemoved += (sender, e) => ManageLeftPanelVisibility(); // // SubMainLeft.Panel2 // @@ -551,6 +553,8 @@ private void InitializeComponent() this.tabControlactions.SelectedIndex = 0; this.tabControlactions.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.tabControl1_DrawItem); this.tabControlactions.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged); + this.tabControlactions.ControlAdded += (sender, e) => ManageLeftPanelVisibility(); + this.tabControlactions.ControlRemoved += (sender, e) => ManageLeftPanelVisibility(); // // contextMenuStripactionstab // @@ -2258,6 +2262,8 @@ private void InitializeComponent() // resources.ApplyResources(this.panel_persistent, "panel_persistent"); this.panel_persistent.Name = "panel_persistent"; + this.panel_persistent.ControlAdded += (sender, e) => ManageLeftPanelVisibility(); + this.panel_persistent.ControlRemoved += (sender, e) => ManageLeftPanelVisibility(); // // tableMap // diff --git a/GCSViews/FlightData.cs b/GCSViews/FlightData.cs index d3ca0f6ba9..6919ceed4e 100644 --- a/GCSViews/FlightData.cs +++ b/GCSViews/FlightData.cs @@ -2895,6 +2895,33 @@ private void hud1_vibeclick(object sender, EventArgs e) frm.Show(); } + /// + /// Collapses or expands MainH.Panel1 depending on no. of controls within. + /// If you add controls to SubMainLeft that can be hidden, displaced or removed, add their first parent control here.
+ /// Otherwise they'll prevent the collapsing of SubMainLeft. + ///
+ private void ManageLeftPanelVisibility() + { + // Define controls to check, ADD THEM HERE + List controlsToCheck = new List() + { + SubMainLeft.Panel1, // contains hud1 + panel_persistent, // might contain plugin controls + tabControlactions // contains the tabs + }; + + bool controlsEmpty = controlsToCheck.Sum(x => x.Controls.Count) == 0; + bool panelVisible = !MainH.Panel1Collapsed; + + // if controls are empty, but panel is visible -> hide + if (controlsEmpty && panelVisible) + MainH.Panel1Collapsed = true; + + // if controls have content, but panel is hidden -> show + if (!controlsEmpty && !panelVisible) + MainH.Panel1Collapsed = false; + } + private void loadFileToolStripMenuItem_Click(object sender, EventArgs e) { POI.POILoad();