All Projects → bdlukaa → rounded_background_text

bdlukaa / rounded_background_text

Licence: BSD-3-Clause license
Text and TextField highlighted with rounded corners

Programming Languages

dart
5743 projects
C++
36643 projects - #6 most used programming language
CMake
9771 projects
HTML
75241 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to rounded background text

Text
An efficient packed, immutable Unicode text type for Haskell, with a powerful loop fusion optimization framework.
Stars: ✭ 248 (+476.74%)
Mutual labels:  text
vue-swimlane
A Text Swimlane plugin for Vue.js
Stars: ✭ 71 (+65.12%)
Mutual labels:  text
clifs
Contrastive Language-Image Forensic Search allows free text searching through videos using OpenAI's machine learning model CLIP
Stars: ✭ 271 (+530.23%)
Mutual labels:  text
DotGrok
Parse text with pattern. Inspired by grok filter.
Stars: ✭ 26 (-39.53%)
Mutual labels:  text
jomini
Low level, performance oriented parser for save and game files from EU4, CK3, HOI4, Vic3, Imperator, and other PDS titles.
Stars: ✭ 40 (-6.98%)
Mutual labels:  text
markdown
markdown tools, libraries & scripts
Stars: ✭ 52 (+20.93%)
Mutual labels:  text
Stubble
Trimmed down {{mustache}} templates in .NET
Stars: ✭ 247 (+474.42%)
Mutual labels:  text
ConTexto
Librería en Python para minería de texto y NLP
Stars: ✭ 43 (+0%)
Mutual labels:  text
textalyzer
Analyze key metrics like number of words, readability, complexity, etc. of any kind of text
Stars: ✭ 50 (+16.28%)
Mutual labels:  text
react-watermark-module
React水印组件,支持图片水印,文字水印。
Stars: ✭ 31 (-27.91%)
Mutual labels:  text
J2N
Java-like Components for .NET
Stars: ✭ 37 (-13.95%)
Mutual labels:  text
TextBoxes
TextBoxes: A Fast Text Detector with a Single Deep Neural Network
Stars: ✭ 625 (+1353.49%)
Mutual labels:  text
react-bones
💀 Dead simple content loading components for React and React-Native. 💀
Stars: ✭ 42 (-2.33%)
Mutual labels:  text
GPT2-Telegram-Chatbot
GPT-2 Telegram Chat bot
Stars: ✭ 67 (+55.81%)
Mutual labels:  text
svelte-slate
slate svelte view layer
Stars: ✭ 43 (+0%)
Mutual labels:  text
Finalcut
A text-based widget toolkit
Stars: ✭ 244 (+467.44%)
Mutual labels:  text
MailDemon
Smtp server for mass emailing, managing email lists and more. Built on .NET Core. Linux, MAC and Windows compatible.
Stars: ✭ 113 (+162.79%)
Mutual labels:  text
cape
Continuous Augmented Positional Embeddings (CAPE) implementation for PyTorch
Stars: ✭ 29 (-32.56%)
Mutual labels:  text
react-native-animateable-text
🆎 A fork of React Native's <Text/> component that supports Animated Values!
Stars: ✭ 263 (+511.63%)
Mutual labels:  text
readthat
Read Text Data
Stars: ✭ 27 (-37.21%)
Mutual labels:  text

rounded_background_text

Highlight text with rounded corners

Content

Features

  • Highlight Text
  • Highlight Text Field [beta]
  • Highlight Text Span

Getting started

Import the package:

import 'package:rounded_background_text/rounded_background_text.dart';

Usage

Highlight a simple text:

RoundedBackgroundText(
  'A cool text to be highlighted',
  style: const TextStyle(fontWeight: FontWeight.bold),
  backgroundColor: Colors.white,
),

Simple Text

Multiline text is also supported

RoundedBackgroundText(
  'A cool text to be highlighted\nWith two lines or more',
  style: const TextStyle(fontWeight: FontWeight.bold),
  backgroundColor: Colors.amber,
),

Two Lines Text

Highlight a text field:

You must use a TextEditingController

final controller = TextEditingController();

RoundedBackgroundTextField(
  controller: controller, // required
  backgroundColor: Colors.blue,
  style: const TextStyle(fontWeight: FontWeight.bold),
  textAlign: TextAlign.center,
),

The text will be highlighted as the user types

TextField Preview

The font size of the text will be reduced if there isn't enough space to fit the text. The text field can't be scrollable

Highlight a text span:

Highlight a small part of a text

RichText(
  text: TextSpan(
    text: 'Start your text and ',
    children: [
      RoundedBackgroundTextSpan(
        text: 'highlight something',
        backgroundColor: Colors.blue,
      ),
      const TextSpan(text: ' when necessary'),
    ],
  ),
),

TextSpan Highlight Preview

You may like to know:

Change the corner radius

You can change the radius of the corners by setting innerRadius and outerRadius:

RoundedBackgroundText(
  'A cool text to be highlighted',
  style: const TextStyle(fontWeight: FontWeight.bold),
  backgroundColor: Colors.white,
  innerRadius: 15.0,
  outerRadius: 10.0,
),

The max allowed value is 20.0. The min is 0.0

Known issues with the text field

  • It can't be scrollable. Instead, as a workaround, the text is scaled down to fit the available space

Deep dive

This section explains, with details, how the background painting works.

RoundedBackgroundText doesn't use a Text widget under the hood. Instead, it uses a custom text painter to paint the text above the background. As soon as the RoundedBackgroundText widget is initialized, the line metrics for the text is calculated (See computeLineMetrics), and is recalculated when the text changes or when the parent width changes. This is done at built time, resulting in a smooth experience for the user.

To paint the background, the line metrics generated before is used. Each line has 4 properties:

  • x - where the line starts horizontally within the size
  • y - where the line starts vertically within the size
  • width - the horizontal size of the line
  • height - the vertical size of the line

With these values, we can generate the background for each line. The background is generated around the whole text: from top-left to bottom-left to bottom-right to top-right to top-left. This makes it easy to calculate when there is a corner, either outer or inner.

The inner and outer radius are dynamically calculated based on the line height, provided by the line metrics, and the given innerFactor and outerFactor, respectively. By default, innerFactor is 8.0 and outerFactor is 10.0. For safety, in order to keep the roundnesses correct, these values must be in the bounds of 0.0 (min) and 20.0 max, otherwise the painting would go off-line.

Contribution

Feel free to file an issue if you find a problem or make pull requests.

All contributions are welcome!

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].