# Should changing a style% update derived style%'s?

**URL:** <https://racket.discourse.group/t/should-changing-a-style-update-derived-style-s/3904>\
**Category:** Questions & Answers\
**Created:** [August 17, 2025, 1:18am UTC](https://racket.discourse.group/t/should-changing-a-style-update-derived-style-s/3904 "2025-08-17T01:18:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjsimpso](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jjsimpso/32/602_2.png) [@jjsimpso](https://racket.discourse.group/u/jjsimpso)\
**Post date:** [August 17, 2025, 1:18am UTC](https://racket.discourse.group/t/should-changing-a-style-update-derived-style-s/3904/1 "2025-08-17T01:18:42Z")

</div>

I have some code to increase the font size in my application:

```scheme
(define (change-canvas-font-size canvas amount)
    (define standard (send (send canvas get-style-list) find-named-style "Standard"))
    (when standard
      (define delta (make-object style-delta%))
      (send standard get-delta delta)
      (send delta set-delta 'change-size (+ (send standard get-size) amount))
      (send standard set-delta delta)
      (send canvas redo-layout)))

```

This works but it doesn't update the size of other `style%` objects derived from `Standard`, ie styles that have `Standard` as their base style. Am I misunderstanding the docs here? It seems like the point of having a hierarchy of styles is so that you don't have to walk down the tree manually updating styles.

Here is an example of how I have some of my styles defined:

```scheme
(define standard (send style-list find-named-style "Standard"))
(define standard-delta (make-object style-delta%))
(send* standard-delta
  (set-family 'modern)
  ;(set-face font-name)
  (set-delta 'change-size 12)
  (set-delta-foreground text-fg-color)
  (set-delta-background canvas-bg-color))
(send standard set-delta standard-delta)

(define (make-color-style name color)
  ;; Each style created with this procedure copies "Standard" style
  ;; and creates a new style by name 'name' and with the foreground
  ;; color 'color'.
  (send (send style-list new-named-style name standard)
        set-delta (send* (make-object style-delta%)
                    (copy standard-delta)
                    (set-delta-foreground color))))
   
(make-color-style "Link" link-color)
(make-color-style "Link Highlight" link-highlight-color)

```

`Link` and `Link Highlight` are derived from `Standard` so it would be nice if their size changed to match `Standard`. I was thinking that perhaps it has something to do with the fact that the `style-delta%` I use for the derived styles is copying the `change-size` delta from `standard-delta` but removing `change-size` from `standard-delta` didn't change anything.

I probably need to do something with the additive or multiplicative style size parameters(instead of just using `change-size`, but my experiments with those haven't gone well.

---

<div class="post-metadata">

**Author:** ![mflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/mflatt/32/6_2.png) [@mflatt](https://racket.discourse.group/u/mflatt)\
**Post date:** [August 19, 2025, 10:00pm UTC](https://racket.discourse.group/t/should-changing-a-style-update-derived-style-s/3904/2 "2025-08-19T22:00:58Z")

</div>

The `new-named-style` method makes a new style that is essentially a copy of a given one, while `find-or-create-style` creates one that is linked to an existing style. So, I think you want to use both of those:

```scheme
(define (make-color-style name color)
  (send style-list new-named-style name
        (send style-list find-or-create-style standard
              (send (make-object style-delta%)
                    set-delta-foreground color))))

```

---

<div class="post-metadata">

**Author:** ![jjsimpso](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jjsimpso/32/602_2.png) [@jjsimpso](https://racket.discourse.group/u/jjsimpso)\
**Post date:** [August 20, 2025, 1:00am UTC](https://racket.discourse.group/t/should-changing-a-style-update-derived-style-s/3904/3 "2025-08-20T01:00:30Z")

</div>

Ah, this does seem to help. With your version, the style size change is propagating.

I do see a weird problem that is most likely an issue with my code somewhere, which I'll look into further. When I calculate the extent of `string-snip%`s, the height is updating but not the width. For regular `string`s both the width and height are updated correctly.

If I can't fix this but can reproduce it in a simple example, I'll post back here. But for now I'll assume this is a "me" problem. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![jjsimpso](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jjsimpso/32/602_2.png) [@jjsimpso](https://racket.discourse.group/u/jjsimpso)\
**Post date:** [August 20, 2025, 8:45pm UTC](https://racket.discourse.group/t/should-changing-a-style-update-derived-style-s/3904/4 "2025-08-20T20:45:01Z")

</div>

Calling the `size-cache-invalid` method on `string-snip%`s when I change the font size fixes my problem with only the height of `string-snip%`s updating. It looks like the `string-snip%` code has an optimization to reduce how often it recalculates the extent of the snip.

This probably wouldn't be an issue for anyone using a standard canvas, but I needed to fix this in my custom `canvas%`.
