How do I find the actual minimum size of a GUI control (e.g. a button)
without the space around it?


I'm on OSX 10.11.  I'm working on a spreadsheet application, and my current
plan is to have each cell be represented as a separate text control.[1]  I
need to have these controls be in contact with one another the way they are
in Excel or any other spreadsheet.  (That is, there is no empty space
between the controls.) By default Racket wants to put significant space
between controls and I've been unable to figure out how to stop this in a
clean, cross-platform way.

Here's what I've tried:

(define frame (new frame% [label "Example"]))
(define panel (new horizontal-panel% [parent frame]))
(define left-btn (new button% [parent panel] [label "Left"]))
(define right-btn (new button% [parent panel] [label "Right"]))
(define (shrinkwrap c)
  (send c horiz-margin 0)
  (send c vert-margin 0))
(void (map shrinkwrap (list left-btn right-btn panel)))
(for ((c (list panel frame)))
     (send c spacing 0))
;;    These won't work because get-min-graphical-size is 84 and will trump
the requested size
(send left-btn min-width 70)
(send right-btn min-width 70)

(send frame show #t)

This shows the frame with two buttons arranged horizontally.  There is
significant space around each button and between the two buttons.  I want
there to be no space between them.


Both the left and right buttons have minimum graphical sizes of (84,32), as
shown by:
(begin
  (define-values (w h) (send left-btn get-graphical-min-size))
  (displayln
   (format "left button min w/h: ~a,~a" w h)))
;; Same for right-btn

A quick test shows that I can get the behavior I need by overriding
place-children:

(define squishable-panel%
  (class horizontal-panel%
         (define/override (place-children info w h)
           (displayln "Called place-children")
           '((0 0 70 20) (70 0 70 20)))
         (super-new)))
(define panel (new squishable-panel% [parent frame]))
;;  ...all other declarations stay the same...

The problem is that I got the above numbers by experimentation.
get-graphical-min-size returns the size *with* the spacing that I'm trying
to get rid of, which defeats the purpose.  (Also, why??  That's not the
size of the button, it's the size of the button plus some extra space.)  I
don't see a clean way to go from the GMS to the actual minimum size when
dealing with cross-platform size differences and the fact that Windows is
pixel-based and OSX is drawing-unit-based.

Any suggestions?


Dave

[1] I may need to do some optimizations later instead of representing empty
cells as controls, but that's for later.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to