# Scale Text to Button

**URL:** <https://discourse.processing.org/t/scale-text-to-button/40724>\
**Category:** Coding Questions\
**Created:** [January 27, 2023, 12:38am UTC](https://discourse.processing.org/t/scale-text-to-button/40724 "2023-01-27T00:38:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![turke1034](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/turke1034/32/16910_2.png) [@turke1034](https://discourse.processing.org/u/turke1034)\
**Post date:** [January 27, 2023, 12:38am UTC](https://discourse.processing.org/t/scale-text-to-button/40724/1 "2023-01-27T00:38:09Z")

</div>

Hi, I want to create text that dynamically scales to a few pixels smaller than its respective button/boundaries size and also to the size of the screen. It is very easy to let it scale dynamically to the screen; however, I am finding it difficult to come up with an equation to let it scale to the button as well.

```auto
// Scaling the text with the screen
scale((float) width / DEFAULT_WIDTH);

```

However, the text compared to the rest of the screen is always the same size, not fit to the button/boundary.

![bad_scaling_example](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/b/4bb9bbcb840bd621c365184faf4aa0e9f5ea0bad.png)  
(Top: What I want; Bottom: What it is currently)

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [January 27, 2023, 1:22am UTC](https://discourse.processing.org/t/scale-text-to-button/40724/2 "2023-01-27T01:22:22Z")

</div>

Instead of scale, have you tried textSize( ) with the same scaling factor?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 27, 2023, 4:54pm UTC](https://discourse.processing.org/t/scale-text-to-button/40724/3 "2023-01-27T16:54:35Z")

</div>

check out this:

see [textWidth() / Reference / Processing.org](https://processing.org/reference/textWidth_.html)
