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

Customizing/Inheriting SKDefaultTooltip - Paint.PaintStyle - Internal only, Show/Hide non-virtual #1770

Open
Domik234 opened this issue Jan 15, 2025 · 0 comments

Comments

@Domik234
Copy link

Is your feature request related to a problem? Please describe.
Please take this only as an idea for simplifying work with the library.

Default tooltip will be for most users almost the same. Let's make it buildable for everyone (or better) if it needs to be customized.

Describe the solution you'd like
Part 1 - Internal access modifier on BackgroundPaint blocks to build copied SKDefaultTooltip
Trying to make custom tooltip based on SKDefaultTooltip leads to a block or usage of obsolete method (without inspecting the source code). DefaultTooltip should be propably like a template for custom ones.

LiveChartsCore.Painting.Paint internal PaintStyle PaintStyle { get; set; } is internal (cannot be made the same way as default one) - possible to set [Obsolete] <paint>.IsStroke = false;
LiveChartsCore.Painting.PaintStyle - is public (no problem here)
LiveChartsCore.SkiaSharpView.SKCharts.SKDefaultTooltip

Because of _container.Geometry.Fill = BackgroundPaint; that applies the color and changes PaintStyle to Fill - BackgroundPaint's PaintStyle can be removed and access modifier won't be problem anymore.

if (_fill is not null) _fill.PaintStyle = PaintStyle.Fill;

Part 2 - Show/Hide virtual
My reason for customization was to add Hide interval to leave tooltip visible for specific time (and extend it's time if touch is made again before timeout).
If method "Show" and method "Hide" for SKDefaultTooltip were virtual - inheriting could be possible instead of remaking whole file.

Then it could be like (just example - not the most performant but it will explain the situation):

CancellationTokenSource cts;

public void Show(IEnumerable<ChartPoint> foundPoints, Chart chart)
{
    cts?.Cancel();
    base.Show();
}

public async void Hide(Chart chart)
{
    cts?.Cancel();
    cts = new();

    try
    {
        if (HideDelay.HasValue)
            await Task.Delay(HideDelay.Value, cts.Token);
    }
    catch (TaskCanceledException) { return; }
    base.Hide();
}

Summary
https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp/SKCharts/SKDefaultTooltip.cs#L73
Before:

set
{
    _backgroundPaint = value;
    if (value is not null)
        value.PaintStyle = PaintStyle.Fill;
}

After:

set => _backgroundPaint = value;

Additionally:

public void Show(IEnumerable<ChartPoint> foundPoints, Chart chart)

Before:
public void Show(IEnumerable<ChartPoint> foundPoints, Chart chart)

After:
public virtual void Show(IEnumerable<ChartPoint> foundPoints, Chart chart)


Before:
public void Hide(Chart chart)

After:
public virtual void Hide(Chart chart)


Thanks for all your work!

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

No branches or pull requests

1 participant