`text_input` caret is invisible when using `Shrink` or `Shrink.min(n)`
Is your issue REALLY a bug?
- My issue is indeed a bug!
- I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.
Is there an existing issue for this?
- I have searched the existing issues.
Is this issue related to iced?
- My hardware is compatible and my graphics drivers are up-to-date.
What happened?
When using Length::Shrink with the text_input, the drawing of the caret seems a bit "weird". To be honest I'm not 100% sure to understand why this happen but to give some examples of what happen with this width, if you use a width of Shrink, the caret will not be visible at all, even after typing some text. The caret start showing up if I set Shrink.min(20), however it disappear when the input get a certain length, in my app it was after typing a "A" or "aa", a single "a" would still show the caret. This disappearance threshold will probably be different depending of the font/size I assume.
What is the expected behavior?
I think the caret should show on Shrink when the text_input is being focused.
I could make the caret show by doing the following
diff --git a/core/src/text/input.rs b/core/src/text/input.rs
index 04cd2f37d..a6a3d7c8a 100644
--- a/core/src/text/input.rs
+++ b/core/src/text/input.rs
@@ -7,7 +7,7 @@ use crate::text::editor;
use crate::text::paragraph;
use crate::text::{self, Alignment, Editor, LineHeight, Position, Text, Wrapping};
use crate::widget::operation::{Focusable, TextInput};
-use crate::{Color, Event, InputMethod, Length, Padding, Pixels, Point, Rectangle, Shell};
+use crate::{Color, Event, InputMethod, Length, Padding, Pixels, Point, Rectangle, Shell, Size};
use unicode_segmentation::UnicodeSegmentation;
@@ -119,7 +119,12 @@ impl<R: text::Renderer> Input<R> {
| Length::Bounded { .. }
| Length::Fluid(_) => limits.max(),
Length::Shrink | Length::Fit => {
- limits.resolve(layout.width, layout.height, editor.min_bounds())
+ let min_bounds = editor.min_bounds();
+ limits.resolve(
+ layout.width,
+ layout.height,
+ Size::new(min_bounds.width + 1.0, min_bounds.height),
+ )
}
};But it doesn't work well because paired with a placeholder, the Shrink ignore the placeholder size so it will show some part of the first letter since the width would be 1 pixel. So probably this diff isn't good at all, I'm not even sure that using the placeholder size as limit would be a solution as it would then shrink as soon as a character is typed, right?
Version
master
Operating System
Linux
Do you have any log output?
Source: iced-rs/iced