Closed dhardy closed 4 years ago
I would have thought this the job of the LineBreaker
. If you want all characters to remain on one line always, then never return any soft or hard breaks.
#[derive(Clone, Copy, Debug, Hash)]
struct NeverLineBreaker;
impl LineBreaker for NeverLineBreaker {
fn line_breaks<'a>(&self, text: &'a str) -> Box<dyn Iterator<Item = LineBreak> + 'a> {
Box::new(std::iter::empty())
}
}
let custom_layout = Layout::default().line_breaker(NeverLineBreaker);
If you say so. Then it might make sense to add NeverLineBreaker
and to de-unionise the BuiltInLineBreaker
, or even to move the wrap-mode into a method on the LineBreaker
trait.
Do you still want the first commit here?
We could add that impl to the BuiltInLineBreaker
enum if it's useful.
Do you still want the first commit here?
Yes please.
The design seems over-complicated to me. Anyway, take that first commit...
Yeah fair enough. I guess there are times when you want a single line with no overlapping out-of-bounds. Really the line breaker has one job. The single-line/wrap is just about the special case of wanting a single line, you may still want to break normally, or on every char, or perhaps not at all.
The API is quite generic meaning you can change stuff outside the crate, but it also makes it more complicated. Ultimately I don't understand many use cases that well, so the ability to change bits was meant to help there.
If you'd like to improve the API raise an issue with how you'd like it to work. I'm sure there are many ways we can improve it.
Hmm, I don't have any specific recommendations now, though I've been playing with the code in kas-text. A couple of things do strike me though:
Character
is in fact a Unicode Scalar Value ("almost" a codepoint). I presume font-kerning is responsible for handling multi-codepoint "letters".Word
is... any sequence of scalar values which doesn't contain (though may be trailed by) a potential line-break. It may in fact contain no glyphs.\r\n
line-ending sequence does not need two glyphs.Anyway, these are just my thoughts; I'm probably going to bypass glyph-brush-layout
for kas-text
.
Currently, when word-wrapping is disabled, glyph-brush-layout will omit any word after the first which can only partially appear on the line (as is usually the case with line-wrapping). This PR changes that to include the next full word. It could maybe be better (omit letters which are fully outside the bounds, perhaps a nicer way of drawing cut-off text).
Rationale: when writing text into a single-line edit box, normally one does not expect a word to be hidden because it doesn't fully fit on the line. This doesn't fix everything (e.g. horizontal scrolling within the edit box), but is an improvement. (One can test with KAS 0.4 using the
gallery
example.)Two tests fail; I wasn't sure how best to fix these: