iced icon indicating copy to clipboard operation
iced copied to clipboard

Centering TextInput

Open imjasonmiller opened this issue 5 years ago • 2 comments

Hi!

I wondered whether it is possible to center (x- and y) the contents of a TextInput?

I've currently placed the TextInput inside of a Container with the align_x and align_y methods, but while this seems to work for Text, with .horizontal_alignment(HorizontalAlignment::Center), it fails for TextInput.

I'm trying to build the UI below:

image

This is where I'm currently at:

image

The content for each TextInput is aligned to the left. Can this be centered in some way? I tried applying .width(Length::Shrink), thinking it might size it according to the value/placeholder length, but the element seems to disappear in its entirety in that case.

Thank you for creating this library. It's easy to use for a Rust beginner so far.

imjasonmiller avatar May 18 '20 10:05 imjasonmiller

That looks great!

It's not currently possible to center the contents of a TextInput, but it's definitely something we should implement eventually.

I imagine an horizontal_alignment method would work well and be consistent with the Text widget. The implementation will be a bit tricky because the alignment will affect the logic of text measurements for mouse interaction and text selection.

I will try to give it a shot soon, but I believe this could be a good issue for anyone that wants to get familiar with the internals of the library!

hecrj avatar May 18 '20 23:05 hecrj

I want to work on it. Never worked properly on any open source before, so not sure how long will it take, but I would love to finish it.

Will give it a try this weekend.

If I have any doubts will post it here for better reference 👍

phoenisx avatar May 28 '20 02:05 phoenisx