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

Tab indents should align correctly #1791

Closed
andydotxyz opened this issue Jan 13, 2021 · 7 comments
Closed

Tab indents should align correctly #1791

andydotxyz opened this issue Jan 13, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@andydotxyz
Copy link
Member

In #761 we made a rough approximation.
In full implementation we need to align to the next tab-location so that " \tfoo" and "\tfoo" align.

@adrianre12
Copy link
Contributor

adrianre12 commented Jan 18, 2021

I have already worked on tabs and have a POC branch working. I have used the simplest way in which I have extended the image/font so that DrawString and MeasureString implement the tabs by moving the dot to the required offset before drawing the next rune.
An alternative would be to split each line into substrings separated by tabs. Each substring would then be drawn separately and added to the canvas at the relative offset.

@andydotxyz
Copy link
Member Author

I had not considered the former approach, I assumed we had to do it in the label because the tab could be programatic.
Do you have any feelings on which is faster and/or more flexible?

@adrianre12
Copy link
Contributor

Implementing it in DrawString is definitely the fastest, both in coding time and runtime and very easy to back out. I still have to look at how tabs should work with justification, left is easy, the rest ...? Assuming I have not made a huge mistake, I could see that it could be dropped in as a bug fix for 2.0.
The second method is starting to get into the "write a proper editor" realm. I have only just started looking at how the data structures in editors work, but I can see there could be a conflict between how tabs and editor work. e.g. indents and tabs similar but different or calculating cursor position from pointer position.

@andydotxyz
Copy link
Member Author

As I understand it tabs need to align to a position to be completed properly - i.e. "1 inch" or "8 spaces".
Somehow this needs to be passed into whatever is doing the rendering.
I don't think we can manage that without new API - meaning it would need to be a minor release not a bugfix.

@adrianre12
Copy link
Contributor

Yeup, correct at the moment to prove it works I have it hardcoded at 4 spaces. Which is the same as it is now. I started looking at adding it to the theme under text style but was waiting for approval of the concept before digging into the new theme code.
I am using the width of the space rune to calculate the tab width so that tab-width changes with the font. This is probably the most common understanding of tab i.e. N spaces.

@andydotxyz
Copy link
Member Author

That sounds like a good plan

@andydotxyz
Copy link
Member Author

This is now landed on develop branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants