when do we use snip%, snip-class% and editor-snip%

62 views
Skip to first unread message

KOKOU AFIDEGNON

unread,
Nov 19, 2020, 10:47:19 PM11/19/20
to Racket Users
I have been reading about those classes but i can't properly figure out. 

what are the main use-case of snip, snip-class and editor-snip? 




Alex Harsanyi

unread,
Nov 20, 2020, 12:25:56 AM11/20/20
to Racket Users
You use snips to build small interactive widgets which can be combined and embedded into other GUI applications.   the snip-class% is a helper class for building snips and editor-snip% is a type of snip which allows building nested editors (an editor within an editor).

DrRacket uses snips for its editor and REPL, and supports user defined snips as well.  For example, in the video below, the plot is a snip% and so is the map.   Once you implement a snip, DrRacket knows how to use it when you show it in the REPL:


snips can also be embedded into GUI applications, for example you can build a GUI window which contains a map and several plots:


and you can also build interactive applications.  In the video below, each game tile is a snip% and they are managed by a pasteboard% object:


Alex.

KOKOU AFIDEGNON

unread,
Nov 20, 2020, 3:56:03 AM11/20/20
to Alex Harsanyi, Racket Users
please, can you provide some tutorial about this video? 

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/156fcba7-86b4-483b-a936-8121a0f9f397n%40googlegroups.com.

Alex Harsanyi

unread,
Nov 20, 2020, 5:39:57 AM11/20/20
to Racket Users
On Friday, November 20, 2020 at 4:56:03 PM UTC+8 kokou.a...@gmail.com wrote:
please, can you provide some tutorial about this video? 

This explains how the program works: https://alex-hhh.github.io/2020/06/ishido.html, there are other snip% related tutorials on that web site.

KOKOU AFIDEGNON

unread,
Nov 20, 2020, 10:09:13 AM11/20/20
to Alex Harsanyi, Racket Users
Thanks, I'm opening another subject meanwhile, Can you please advise? 

This is my current code which displays a rectangle on a pasteboard. 

I'm trying to build a wireframe designer where. I can click on a button or a node on a rectangle to create either an inner rectangle/circle or another standalone shape which will also contains their properties. At the end, those created object will serve to generate code samples. 

Can you please advise what functions or classes needed to improve on that? 

Below is the current implementation done so far. 


#lang racket
(require racket/gui racket/draw pict)

(define board (new pasteboard%))
(define toplevel (new frame%
                      [label "My board"]
                      [width 500]
                      [height 500]))
(define canvas (new editor-canvas%
                    [parent toplevel]
                    [editor board]))
(send toplevel show #t)
(define my-snip-class
  (new (class snip-class%
         (super-new)
         (send this set-classname "my-snip"))))
(send (get-the-snip-class-list) add my-snip-class)
(define rectangle-snip%
  (class snip%
    (init-field w h)
    (super-new)
    (send this set-snipclass my-snip-class)
    (define/override (get-extent dc x y width height . other)
      (when width (set-box! width w))
      (when height (set-box! height h)))
    (define/override (draw dc x y . other)
      (draw-pict (rectangle w h) dc x y))))

(send board insert (new rectangle-snip% [w 30] [h 80]) 100 300)


Alex Harsanyi

unread,
Nov 21, 2020, 1:16:48 AM11/21/20
to Racket Users
On Friday, November 20, 2020 at 11:09:13 PM UTC+8 kokou.a...@gmail.com wrote:
Thanks, I'm opening another subject meanwhile, Can you please advise? 

This is my current code which displays a rectangle on a pasteboard. 

I'm trying to build a wireframe designer where. I can click on a button or a node on a rectangle to create either an inner rectangle/circle or another standalone shape which will also contains their properties. At the end, those created object will serve to generate code samples. 

Can you please advise what functions or classes needed to improve on that? 

To respond to mouse clicks, the snip instance will need to handle mouse events, which means you need to (1) set the flag 'handles-events and, depending on your use case, 'handles-all-mouse-events and (2) override the `on-event` method.

Alex.
Reply all
Reply to author
Forward
0 new messages