From 2714933469c8be96a06572a311d337bbb90a14d1 Mon Sep 17 00:00:00 2001 From: Mike Carr Date: Sat, 14 Dec 2024 13:18:58 -0800 Subject: [PATCH] add nulls to dropdown to clear --- .../ViewModels/CameraSettingsTabViewModel.cs | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/OpenIPC_Config/ViewModels/CameraSettingsTabViewModel.cs b/OpenIPC_Config/ViewModels/CameraSettingsTabViewModel.cs index 1be3c57..3563e86 100644 --- a/OpenIPC_Config/ViewModels/CameraSettingsTabViewModel.cs +++ b/OpenIPC_Config/ViewModels/CameraSettingsTabViewModel.cs @@ -258,7 +258,25 @@ partial void OnSelectedFpvIntraQpChanged(string value) private void UpdateCombinedValue() { - CombinedFpvRoiRectValue = $"{FpvRoiRectLeft[0]}x{FpvRoiRectTop[0]}x{FpvRoiRectHeight[0]}x{FpvRoiRectWidth[0]}"; + var fpvRoiRectLeft = FpvRoiRectLeft[0]; + var fpvRoiRectTop = FpvRoiRectTop[0]; + var fpvRoiRectHeight = FpvRoiRectHeight[0]; + var fpvRoiRectWidth = FpvRoiRectWidth[0]; + + if (string.IsNullOrEmpty(fpvRoiRectLeft) && + string.IsNullOrEmpty(fpvRoiRectTop) && + string.IsNullOrEmpty(fpvRoiRectHeight) && + string.IsNullOrEmpty(fpvRoiRectWidth) + ) + { + // set to empty so that it removes the settings + CombinedFpvRoiRectValue = ""; + } + else + { + CombinedFpvRoiRectValue = $"{FpvRoiRectLeft[0]}x{FpvRoiRectTop[0]}x{FpvRoiRectHeight[0]}x{FpvRoiRectWidth[0]}"; + } + Log.Debug($"Combined value updated to {CombinedFpvRoiRectValue}"); UpdateYamlConfig(Majestic.FpvRoiRect, CombinedFpvRoiRectValue); } @@ -269,8 +287,14 @@ public void UpdateYamlConfig(string key, string newValue) _yamlConfig[key] = newValue; else _yamlConfig.Add(key, newValue); + + if (string.IsNullOrEmpty(newValue)) + { + _yamlConfig.Remove(key); + } } + private void InitializeCollections() { Resolution = new ObservableCollection @@ -298,17 +322,22 @@ private void InitializeCollections() Mirror = new ObservableCollection { "true", "false" }; FpvEnabled = new ObservableCollection { "true", "false" }; - FpvNoiseLevel = new ObservableCollection { "0", "1", "2" }; + FpvNoiseLevel = new ObservableCollection { "","0", "1", "2" }; + // Create an ObservableCollection with values from -30 to 30 FpvRoiQp = new ObservableCollection(Enumerable.Range(-30, 61).Select(i => i.ToString())); + FpvRoiQp.Insert(0,""); FpvRefEnhance = new ObservableCollection(Enumerable.Range(0, 10).Select(i => i.ToString())); + FpvRefEnhance.Insert(0,""); - FpvRefPred = new ObservableCollection { "true", "false" }; + FpvRefPred = new ObservableCollection { "", "true", "false" }; FpvIntraLine = new ObservableCollection(Enumerable.Range(0, 10).Select(i => i.ToString())); - FpvIntraQp = new ObservableCollection{ "true", "false" }; + FpvIntraLine.Insert(0,""); + + FpvIntraQp = new ObservableCollection{ "","true", "false" }; FpvRoiRectLeft = new ObservableCollection { "" }; }