All Projects → embedded-graphics → embedded-text

embedded-graphics / embedded-text

Licence: MIT license
Multiline TextBox for the embedded-graphics Rust crate

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to embedded-text

CountDownTextView
A count down widget for verify code
Stars: ✭ 22 (-37.14%)
Mutual labels:  textview
android-material-design-in-practice
A project to demonstrate the latest material design principles with simple examples. It has additional examples on how to easily scale texts on different screen sizes without extra effort.
Stars: ✭ 67 (+91.43%)
Mutual labels:  textview
TextViewPlus
an android library for setting custom font in xml layout
Stars: ✭ 27 (-22.86%)
Mutual labels:  textview
SuperShapeView
A smart custom view support shapes for ImageView, TextView ,EditView ,instead of shape.xml.(自定义形状控件,支持TextView,EditText)
Stars: ✭ 60 (+71.43%)
Mutual labels:  textview
ProgressText
A text progress bar with animation effect, highly customized.
Stars: ✭ 13 (-62.86%)
Mutual labels:  textview
TextViewSetWordSpace
Android设置TextView字间距
Stars: ✭ 18 (-48.57%)
Mutual labels:  textview
ShapeView
打造万能shape,再也不用写很多xml了,可以当做TextView,Button,EditText等多种控件,方便实用
Stars: ✭ 34 (-2.86%)
Mutual labels:  textview
CheckableTextView
A simple and flexible Checked TextView or Checkable TextView
Stars: ✭ 108 (+208.57%)
Mutual labels:  textview
ToolTipPopupWordTV
ToolTipopupWordTV is an Open Source Android library that allows developers to easily open a popup with details by select a word from a textview.
Stars: ✭ 41 (+17.14%)
Mutual labels:  textview
LicenseTextView
Custom Lincese TextView for android
Stars: ✭ 31 (-11.43%)
Mutual labels:  textview
simulator
Desktop simulator for embedded-graphics
Stars: ✭ 52 (+48.57%)
Mutual labels:  embedded-graphics
MaterialTextField
Android EditText designed to match Material.IO Design Guidelines of 2019. RTL supported.
Stars: ✭ 41 (+17.14%)
Mutual labels:  textview
Hyena
鬣狗快速开发库(2018年6月停止维护)
Stars: ✭ 21 (-40%)
Mutual labels:  textview
EasyTextView
🌈 🍀支持Java和Xml设置Shape、IconFont、IconFont+String、Span等具有丰富Api的TextView
Stars: ✭ 71 (+102.86%)
Mutual labels:  textview
Socially
Socially is a textView which is able to create separate clickable views according to your requirements.
Stars: ✭ 28 (-20%)
Mutual labels:  textview
TypedTextView
Custom implementation of Android's TextView simulating a keyboard/type-writer.
Stars: ✭ 57 (+62.86%)
Mutual labels:  textview
FreeText
Android 字体 文字 特效 动画效果
Stars: ✭ 140 (+300%)
Mutual labels:  textview
Android-SGTextView
同时带字体描边 渐变 阴影的TextView - both have stroker, gradient and shadow TextView
Stars: ✭ 18 (-48.57%)
Mutual labels:  textview
STTextView
📝 STTextView is a light-weight library that adds a placeholder to the UITextView.
Stars: ✭ 36 (+2.86%)
Mutual labels:  textview
hat-view
Allow to put "hat" on TextView. Inspired by Telegram appbar title with Santa Claus hat 🎅🏻
Stars: ✭ 51 (+45.71%)
Mutual labels:  textview

embedded-text crates.io docs.rs Rust

TextBox for embedded-graphics.

This crate provides a configurable TextBox to render multiline text inside a bounding Rectangle using embedded-graphics.

TextBox supports the common text alignments:

  • Horizontal:
    • Left
    • Right
    • Center
    • Justified
  • Vertical:
    • Top
    • Middle
    • Bottom

TextBox also supports some special characters not handled by embedded-graphics' Text:

  • non-breaking space (\u{200b})
  • zero-width space (\u{a0})
  • soft hyphen (\u{ad})
  • carriage return (\r)
  • tab (\t) with configurable tab size

TextBox also supports text coloring using ANSI escape codes via the Ansi plugin.

Example

The examples are based on the embedded-graphics simulator. The simulator is built on top of SDL2. See the simulator README for more information.

embedded-text example

embedded-text example with colored text

use embedded_graphics::{
    mono_font::{ascii::FONT_6X10, MonoTextStyle},
    pixelcolor::BinaryColor,
    prelude::*,
    primitives::Rectangle,
};
use embedded_graphics_simulator::{
    BinaryColorTheme, OutputSettingsBuilder, SimulatorDisplay, Window,
};
use embedded_text::{
    alignment::HorizontalAlignment,
    style::{HeightMode, TextBoxStyleBuilder},
    TextBox,
};

fn main() {
    let text = "Hello, World!\n\
    A paragraph is a number of lines that end with a manual newline. Paragraph spacing is the \
    number of pixels between two paragraphs.\n\
    Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when \
    an unknown printer took a galley of type and scrambled it to make a type specimen book.";

    // Specify the styling options:
    // * Use the 6x10 MonoFont from embedded-graphics.
    // * Draw the text fully justified.
    // * Use `FitToText` height mode to stretch the text box to the exact height of the text.
    // * Draw the text with `BinaryColor::On`, which will be displayed as light blue.
    let character_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
    let textbox_style = TextBoxStyleBuilder::new()
        .height_mode(HeightMode::FitToText)
        .alignment(HorizontalAlignment::Justified)
        .paragraph_spacing(6)
        .build();

    // Specify the bounding box. Note the 0px height. The `FitToText` height mode will
    // measure and adjust the height of the text box in `into_styled()`.
    let bounds = Rectangle::new(Point::zero(), Size::new(128, 0));

    // Create the text box and apply styling options.
    let text_box = TextBox::with_textbox_style(text, bounds, character_style, textbox_style);

    // Create a simulated display with the dimensions of the text box.
    let mut display = SimulatorDisplay::new(text_box.bounding_box().size);

    // Draw the text box.
    text_box.draw(&mut display).unwrap();

    // Set up the window and show the display's contents.
    let output_settings = OutputSettingsBuilder::new()
        .theme(BinaryColorTheme::OledBlue)
        .scale(2)
        .build();
    Window::new("TextBox example with paragraph spacing", &output_settings).show_static(&display);
}

Cargo features

  • plugin (experimental): allows implementing custom plugins.
  • ansi (default enabled): enables ANSI sequence support using the Ansi plugin.

Development setup

Minimum supported Rust version

The minimum supported Rust version for embedded-text is 1.46.0 or greater. Ensure you have the latest stable version of Rust installed, preferably through https://rustup.rs.

Documentation depends on the ability to link by item names (a.k.a intra-doc links), which is available since Rust 1.48.

Installation

For setup in general, follow the installation instructions for embedded-graphics.

To install SDL2 on Windows, see https://github.com/Rust-SDL2/rust-sdl2#windows-msvc

Attribution

The last paragraph of the example text is copied from https://www.lipsum.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].