elfisa-pharmacy/src/ElectronicPharmacy/Classes/UiThemeHelper.cs
Magomed 5cc202dea7 Polish cart tabs and dialog chrome for light/dark themes.
Add ModernTabControl/SplitContainer for cart UI without system borders, fix button corner artifacts and dialog text contrast, and use TitleBarTop green for auth header in light mode.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-14 20:32:54 +03:00

143 lines
5.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Drawing;
using System.Windows.Forms;
using Elfisa.UI.Controls;
using Elfisa.UI.Theming;
namespace Электроннаяармация.Classes
{
public static class UiThemeHelper
{
public static void ApplyToControlTree(Control root)
{
if (root == null)
{
return;
}
new ThemeService().Apply(root);
ApplyLegacyControls(root, ThemeManager.Colors);
}
private static void ApplyLegacyControls(Control control, ThemeColors theme)
{
if (control is ModernDataGridView modernGrid)
{
modernGrid.ApplyTheme(theme);
}
else if (control is ModernButton modernButton)
{
modernButton.ApplyTheme(theme);
if (!modernButton.HeaderNavMode && !modernButton.TopNavMode && !modernButton.SidebarMode)
{
modernButton.AllowTextEllipsis = false;
ModernButtonStyles.ApplyAuto(modernButton);
}
}
else if (control is ModernTextBox modernTextBox)
{
modernTextBox.ApplyTheme(theme);
}
else if (control is ModernNumericUpDown modernNumeric)
{
modernNumeric.ApplyTheme(theme);
}
else if (control is ModernSearchBox modernSearch)
{
modernSearch.ApplyTheme(theme);
}
else if (control is DataGridView grid)
{
grid.EnableHeadersVisualStyles = false;
grid.BackgroundColor = theme.GridRowBackground;
grid.GridColor = theme.GridBorder;
grid.ColumnHeadersDefaultCellStyle.BackColor = theme.GridHeaderBackground;
grid.ColumnHeadersDefaultCellStyle.ForeColor = theme.GridHeaderForeground;
grid.ColumnHeadersDefaultCellStyle.Font = theme.FontSemibold14;
grid.DefaultCellStyle.BackColor = theme.GridRowBackground;
grid.DefaultCellStyle.ForeColor = theme.TextPrimary;
grid.DefaultCellStyle.SelectionBackColor = theme.GridRowSelected;
grid.DefaultCellStyle.SelectionForeColor = theme.GridRowSelectedText;
grid.DefaultCellStyle.Font = theme.FontRegular13;
grid.AlternatingRowsDefaultCellStyle.BackColor = theme.GridRowAlternate;
}
else if (control is Button button)
{
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderColor = theme.Border;
button.BackColor = theme.Surface;
button.ForeColor = theme.TextPrimary;
button.Font = theme.FontRegular13;
}
else if (control is TextBox textBox)
{
textBox.BackColor = theme.InputBackground;
textBox.ForeColor = theme.TextPrimary;
textBox.BorderStyle = BorderStyle.FixedSingle;
textBox.Font = theme.FontRegular13;
}
else if (control is NumericUpDown numeric)
{
numeric.BackColor = theme.InputBackground;
numeric.ForeColor = theme.TextPrimary;
numeric.Font = theme.FontRegular13;
}
else if (control is CheckBox checkBox)
{
checkBox.ForeColor = theme.TextPrimary;
checkBox.Font = theme.FontRegular13;
}
else if (control is Label label)
{
label.ForeColor = theme.TextPrimary;
label.Font = theme.FontRegular13;
}
else if (control is ModernTabControl modernTabControl)
{
modernTabControl.ApplyTheme(theme);
}
else if (control is ModernSplitContainer modernSplitContainer)
{
modernSplitContainer.ApplyTheme(theme);
}
else if (control is TabControl tabControl)
{
tabControl.BackColor = theme.BackgroundSecondary;
tabControl.Font = theme.FontRegular13;
}
else if (control is ToolStrip toolStrip)
{
toolStrip.BackColor = theme.TitleBarBottom;
toolStrip.ForeColor = Color.White;
}
else if (control is SplitContainer splitContainer)
{
splitContainer.BackColor = theme.Mode == ThemeMode.Dark ? theme.BorderSubtle : theme.Border;
splitContainer.Panel1.BackColor = theme.BackgroundPrimary;
splitContainer.Panel2.BackColor = theme.BackgroundPrimary;
}
else if (control is Panel || control is UserControl || control is TableLayoutPanel)
{
if (control.Tag as string == "keep-bg")
{
// preserve custom background
}
else if (control.Tag as string == "chrome-child")
{
control.BackColor = theme.BackgroundPrimary;
control.ForeColor = theme.TextPrimary;
}
else
{
control.BackColor = theme.BackgroundSecondary;
control.ForeColor = theme.TextPrimary;
}
}
foreach (Control child in control.Controls)
{
ApplyLegacyControls(child, theme);
}
}
}
}