# VTK Examples - Text & Scalar Bar Widgets

**URL:** https://discourse.vtk.org/t/vtk-examples-text-scalar-bar-widgets/16156
**Category:** Announcements
**Created:** [November 24, 2025, 10:58pm UTC](https://discourse.vtk.org/t/vtk-examples-text-scalar-bar-widgets/16156 "2025-11-24T22:58:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [November 24, 2025, 10:58pm UTC](https://discourse.vtk.org/t/vtk-examples-text-scalar-bar-widgets/16156/1 "2025-11-24T22:58:09Z")

</div>

# Text & ScalarBar Widgets

Until now there have been only two examples in C++ namely [TextWidget.cxx](https://examples.vtk.org/site/Cxx/Widgets/TextWidget/) and [ScalarBarWidget.cxx](https://examples.vtk.org/site/Cxx/Widgets/ScalarBarWidget/). These examples are very simple. In the PythonicAPI examples, about 20 examples already use these widgets.

The main reason for using these widgets is their versatility. Since these are widgets, the user can interact with the widget, rescaling and repositioning it. Useful if they obstruct the object being viewed.

To rectify this, the Curvature examples have been enhanced along with RescaleReverseLUT in both the C++ and PythonicAPI examples. It is hoped that these examples will provide people with code to easily implement the use these these widgets in their own code.

In order to facilitate this, some ancillary structs/classes and functions have been provided:

- `GetTextPositions(...)` and `get_text_positions(...)`: these take lists or vectors of text and return coordinates that are used to position the relevant vtkTextWidget using the text. It is pretty basic, just using the characters of the text to position it. See [RescaleReverseLUT.cxx](https://examples.vtk.org/site/Cxx/Utilities/RescaleReverseLUT/), [RescaleReverseLUT.py](https://examples.vtk.org/site/PythonicAPI/Utilities/RescaleReverseLUT/) where text is positioned in four viewports. Note the use of a Courier font to ensure that centered text of the same text height is centered in all four viewports.

- A struct: `ScalarBarProperties` and class: `scalar_bar_properties`, these aggregate all the necessary scalar bar properties into one place. This makes it simple to create a function `MakeScalarBarWidget(...)` and `make_scalar_barWidget(...)` returning the vtkScalarBarWidget. See: [CurvaturesAdjustEdges.cxx](https://examples.vtk.org/site/Cxx/PolyData/CurvaturesAdjustEdges/), [CurvaturesAdjustEdges.py](https://examples.vtk.org/site/PythonicAPI/PolyData/CurvaturesAdjustEdges/).

Edit and change these as you need.

Other changes in the curvature examples are:

- The use of `cli11`, making the specification, parsing and checking of command line parameters in C++ very easy. Also see how `SetWindowName()` uses this and the `std::filesystem` to name the window. See [Curvatures.cxx](https://examples.vtk.org/site/Cxx/PolyData/Curvatures/) where this is used to name the window along with appending the file name used - if applicable.

- The use of `fmt` replacing stream formatting.

Remember to add

```plaintext

cli11

fmt

```

to your CMakeLists.txt file.

**Note:**

1. In most cases the curvature calculations have been moved into functions returning a struct or class.

2. In the PythonicAPI, NormalsCurvaturesElevations is now called [CurvaturesNormalsElevations.py](https://examples.vtk.org/site/PythonicAPI/PolyData/CurvaturesNormalsElevations/).
