horizontal alignment in a message% or equivalent

40 views
Skip to first unread message

Martin DeMello

unread,
Oct 13, 2019, 3:11:04 AM10/13/19
to Racket Users
I'm trying to create a message% with the text left-justified rather than centred, and have been searching through the docs with no luck. Is there a way to do it, or a widget I should be using instead? My use case is to provide a status message at the bottom of a frame.

martin

Laurent

unread,
Oct 13, 2019, 11:02:39 AM10/13/19
to Martin DeMello, Racket Users
If I remember correctly, I think you want to add a spacer box at the right of your message% in the same panel:
so that the message takes only the space it needs and is thus flushed to the left.


On Sun, Oct 13, 2019 at 8:11 AM Martin DeMello <martin...@gmail.com> wrote:
I'm trying to create a message% with the text left-justified rather than centred, and have been searching through the docs with no luck. Is there a way to do it, or a widget I should be using instead? My use case is to provide a status message at the bottom of a frame.

martin

--
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/CAFrFfuHv8WAVnSSQibmQ7DOFoJjw_HyVkXm_7Y-2He4fPQ30Hw%40mail.gmail.com.

Martin DeMello

unread,
Oct 13, 2019, 1:15:01 PM10/13/19
to Laurent, Racket Users
thanks, that worked nicely!

martin

Simon Schlee

unread,
Oct 13, 2019, 4:33:30 PM10/13/19
to Racket Users
Another possibility is to set the stretchable-width of the message to #f, this way the message does not take more than its minimal required space.

#lang racket/gui

(define (example)
  (define frame (new frame% [label "Alignment example"] [width 400]))
  (define vbox  (new vertical-panel% [parent frame]))

  (define (test h-align)
    (define p (new horizontal-panel% [parent vbox] [alignment `(,h-align center)]))
    (new message% [parent p] [label (symbol->string h-align)] [stretchable-width #f]))

  (for-each test '(left center right))

  (send frame show #t))

(module+ main
  (example))


RacketPanelAlignmentExample.png


Reply all
Reply to author
Forward
0 new messages