using DataModel.Database; using Processor; using UI_WinForms.Resources; namespace UI_WinForms.Components; public partial class Setting : UserControl { private readonly SettingUIData settingData; public Setting() { this.InitializeComponent(); } private Setting(SettingUIData settingData) { this.InitializeComponent(); this.settingData = settingData; this.labelIcon.Image = settingData.Icon; this.labelSettingName.Text = settingData.SettingName(); this.labelExplanation.Text = settingData.SettingExplanation(); var dataControl = this.settingData.SetupDataControl(); this.tableLayout.Controls.Add(dataControl, 2, 0); } private void buttonSave_Click(object sender, EventArgs e) { } private readonly record struct SettingUIData( Bitmap Icon, Func SettingName, Func SettingExplanation, Func SetupDataControl, Func GetCurrentSetting, Func SaveSetting ); public static async Task> ShowDeepLSettingAsync() { var currentSetting = await AppSettings.GetDeepLMode(); var settingData = new Setting.SettingUIData( Icon: Icons.deepl_logo_icon_170284, SettingName: () => "DeepL Service", SettingExplanation: () => "DeepL is a translation service that offers a wide range of translation services. This setting allows you to choose between the free and pro version of DeepL.", SetupDataControl: () => { var dropdown = new ComboBox(); dropdown.Items.Add("Disabled"); dropdown.Items.Add("Free version"); dropdown.Items.Add("Pro version"); dropdown.SelectedIndex = currentSetting switch { SettingDeepL.DISABLED => 0, SettingDeepL.USE_FREE_ACCOUNT => 1, SettingDeepL.USE_PRO_ACCOUNT => 2, _ => 0, }; // Apply the desired design: dropdown.Dock = DockStyle.Fill; dropdown.DropDownStyle = ComboBoxStyle.DropDownList; return dropdown; }, GetCurrentSetting: () => currentSetting, SaveSetting: async setting => await AppSettings.SetDeepLMode(setting)); return new Setting(settingData) { Dock = DockStyle.Top, }; } }