Skip to content

PlotStyle: styling information that simplifies storing, recalling, and copying plot styles#4025

Merged
swharden merged 12 commits intoScottPlot:mainfrom
StendProg:DarkMode
Jul 3, 2024
Merged

PlotStyle: styling information that simplifies storing, recalling, and copying plot styles#4025
swharden merged 12 commits intoScottPlot:mainfrom
StendProg:DarkMode

Conversation

@StendProg
Copy link
Contributor

@StendProg StendProg commented Jul 1, 2024

This PR adds the Plot.Style.IsDarkMode property.
This property allows you to toggle the display mode light/dark. If the user has changed any colors manually, these colors are not affected by the switch and remain as configured by the user.
Calling the Plot.Style.GrabLightSettings() method allows you to save the changes made by the user as light theme settings.

IsDarkMode is not a good name for the set value property. The more appropriate DarkMode is already taken up by the DarkMode() method. Renaming it would be a breaking change.

    private void DarkModeCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        formsPlot1.Plot.Style.IsDarkMode = DarkModeCheckBox.Checked;
        formsPlot1.Refresh();
    }
DarkMode.mp4

@swharden
Copy link
Member

swharden commented Jul 1, 2024

Hi @StendProg, thanks so much for this PR! The timing is great as I was about to start working on #3955

I may refactor this a bit before merging it in, but I'll have it merged before the next release for sure.

I look forward to reviewing this! 🚀

@heartacker
Copy link
Contributor

great~

@swharden swharden linked an issue Jul 2, 2024 that may be closed by this pull request
@swharden swharden changed the title Improve DarkMode support PlotStyle: styling information that simplifies storing, recalling, and copying plot styles Jul 2, 2024
@swharden
Copy link
Member

swharden commented Jul 3, 2024

I think I've recreated the original behavior... customized style settings can be recognized and preserved even as new styles are applied. I'll probably put this down for tonight and pick it up again tomorrow, but I'm encouraged by the direction that this is going 😄

image

image

public Form1()
{
    InitializeComponent();

    var sig1 = formsPlot1.Plot.Add.Signal(Generate.Sin());
    sig1.LegendText = "Sin";
    var sig2 = formsPlot1.Plot.Add.Signal(Generate.Cos());
    sig2.LegendText = "Cos";

    // apply custom styling options
    formsPlot1.Plot.Legend.BackgroundColor = Colors.Magenta;
    formsPlot1.Plot.Legend.FontColor = Colors.White;

    // prepare the two styles we will be switching between later
    PlotStyle lightStyle = new ScottPlot.PlotStyles.Light();

    // the WinForms control customizes light style by setting background to match the form
    lightStyle.FigureBackground = ScottPlot.Color.FromColor(SystemColors.Control);

    PlotStyle darkStyle = new ScottPlot.PlotStyles.Dark();
    PlotStyle customStyle = formsPlot1.Plot.GetStyle().WhereDifferentFrom(lightStyle);

    checkBox1.CheckedChanged += (s, e) =>
    {
        // apply light or dark mode
        if (checkBox1.Checked)
            formsPlot1.Plot.SetStyle(darkStyle);
        else
            formsPlot1.Plot.SetStyle(lightStyle);

        // apply the customized style options
        formsPlot1.Plot.SetStyle(customStyle);

        formsPlot1.Refresh();
    };
}

@swharden swharden merged commit 723f187 into ScottPlot:main Jul 3, 2024
@kebox7
Copy link
Contributor

kebox7 commented Jul 3, 2024

Hi @swharden. This PR is already closed, but I have some comments/suggestions.

public Color? FigureBackground { get; set; } = null;
public Color? DataBackGround { get; set; } = null;

For consistency, change DataBackGround to DataBackground.

public Color? LegendBackground { get; set; } = null;
public Color? LegendFont { get; set; } = null;

LegendFont is more associated with the font name, but not the color. It might be better to change it to LegendForeground or LegendText.

@swharden
Copy link
Member

swharden commented Jul 3, 2024

Good point @kebox7, thanks for pointing that out! I meant to rename all those properties but I forgot to before merging... I opened #4036 to track the fix and added my recommended names there. If you get to it before I do and create a pull request, I'd be happy to merge it in! Otherwise I'll pick it up next time I work on this project 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Style: Add ways to create custom styles and reset to default style

4 participants