pub struct StringBar { /* private fields */ }Expand description
Make plain text bars with Unicode block elements.
§Monospaced vs. proportional fonts
It is easier to make string bars with proportional fonts, which often looks better too. But these string bars look bad with monospaced fonts. On the other side, monospaced bars look okay with proportional fonts.
Windows 11 File Explorer uses a proportional font by default. However, Windows 10 uses a monospaced one; and even on Windows 11 the user may use tools like MacType to customize the font.
So we use monospaced mode by default, but if you know the app will use a proportional font, you should use proportional mode; or provide an option to the user.
Is is also found later that proportional bar’s width is unstable across screens with different DPI.
Related issues:
§Alignment
Unfortunately, Unicode only provides full block elements for lower and left variants. For right variants, there are only 4/8 and 1/8 blocks, and some fonts don’t even support them, like Microsoft YaHei.
So we only provide left alignment to simplify the implementation.
Implementations§
Source§impl StringBar
impl StringBar
Sourcepub fn builder() -> StringBarBuilder
pub fn builder() -> StringBarBuilder
Create an instance of StringBar using the builder syntax
Source§impl StringBar
impl StringBar
pub fn to_utf16_string(&self) -> Utf16String
Sourcepub fn proportional_font_to_utf16_string(&self) -> Utf16String
pub fn proportional_font_to_utf16_string(&self) -> Utf16String
For proportional fonts, making bar is easy.
Unfortunately, we also can’t overlap bar with label string easily.
See StringBar for details.
Sourcepub fn monospaced_font_to_utf16_string(&self) -> Utf16String
pub fn monospaced_font_to_utf16_string(&self) -> Utf16String
See StringBar for details.