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

fix baseline offset for sized widget #2110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

maurerdietmar
Copy link
Contributor

@maurerdietmar maurerdietmar commented Jan 6, 2022

Baseline offset is relative to the bottom of a widget. Current code
assumes that the widget has exactly the required height. For sized
widgets, where there is more vertical space, the baseline is totally
wrong. This patch series considers the additional space to adjust the
baseline offset.

Signed-off-by: Dietmar Maurer [email protected]

Baseline offset is relative to the bottom of a widget. Current code
assume that the widget has exactly the required height. For sized
widgets, where there is more vertical space, the baseline is totally
wrong. This patch series considers the additional space to adjust the
baseline offset.

Signed-off-by: Dietmar Maurer <[email protected]>
@maurerdietmar
Copy link
Contributor Author

There are more widgets that needs to be fixed, i.e. TextBox. Attached an example to show the problem:

align.rs.txt

@maurerdietmar
Copy link
Contributor Author

Oh, I already added the TextBox fix. Just want to notice that I do
not understand the original code:

 let baseline_off = layout_baseline
-            - (self.inner.child_size().height - self.inner.viewport_rect().height())
-            + textbox_insets.y1;

Why does the baseline depend on the viewport_rect?

We use RawLabel:baseline_offset in Checkbox::layout, so this fixes
wrong baseline with checkboxes.

Signed-off-by: Dietmar Maurer <[email protected]>
@jneem
Copy link
Collaborator

jneem commented Jan 10, 2022

Good question, I'm not sure (@cmyr?).

I mean, if the Scroll is scrolled, then the text baseline will appear to move. But I'm not sure we want to actually use that scrolled baseline for aligning anything -- it would cause weird layout changes as you scroll.

@cmyr cmyr self-requested a review January 12, 2022 23:20
@cmyr
Copy link
Member

cmyr commented Jan 12, 2022

this was a long time ago, but I believe this is just trying to figure out where in the overall widget the text is.

let baseline_off = layout_baseline
- (self.inner.child_size().height - self.inner.viewport_rect().height())

The layout_baseline that we have is relative to the top of the inner TextComponent. Druid tracks baselines relative to the bottom of the layout rect; to make this conversion we need to know where exactly the top of the TextComponent is, relative to our own layout rect. So:

  • we have a point relative to the top of a TextComponent that is in a Padding in a Scroll (Scroll<Padding<TextComponent>>)
  • self.inner.child_size().height is the total height of the Padding widget, inside the scroll. This can be larger than the scroll.
  • self.inner.viewport_rect().height() is the height of the visible region; it does not account for the scroll position
  • so then (self.inner.child_size().height - self.inner.viewport_rect().height()) is the total height of the content of the textbox, - the height of the visible region.

so what I think this is trying to do is to account for any possible scroll that is currently not visible, in order to adjust the baseline up to the bottom of the visible region. I am not sure it is right. Staring at it right now, I would expect it to be self.inner.viewport_rect().max_y(), instead of height()? But also I was quite careful with a lot of this code, and especially things like this I would have often tested manually.

This is easy enough, though: if you have a textbox that can scroll vertically, and it is baseline aligned, do weird things happen to the layout when you scroll that textbox?

@maurerdietmar
Copy link
Contributor Author

so what I think this is trying to do is to account for any possible scroll that is currently not visible, in order to adjust the baseline up to the bottom of the visible region. I am not sure it is right. Staring at it right now, I would expect it to be self.inner.viewport_rect().max_y(), instead of height()? But also I was quite careful with a lot of this code, and especially things like this I would have often tested manually.

I simply don't get why you want to account for any possible scroll that is currently not visible. Make no sense to me.
The baseline should not depend on the scroll position at all.

This is easy enough, though: if you have a textbox that can scroll vertically, and it is baseline aligned, do weird things happen to the layout when you scroll that textbox?

Yes. I have postend an example above where you can see the effects.

@jneem
Copy link
Collaborator

jneem commented Jan 13, 2022

Ah, I was reading it wrong, sorry. The baseline calculation doesn't depend on the scroll offset, just the height of the viewport. The effect of the current code is to put the baseline of the text box at the baseline of the first line of text, when the viewport is scrolled all the way to the top. I don't know if that's the desired behavior, but it's what it does.

2022-01-13.16-25-27.mp4

@maurerdietmar
Copy link
Contributor Author

I don't know if that's the desired behavior, but it's what it does.

IMHO that behavior is really strange (Please compare with my patch applied)

@xStrom xStrom added the S-needs-review waits for review label Jan 12, 2023
@xStrom xStrom added the text label Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-review waits for review text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants