Skip to content

Commit

Permalink
Dark Mode (#65)
Browse files Browse the repository at this point in the history
* Initial dark mode implementation

* Dark mode improvements for PracticeDialog and PracticeResultList

* Add setting for color mode

* Improve dark mode for settings and more forms

* Apply winforms color mode for Avalonia controls
  • Loading branch information
daniel-lerch authored Nov 29, 2024
1 parent 5e7c86b commit 8cfcecc
Show file tree
Hide file tree
Showing 18 changed files with 1,981 additions and 1,742 deletions.
400 changes: 198 additions & 202 deletions src/Vocup.WinForms/Forms/PracticeDialog.Designer.cs

Large diffs are not rendered by default.

46 changes: 34 additions & 12 deletions src/Vocup.WinForms/Forms/PracticeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace Vocup.Forms;
public partial class PracticeDialog : Form
{
private const int userEvaluationHeight = 38;
private readonly Color InputHighlightBackColor;
private readonly Color CorrectFeedbackBackColor;
private readonly Color PartlyCorrectFeedbackBackColor;
private readonly Color WrongFeedbackBackColor;

private readonly VocabularyBook book;
private readonly List<VocabularyWordPractice> practiceList;
Expand All @@ -34,6 +38,24 @@ public PracticeDialog(VocabularyBook book, List<VocabularyWordPractice> practice

Icon = Icon.FromHandle(Icons.LightningBolt.GetHicon());

InputHighlightBackColor = Color.FromArgb(255, 255, 150);
CorrectFeedbackBackColor = Color.FromArgb(144, 238, 144);
PartlyCorrectFeedbackBackColor = Color.FromArgb(255, 215, 0);
WrongFeedbackBackColor = Color.FromArgb(255, 192, 203);

#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
if (Application.ColorMode == SystemColorMode.Dark)
{
InputHighlightBackColor = Color.FromArgb(127, 127, 75);
CorrectFeedbackBackColor = Color.FromArgb(0, 100, 0);
PartlyCorrectFeedbackBackColor = Color.FromArgb(127, 106, 0);
WrongFeedbackBackColor = Color.FromArgb(127, 0, 0);
TbCorrectCount.BackColor = Color.DarkGreen;
TbPartlyCorrectCount.BackColor = Color.DarkGoldenrod;
TbWrongCount.BackColor = Color.DarkRed;
}
#pragma warning restore WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

evaluator = new Evaluator
{
OptionalExpressions = Program.Settings.EvaluateOptionalExpressions,
Expand Down Expand Up @@ -182,7 +204,7 @@ public void LoadNextWord()
TbMotherTongue.BackColor = DefaultBackColor;
TbForeignLang.Text = "";
TbForeignLang.ReadOnly = false;
TbForeignLang.BackColor = Color.FromArgb(250, 250, 150);
TbForeignLang.BackColor = InputHighlightBackColor;
TbForeignLangSynonym.Text = "";
if (string.IsNullOrWhiteSpace(currentWord.ForeignLangSynonym))
{
Expand All @@ -192,7 +214,7 @@ public void LoadNextWord()
else
{
TbForeignLangSynonym.ReadOnly = false;
TbForeignLangSynonym.BackColor = Color.FromArgb(250, 250, 150);
TbForeignLangSynonym.BackColor = InputHighlightBackColor;
}
TbForeignLang.Select();
}
Expand All @@ -208,7 +230,7 @@ public void LoadNextWord()
TbForeignLang.ReadOnly = true;
TbForeignLang.BackColor = DefaultBackColor;
TbForeignLangSynonym.ReadOnly = true;
TbMotherTongue.BackColor = Color.FromArgb(250, 250, 150);
TbMotherTongue.BackColor = InputHighlightBackColor;
TbMotherTongue.Select();
}

Expand All @@ -235,19 +257,19 @@ private PracticeResult EvaluateInput()
{
if (string.IsNullOrWhiteSpace(currentWord.ForeignLangSynonym))
{
inputs = new[] { TbForeignLang.Text.Trim() };
results = new[] { currentWord.ForeignLang };
inputs = [TbForeignLang.Text.Trim()];
results = [currentWord.ForeignLang];
}
else
{
inputs = new[] { TbForeignLang.Text.Trim(), TbForeignLangSynonym.Text.Trim() };
results = new[] { currentWord.ForeignLang, currentWord.ForeignLangSynonym };
inputs = [TbForeignLang.Text.Trim(), TbForeignLangSynonym.Text.Trim()];
results = [currentWord.ForeignLang, currentWord.ForeignLangSynonym];
}
}
else // PracticeMode.AskForMotherTongue
{
inputs = new[] { TbMotherTongue.Text.Trim() };
results = new[] { currentWord.MotherTongue };
inputs = [TbMotherTongue.Text.Trim()];
results = [currentWord.MotherTongue];
}

return evaluator.GetResult(results, inputs);
Expand Down Expand Up @@ -278,7 +300,7 @@ private void EvaluateWord()
if (!Program.Settings.UserEvaluates)
{
TbCorrectAnswer.Text = Words.Correct + "!";
TbCorrectAnswer.BackColor = Color.FromArgb(144, 238, 144);
TbCorrectAnswer.BackColor = CorrectFeedbackBackColor;
sound = Sounds.sound_correct;
}
}
Expand All @@ -290,7 +312,7 @@ private void EvaluateWord()
if (!Program.Settings.UserEvaluates)
{
TbCorrectAnswer.Text = $"{Words.PartlyCorrect}! ({GetEvaluationAnswer()})";
TbCorrectAnswer.BackColor = Color.FromArgb(255, 215, 0);
TbCorrectAnswer.BackColor = PartlyCorrectFeedbackBackColor;
sound = Sounds.sound_correct;
}
}
Expand All @@ -302,7 +324,7 @@ private void EvaluateWord()
if (!Program.Settings.UserEvaluates)
{
TbCorrectAnswer.Text = $"{Words.Wrong}! ({GetEvaluationAnswer()})";
TbCorrectAnswer.BackColor = Color.FromArgb(255, 192, 203);
TbCorrectAnswer.BackColor = WrongFeedbackBackColor;
sound = Sounds.sound_wrong;
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/Vocup.WinForms/Forms/PracticeDialog.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down
24 changes: 21 additions & 3 deletions src/Vocup.WinForms/Forms/PracticeResultList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace Vocup.Forms;

public partial class PracticeResultList : Form
{
private readonly Color CorrectFeedbackBackColor;
private readonly Color PartlyCorrectFeedbackBackColor;
private readonly Color WrongFeedbackBackColor;

private VocabularyBook book;
private List<VocabularyWordPractice> practiceList;

Expand All @@ -23,6 +27,20 @@ public PracticeResultList(VocabularyBook book, List<VocabularyWordPractice> prac
InitializeComponent();
Icon = Icon.FromHandle(Icons.BarChart.GetHicon());

CorrectFeedbackBackColor = Color.FromArgb(144, 238, 144);
PartlyCorrectFeedbackBackColor = Color.FromArgb(255, 215, 0);
WrongFeedbackBackColor = Color.FromArgb(255, 192, 203);

#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
if (Application.ColorMode == SystemColorMode.Dark)
{
CorrectFeedbackBackColor = Color.FromArgb(0, 100, 0);
PartlyCorrectFeedbackBackColor = Color.FromArgb(127, 106, 0);
WrongFeedbackBackColor = Color.FromArgb(127, 0, 0);
}
#pragma warning restore WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.


this.book = book;
this.practiceList = practiceList;
}
Expand Down Expand Up @@ -121,9 +139,9 @@ private void CalculateGrade()
TbPercentage.BackColor = correctRatio switch
{
// Steps taken from https://de.wikipedia.org/wiki/Vorlage:Punktesystem_der_gymnasialen_Oberstufe
>= 0.70 => Color.FromArgb(144, 238, 144), // at least 70% -> green background
>= 0.45 => Color.FromArgb(255, 215, 0), // at least 45% -> yellow background
_ => Color.FromArgb(255, 192, 203) // less than 45% -> red background
>= 0.70 => CorrectFeedbackBackColor, // at least 70% -> green background
>= 0.45 => PartlyCorrectFeedbackBackColor, // at least 45% -> yellow background
_ => WrongFeedbackBackColor // less than 45% -> red background
};

TbPercentage.Text = Math.Round(correctRatio * 100) + "%";
Expand Down
Loading

0 comments on commit 8cfcecc

Please sign in to comment.