chris613
2019-9-28 10:37:55

i feel like im missing something simple here maybe … ive been following the guide on implimenting snips. #lang racket/gui (define thing (make-object string-snip% "hello")) (define collapsable-snip% (class snip% (init given-child) (define open? #f) (define child given-child) (super-new) (define/public (get-child) child) (define/override (draw dc x y left top right bottom dx dy draw-caret) (send child draw dc x y left top right bottom dx dy draw-caret)) (define/override (get-extent dc x y w h descent space lspace rspace) (send child get-extent dc x y w h descent space lspace rspace)) )) (define colapsable/thing (make-object collapsable-snip% thing)) (send colapsable/thing get-child) colapsable/thing


chris613
2019-9-28 10:38:06

currently im just trying to “wrap” a snip


chris613
2019-9-28 10:49:39

But all I get is some empty space?


chris613
2019-9-28 10:50:12

I figured if I delicate the draw method to the internal snip it should draw the internal one for me?


soegaard2
2019-9-28 11:03:12

@chris613 Define a copy method. I believe DrRacket makes a copy, and then draws.


soegaard2
2019-9-28 11:03:16

E.g. (define/override (copy) (make-object collapsable-snip% child))


soegaard2
2019-9-28 11:03:42

(But this reuses the child - maybe call the copy method on the child instead)


chris613
2019-9-28 11:11:21

Ahhhh brill thanks!


chris613
2019-9-28 14:20:49

seems like if the draw method throws an error when printing to repl it can freeze drracket. is this normal?


chris613
2019-9-28 14:21:15

also, tried your method and works great so thanks!


soegaard2
2019-9-28 15:07:23

@chris613 Don’t know it is normal. @robby will know.


robby
2019-9-28 15:37:50

@robby has joined the channel


robby
2019-9-28 15:38:04

Yes a buggy snip can break drr.


robby
2019-9-28 15:38:16

This is a bug in drr but not a simple one to fix


robby
2019-9-28 15:40:49

It is a problem only when you return snips to the REPL


robby
2019-9-28 15:41:11

Inserting them into a text% object and showing that in your own frame causes no problems.


chris613
2019-9-28 17:22:10

i assume thats somethign to do with the error essentially braking into the drracket “scope” or something by being returned to the repl ?


chris613
2019-9-28 17:22:19

thanks for the clarification though :slightly_smiling_face:


robby
2019-9-28 19:53:25

roughly speaking, when an error happens due to a callback to a snip that is in the interactions window, it counts as being a part of DrRacket’s implementation instead of the program in the definition window’s implementation (which is wrong — it should still count as being part of the definitions window’s program)


robby
2019-9-28 19:53:52

So all kinds of things can go wrong, not just mishandled errors, actually :disappointed: