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

Support setting tabs width #174

Open
benoitkugler opened this issue Nov 18, 2024 · 7 comments
Open

Support setting tabs width #174

benoitkugler opened this issue Nov 18, 2024 · 7 comments

Comments

@benoitkugler
Copy link
Contributor

I would like to support setting the width of tabs in a run, following the CSS 'tab-size' property.

That could be exposed with the method

// SetTabsWidth alters the run, replacing the width of every tab character (U+0009).
//
// [text] is the input slice used to create the run.
func (*Output) SetTabsWidth(text []rune, spacing fixed.Int26_6)

(At a first glance, the implementation would be somewhat similar to Output.AddWordSpacing)

What do you think ?

@andydotxyz
Copy link
Contributor

A great idea, however I don't think it is quite that straight forward - I think you also need to have a starting position, because tab alignment is actually relative to the page and not to the first character of a run...

@benoitkugler
Copy link
Contributor Author

Well, I think what I've in mind is indeed a lot simpler than tabs alignement. I think what you describe is something about "dynamic" adjustment, depending on the position of the run with respect to the page start ?

@andydotxyz
Copy link
Contributor

What you outline I think only works when the tabs are right at the beginning of a line. But for example "\t\tpoint a:\t detail here" won't work as expected.

A while back I hoped to contribute the algorithm we use in Fyne for this work but licensing doesn't allow.

@hajimehoshi
Copy link
Contributor

Tabs work in much more complicated way in e.g. MS Word's tab stops. Are tabs really this library's scope?

@benoitkugler
Copy link
Contributor Author

What you outline I think only works when the tabs are right at the beginning of a line. But for example "\t\tpoint a:\t detail here" won't work as expected.

A while back I hoped to contribute the algorithm we use in Fyne for this work but licensing doesn't allow.

Aah ! Indeed, you are right. Browser rendering for the string
\t\tpoint a:\tdetail here
with tab-size: 10 (meaning a tab is 10 spaces) :
image
The expected result is to align the content after a tab to a "tab grid" (displayed in red in the example).

Tabs work in much more complicated way in e.g. MS Word's tab stops. Are tabs really this library's scope?

Well, since it seems not trivial, I could be great to provide it for all go-text consumers right ? (If we find an API that suits everybody.)

@hajimehoshi
Copy link
Contributor

I'm not sure it is really possible to provide a generic model for various use cases including MS Word, but I keep my fingers crossed :)

@andydotxyz
Copy link
Contributor

They way we do it in Fyne is to pass in the "current offset" into the tabletop function so that they incremented by "offset mod tabwidth" and after that it's just the basic math.

OK not quite that simple - you might need 2 offsets: the current offset and the offset used on subsequent lines.

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

3 participants