Skip to content

Commit

Permalink
Merge pull request #252 from leocb/orapps44-MaterialListBox-disabled
Browse files Browse the repository at this point in the history
Fix MaterialListBox disabled mode colors
  • Loading branch information
orapps44 authored Oct 20, 2021
2 parents 8077fa3 + 3f62348 commit 01b6319
Showing 1 changed file with 28 additions and 92 deletions.
120 changes: 28 additions & 92 deletions MaterialSkin/Controls/MaterialListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,12 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
//using System.Collections.Specialized;
using System.Runtime.InteropServices;
//using System.Collections;
//using System.Windows.Forms.Design;
//using System.ComponentModel.Design;

#endregion

namespace MaterialSkin.Controls
{
#region MaterialListBoxDesignerDesign

//internal class MaterialListBoxDesigner : ControlDesigner
//{
// private readonly string[] _propertiesToRemove =
// {
// "BackgroundImage", "BackgroundImageLayout",
// "RightToLeft","ImeMode"
// };

// protected override void PostFilterProperties(IDictionary properties)
// {
// foreach (string property in _propertiesToRemove)
// {
// properties.Remove(property);
// }

// base.PostFilterProperties(properties);
// }

// private DesignerActionListCollection _actionListCollection;

// public override DesignerActionListCollection ActionLists => _actionListCollection ?? (_actionListCollection = new DesignerActionListCollection { new MaterialListBoxActionList(Component) });
//}
#endregion

#region MaterialListBox

Expand All @@ -53,54 +24,6 @@ namespace MaterialSkin.Controls
[ComVisible(true)]
public class MaterialListBox : Control, IMaterialControl
{
#region Interfaces

//[Category("Metro"), Description("Gets or sets the style associated with the control.")]
//public Style Style
//{
// get => StyleManager?.Style ?? _style;
// set
// {
// _style = value;
// switch (value)
// {
// case Style.Light:
// ApplyTheme();
// break;
// case Style.Dark:
// ApplyTheme(Style.Dark);
// break;
// case Style.Custom:
// ApplyTheme(Style.Custom);
// break;
// default:
// ApplyTheme();
// break;
// }
// _scrollBar.Style = value;
// Invalidate();
// }
//}

//[Category("Metro"), Description("Gets or sets the Style Manager associated with the control.")]
//public MetroStyleManager StyleManager
//{
// get => _styleManager;
// set
// {
// _styleManager = value;
// Invalidate();
// }
//}

//[Category("Metro"), Description("Gets or sets the The Author name associated with the theme.")]
//public string ThemeAuthor { get; set; }

//[Category("Metro"), Description("Gets or sets the The Theme name associated with the theme.")]
//public string ThemeName { get; set; }

#endregion Interfaces

#region Internal Vars

private ObservableCollection<MaterialListBoxItem> _items = new ObservableCollection<MaterialListBoxItem>();
Expand Down Expand Up @@ -390,16 +313,6 @@ private void UpdateProperties()

private void UpdateItemSpecs()
{
//_leftrightPadding = 16;
//if (_style == ListBoxStyle.SingleLine)
//{
// if (_density == MaterialItemDensity.Dense)
// _itemHeight = 40;
// else
// _itemHeight = 48;
// base.Font = SkinManager.getFontByType(MaterialSkinManager.fontType.Subtitle1);
// _secondaryFont = SkinManager.getFontByType(MaterialSkinManager.fontType.Body1);
//}
if (_style == ListBoxStyle.TwoLine)
{
_secondaryTextTopPadding = 4;
Expand Down Expand Up @@ -482,6 +395,14 @@ protected override void OnPaint(PaintEventArgs e)
primaryTextAlignFlags = NativeTextRenderer.TextAlignFlags.Left | NativeTextRenderer.TextAlignFlags.Middle;
}

//Set color and brush
Color SelectedColor = new Color();
if (UseAccentColor)
SelectedColor = SkinManager.ColorScheme.AccentColor;
else
SelectedColor = SkinManager.ColorScheme.PrimaryColor;
SolidBrush SelectedBrush = new SolidBrush(SelectedColor);

//Draw items
for (int i = firstItem; i < lastItem; i++)
{
Expand All @@ -498,7 +419,10 @@ protected override void OnPaint(PaintEventArgs e)
}
else if (_indicates.Contains(i))
{
g.FillRectangle(UseAccentColor ? SkinManager.ColorScheme.AccentBrush : SkinManager.ColorScheme.PrimaryBrush, itemRect);
g.FillRectangle(Enabled ?
SelectedBrush :
new SolidBrush(DrawHelper.BlendColor(SelectedColor, SkinManager.SwitchOffDisabledThumbColor, 197)),
itemRect);
}
}
else
Expand All @@ -509,7 +433,10 @@ protected override void OnPaint(PaintEventArgs e)
}
else if (i == SelectedIndex)
{
g.FillRectangle(UseAccentColor ? SkinManager.ColorScheme.AccentBrush : SkinManager.ColorScheme.PrimaryBrush, itemRect);
g.FillRectangle(Enabled ?
SelectedBrush :
new SolidBrush(DrawHelper.BlendColor(SelectedColor, SkinManager.SwitchOffDisabledThumbColor, 197)),
itemRect);
}
}

Expand Down Expand Up @@ -539,7 +466,10 @@ protected override void OnPaint(PaintEventArgs e)
NativeText.DrawTransparentText(
itemText,
_primaryFont,
(i != SelectedIndex || UseAccentColor) ? SkinManager.TextHighEmphasisColor : SkinManager.ColorScheme.TextColor,
Enabled ? (i != SelectedIndex || UseAccentColor) ?
SkinManager.TextHighEmphasisColor :
SkinManager.ColorScheme.TextColor :
SkinManager.TextDisabledOrHintColor, // Disabled
primaryTextRect.Location,
primaryTextRect.Size,
primaryTextAlignFlags);
Expand All @@ -548,7 +478,10 @@ protected override void OnPaint(PaintEventArgs e)
NativeText.DrawTransparentText(
itemSecondaryText,
_secondaryFont,
(i != SelectedIndex || UseAccentColor) ? SkinManager.TextDisabledOrHintColor : SkinManager.ColorScheme.TextColor.Darken(0.25f),
Enabled ? (i != SelectedIndex || UseAccentColor) ?
SkinManager.TextDisabledOrHintColor :
SkinManager.ColorScheme.TextColor.Darken(0.25f) :
SkinManager.TextDisabledOrHintColor, // Disabled
secondaryTextRect.Location,
secondaryTextRect.Size,
secondaryTextAlignFlags);
Expand All @@ -558,7 +491,10 @@ protected override void OnPaint(PaintEventArgs e)
NativeText.DrawMultilineTransparentText(
itemSecondaryText,
_secondaryFont,
(i != SelectedIndex || UseAccentColor) ? SkinManager.TextDisabledOrHintColor : SkinManager.ColorScheme.TextColor.Darken(0.25f),
Enabled ? (i != SelectedIndex || UseAccentColor) ?
SkinManager.TextDisabledOrHintColor :
SkinManager.ColorScheme.TextColor.Darken(0.25f) :
SkinManager.TextDisabledOrHintColor, // Disabled
secondaryTextRect.Location,
secondaryTextRect.Size,
secondaryTextAlignFlags);
Expand Down

0 comments on commit 01b6319

Please sign in to comment.