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 support for DrawText maxSize parameter to all platforms #1559

Open
Jonarw opened this issue May 11, 2020 · 7 comments
Open

Add support for DrawText maxSize parameter to all platforms #1559

Jonarw opened this issue May 11, 2020 · 7 comments

Comments

@Jonarw
Copy link
Member

Jonarw commented May 11, 2020

As became apparent in #1558, not all IRenderContext implementations support the maxSize parameter of DrawText(...).

I think we could address this by:

  • Remove the maxSize parameter from IRenderContext.DrawText()
  • Add a RenderingExtensions.DrawText() extension method with the maxSize parameter
  • Implement this functionality using a combination of text measurement and regular clipping

That way I think it should be possible to get this to work on all platforms that natively support clipping.

I might have a look at this later.

@VisualMelon
Copy link
Contributor

I have also been thinking about this with respect to #1556, where a common method to perform text arranging could handle computing/intersecting clipping rects also (currently it throws if given a non-null maxSize).

The WPF behaviour seems to be to equivalent to clamping the bounds of the whole block of text before arranging it, and then effectively rendering the text in the top-left corner. I'll try messing around with this later on today.

@VisualMelon
Copy link
Contributor

Irritating, I think the clipping has to be done on the text itself, because clipping rects are non-rotational.

VisualMelon added a commit to VisualMelon/oxyplot that referenced this issue May 11, 2020
@VisualMelon
Copy link
Contributor

VisualMelon commented May 11, 2020

I've thrown together maxSize support in 1df261a (see #1556, where it is implemented for SkiaSharp) using a binary search to reduce the string. It's not properly tested, but I thought I'd push this now as a POC now because I might be busy tomorrow.

@Jonarw
Copy link
Member Author

Jonarw commented May 12, 2020

The more I think about this the more I realize that this is a feature that brings a lot of complications when we want to support it properly. Especially when it is combined with multi-line text and rotation. I am wondering if this is really worth the trouble?

After all, I think pretty much the only place where this is actually used is to clip axis titles and (since recently) plot titles. Is there an easier way we could achieve this?

Just a thought: Could we remove the maxSize functionality alltogether and change the few instances where it is actually used such that they just set an appropriate clipping rectangle?

@VisualMelon
Copy link
Contributor

VisualMelon commented May 12, 2020

I guess it depends on what we want. From my perspective, the current WPF behaviour is undesirable, because clipping by pixel produces partial glyphs that could be misleading, and can otherwise fail to convey that anything has been trimmed. I'd prefer something equivalent to WPF's CharacterEllipsis. This is what people are used to from e.g. Windows Explorer. This would be easy to add to #1556 for example, and it would be easy to switch WPF and GDI+ to use these methods as they are built in.

You mentioned not encountering it in usage, and I'll second that experience: if anything were ever clipping then I would make the plot bigger to accommodate, but I usually have the freedom to make them any size I want where others might not. Maybe we should try to solicit input from people who do rely on it (e.g. @UndisputedBasement33). I'm certainly happy to go to the trouble of implementing all of this if we can put it all in one place.

@UndisputedBasement33
Copy link
Contributor

UndisputedBasement33 commented May 13, 2020

I would also prefer the CharacterEllipsis rather than just clipping by pixel.

In my (windows wpf)-App I have a Tab with in total 6 PlotViews. Each plot has a title, that fits nicely, if the app is started. But since the user has the possibility to change the window size the plots scale accordingly. I want to have this behavior because even the smaller plots deliver the information that is necessary. But at some point the size is that small that the title doesn't fit anymore, and then the titles of the plots next to each other start to overlay:

(the pictures are from the released Oxyplot version, without clipping functionality)

Standard:
fitting

Scaled:
not fitting

As you can see the title overlays even space that is not assigned for the plotview (means it goes out of the border of the groupbox and overlays even the border of the whole app)

@VisualMelon
Copy link
Contributor

@UndisputedBasement33 thanks for commenting: I'll be sure to add CharacterEllipsis to my work in #1556 in my next round of changes so we can evaluate it.

VisualMelon added a commit to VisualMelon/oxyplot that referenced this issue May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants