Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CharacterCasing property in MaterialTabSelector and SubtleEmphasis in FontType #281

Merged
merged 6 commits into from
Nov 8, 2021
41 changes: 38 additions & 3 deletions MaterialSkin/Controls/MaterialTabSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.Globalization;
using System.Windows.Forms;

public class MaterialTabSelector : Control, IMaterialControl
Expand All @@ -19,6 +20,21 @@ public class MaterialTabSelector : Control, IMaterialControl
[Browsable(false)]
public MouseState MouseState { get; set; }

//[Browsable(false)]
public enum CustomCharacterCasing
{
[Description("Text will be used as user inserted, no alteration")]
Normal,
[Description("Text will be converted to UPPER case")]
Upper,
[Description("Text will be converted to lower case")]
Lower,
[Description("Text will be converted to Proper case (aka Title case)")]
Proper
}

TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

private MaterialTabControl _baseTabControl;

[Category("Material Skin"), Browsable(true)]
Expand Down Expand Up @@ -62,13 +78,28 @@ public MaterialTabControl BaseTabControl
private List<Rectangle> _tabRects;

private const int ICON_SIZE = 24;
private const int FIRST_TAB_PADDING = 80;
private const int FIRST_TAB_PADDING = 50;
private const int TAB_HEADER_PADDING = 24;
private const int TAB_WIDTH_MIN = 160;
private const int TAB_WIDTH_MAX = 264;

private int _tab_over_index = -1;

private string TextCased;

private CustomCharacterCasing _characterCasing;

[Category("Appearance")]
public CustomCharacterCasing CharacterCasing
{
get => _characterCasing;
set
{
_characterCasing = value;
_baseTabControl.Invalidate();
Invalidate();
}
}
private int _tab_indicator_height;

[Category("Material Skin"), Browsable(true), DisplayName("Tab Indicator Height"), DefaultValue(2)]
Expand Down Expand Up @@ -188,7 +219,9 @@ protected override void OnPaint(PaintEventArgs e)
if (((TAB_HEADER_PADDING*2) + textSize.Width < TAB_WIDTH_MAX))
{
NativeText.DrawTransparentText(
tabPage.Text.ToUpper(),
CharacterCasing == CustomCharacterCasing.Upper ? tabPage.Text.ToUpper() :
CharacterCasing == CustomCharacterCasing.Lower ? tabPage.Text.ToLower() :
CharacterCasing == CustomCharacterCasing.Proper ? textInfo.ToTitleCase(tabPage.Text.ToLower()) : tabPage.Text,
Font,
Color.FromArgb(CalculateTextAlpha(currentTabIndex, animationProgress), SkinManager.ColorScheme.TextColor),
textLocation.Location,
Expand All @@ -203,7 +236,9 @@ protected override void OnPaint(PaintEventArgs e)
textLocation.Height = 26;
}
NativeText.DrawMultilineTransparentText(
tabPage.Text.ToUpper(),
CharacterCasing == CustomCharacterCasing.Upper ? tabPage.Text.ToUpper() :
CharacterCasing == CustomCharacterCasing.Lower ? tabPage.Text.ToLower() :
CharacterCasing == CustomCharacterCasing.Proper ? textInfo.ToTitleCase(tabPage.Text.ToLower()) : tabPage.Text,
SkinManager.getFontByType(MaterialSkinManager.fontType.Body2),
Color.FromArgb(CalculateTextAlpha(currentTabIndex, animationProgress), SkinManager.ColorScheme.TextColor),
textLocation.Location,
Expand Down
8 changes: 7 additions & 1 deletion MaterialSkin/MaterialSkinManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private MaterialSkinManager()
logicalFonts.Add("H6", createLogicalFont("Roboto Medium", 20, NativeTextRenderer.logFontWeight.FW_MEDIUM));
logicalFonts.Add("Subtitle1", createLogicalFont("Roboto", 16, NativeTextRenderer.logFontWeight.FW_REGULAR));
logicalFonts.Add("Subtitle2", createLogicalFont("Roboto Medium", 14, NativeTextRenderer.logFontWeight.FW_MEDIUM));
logicalFonts.Add("SubtleEmphasis", createLogicalFont("Roboto", 12, NativeTextRenderer.logFontWeight.FW_NORMAL, 1));
logicalFonts.Add("Body1", createLogicalFont("Roboto", 16, NativeTextRenderer.logFontWeight.FW_REGULAR));
logicalFonts.Add("Body2", createLogicalFont("Roboto", 14, NativeTextRenderer.logFontWeight.FW_REGULAR));
logicalFonts.Add("Button", createLogicalFont("Roboto Medium", 14, NativeTextRenderer.logFontWeight.FW_MEDIUM));
Expand Down Expand Up @@ -283,6 +284,7 @@ public enum fontType
H6,
Subtitle1,
Subtitle2,
SubtleEmphasis,
Body1,
Body2,
Button,
Expand Down Expand Up @@ -317,6 +319,9 @@ public Font getFontByType(fontType type)

case fontType.Subtitle2:
return new Font(RobotoFontFamilies["Roboto_Medium"], 14f, FontStyle.Bold, GraphicsUnit.Pixel);

case fontType.SubtleEmphasis:
return new Font(RobotoFontFamilies["Roboto"], 12f, FontStyle.Italic, GraphicsUnit.Pixel);

case fontType.Body1:
return new Font(RobotoFontFamilies["Roboto"], 14f, FontStyle.Regular, GraphicsUnit.Pixel);
Expand Down Expand Up @@ -379,13 +384,14 @@ private void addFont(byte[] fontdata)
privateFontCollection.AddMemoryFont(ptrFont, dataLength);
}

private IntPtr createLogicalFont(string fontName, int size, NativeTextRenderer.logFontWeight weight)
private IntPtr createLogicalFont(string fontName, int size, NativeTextRenderer.logFontWeight weight, byte lfItalic = 0)
{
// Logical font:
NativeTextRenderer.LogFont lfont = new NativeTextRenderer.LogFont();
lfont.lfFaceName = fontName;
lfont.lfHeight = -size;
lfont.lfWeight = (int)weight;
lfont.lfItalic = lfItalic;
return NativeTextRenderer.CreateFontIndirect(lfont);
}

Expand Down
Loading