Skip to content

Commit

Permalink
Fixes #1909 Gridview dark mode is hard to use (#1917)
Browse files Browse the repository at this point in the history
* Fixes #1909 Gridview dark mode is hard to use

* pr feedback
  • Loading branch information
rwmcintosh authored Mar 8, 2023
1 parent e960489 commit 4963347
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/OSPSuite.Assets/UIConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2458,8 +2458,6 @@ public static class Colors
/// </summary>
public static Color ChartDiagramBack = Color.White;

public static Color Disabled = Color.FromArgb(255, 247, 247, 249);

public static Color BelowLLOQ => Color.LightSkyBlue;
public static Color DefaultRowColor => Color.White;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@ public interface IHistoryBrowserConfiguration

IEnumerable<string> AllDynamicColumnNames { get; }
Color LabelColor { get; set; }
Color NotReversibleColor { get; set; }
}

public class HistoryBrowserConfiguration : IHistoryBrowserConfiguration
{
//cache: key is name of column, value is description
private readonly ICache<string, string> _dynamicColumns;
public Color LabelColor { get; set; }
public Color NotReversibleColor { get; set; }

public HistoryBrowserConfiguration()
{
_dynamicColumns = new Cache<string, string>();
LabelColor = Color.YellowGreen;
NotReversibleColor = Color.LightGray;
}

public void AddDynamicColumn(string dynamicColumnName, string dynamicColumnCaption)
Expand Down
2 changes: 1 addition & 1 deletion src/OSPSuite.UI/Controls/PKAnalysisPivotGridControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void onCustomDrawCell(PivotCustomDrawCellEventArgs e)
{
if (e.DataField != ValueField) return;
if (e.Value == null)
updateAppearanceBackColor(e.Appearance, Colors.Disabled);
updateAppearanceBackColor(e.Appearance, UIConstants.Colors.Disabled);
}

private void updateAppearanceBackColor(AppearanceObject appearance, Color color)
Expand Down
25 changes: 13 additions & 12 deletions src/OSPSuite.UI/Controls/UxGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ public class UxGridView : GridView
private DataTable rectangularSelectionOnlyTable => _gridViewToDataTableMapper.MapFrom(this, GetSelectedRows(), GetSelectedCells);

protected override string ViewName => "UxGridView";

/// <summary>
/// Color used for cell that are locked/disabled (End of gradient)
/// </summary>
protected Color _colorDisabled = Colors.Disabled;


public UxGridView(GridControl gridControl) : base(gridControl)
{
DoInit();
Expand Down Expand Up @@ -142,7 +137,7 @@ public void AdjustAppearance(RowStyleEventArgs e, bool isEnabled)
e.CombineAppearance(Appearance.Row);
else
{
AdjustAppearance(e, _colorDisabled);
AdjustAppearance(e, UIConstants.Colors.Disabled, UIConstants.Colors.TextDisabled);
}
}

Expand All @@ -151,23 +146,29 @@ public void AdjustAppearance(RowCellStyleEventArgs e, bool isEnabled)
if (isEnabled)
e.CombineAppearance(Appearance.Row);
else
AdjustAppearance(e, _colorDisabled);
AdjustAppearance(e, UIConstants.Colors.Disabled, UIConstants.Colors.TextDisabled);
}

public void AdjustAppearance(RowCellStyleEventArgs e, Color color)
public void AdjustAppearance(RowCellStyleEventArgs e, Color backgroundColor, Color foregroundColor)
{
if (rowHasFocus(e.RowHandle))
e.CombineAppearance(Appearance.FocusedCell);
else
UpdateAppearanceBackColor(e.Appearance, color);
{
UpdateAppearanceBackColor(e.Appearance, backgroundColor);
e.Appearance.ForeColor = foregroundColor;
}
}

public void AdjustAppearance(RowStyleEventArgs e, Color color)
public void AdjustAppearance(RowStyleEventArgs e, Color backgroundColor, Color foregroundColor)
{
if (rowHasFocus(e.RowHandle))
e.CombineAppearance(Appearance.FocusedRow);
else
UpdateAppearanceBackColor(e.Appearance, color);
{
UpdateAppearanceBackColor(e.Appearance, backgroundColor);
e.Appearance.ForeColor = foregroundColor;
}
}

public void UpdateAppearanceBackColor(AppearanceObject appearance, Color color)
Expand Down
13 changes: 13 additions & 0 deletions src/OSPSuite.UI/UIConstants.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using DevExpress.Skins;
using OSPSuite.Assets;

namespace OSPSuite.UI
{
public static class UIConstants
{
public static class Colors
{
// These colors change with the skin, so we use a method to read the latest up-to-date value from the skin
public static Color Disabled => skinColorFor("ReadOnly");
public static Color TextDisabled => skinColorFor("DisabledText");

private static Color skinColorFor(string state)
{
return CommonSkins.GetSkin(DevExpress.LookAndFeel.UserLookAndFeel.Default).Colors[state];
}
}

public const int TOOL_TIP_INITIAL_DELAY = 500;
public const int TOOL_TIP_INITIAL_DELAY_LONG = 1500;
public const string EMPTY_COLUMN = " ";
Expand Down
5 changes: 4 additions & 1 deletion src/OSPSuite.UI/Views/Commands/HistoryBrowserView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ private void historyTreeListNodeCellStyle(object sender, GetCustomNodeCellStyleE
if (_presenter.IsLabel(historyItemId))
e.Appearance.BackColor = _historyBrowserConfiguration.LabelColor;
else if (!_presenter.CanRollBackTo(historyItemId))
e.Appearance.BackColor = _historyBrowserConfiguration.NotReversibleColor;
{
e.Appearance.BackColor = UIConstants.Colors.Disabled;
e.Appearance.ForeColor = UIConstants.Colors.TextDisabled;
}
}
}
}
2 changes: 1 addition & 1 deletion src/OSPSuite.UI/Views/Comparisons/ComparisonView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void updateRowCellStyle(object sender, RowCellStyleEventArgs e)
if (dto == null) return;

if (dto.ItemIsMissing)
gridView.AdjustAppearance(e, Colors.ADDED_OR_MISSING);
gridView.AdjustAppearance(e, Colors.ADDED_OR_MISSING, e.Appearance.ForeColor);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void highlightRowsBelowLLOQ(RowStyleEventArgs e)
if (table == null) return;

var color = _presenter.BackgroundColorForRow(sourceRow);
gridView.AdjustAppearance(e, color);
gridView.AdjustAppearance(e, color, e.Appearance.ForeColor);
}

public override ApplicationIcon ApplicationIcon => ApplicationIcons.Parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void displayColumnReadOnly(DataColumn column)
if (gridViewColumn == null)
return;
gridViewColumn.OptionsColumn.AllowEdit = false;
gridViewColumn.AppearanceCell.BackColor = Colors.Disabled;
gridViewColumn.AppearanceCell.BackColor = UIConstants.Colors.Disabled;
}

private GridColumn gridViewColumnFromDataColumn(DataColumn column)
Expand Down

0 comments on commit 4963347

Please sign in to comment.