Fl_Button label line spacing

16 vaatamist
Liigu esimese lugemata sõnumi juurde

Daniel Santos

lugemata,
11. aug 2021, 08:55:1711.08.21
kuni fltk.general
Hi, I'm trying to put vertical text in a button, I'm using the \n newline, but the vertical spacing is too big, is it possible to put less spacing?
Thanks

Ian MacArthur

lugemata,
11. aug 2021, 10:44:3311.08.21
kuni fltk.general
On Wednesday, 11 August 2021 at 13:55:17 UTC+1 supe...@gmail.com wrote:
Hi, I'm trying to put vertical text in a button, I'm using the \n newline, but the vertical spacing is too big, is it possible to put less spacing?
Thanks


OK, so I interpret your question like this: You have a tall, thin button and are setting this label as "T\nh\ni\ns" to try and get (ASCII art alert!)

-----
| T |
| h |
| i |
| s |
-----

Is that correct?
If so, there might be no trivial answer...
Note that to keep things simple, fltk just uses the line height to set the vertical spacing, so it is not readily changed (it is tied to the font size, in effect.)
In the past, I have derived my own button and then used fl_text_extents() to measure the minimum bounds around each glyph and position it suitably, but that's a fair bit of work. (Contrast with fl_measure() which will use a vertical bound based on the line spacing, which is in essence what you are seeing at present.)
An alternative, if you derive your own button, might be to just rotate the entire label 90 degrees (without the embedded "\n" in the labels) and see how that looks. The "rotated_text" demo illustrates that approach - though I do not know if that would be any use to you or not.


Daniel Santos

lugemata,
11. aug 2021, 11:15:2011.08.21
kuni fltk.general
It could be rotated text, how do I rotate it?

Greg Ercolano

lugemata,
11. aug 2021, 11:27:4711.08.21
kuni fltkg...@googlegroups.com


On 8/11/21 5:55 AM, Daniel Santos wrote:
Hi, I'm trying to put vertical text in a button, I'm using the \n newline, but the vertical spacing is too big, is it possible to put less spacing?
Thanks

    I take this to mean you have maybe:

     ___________________
    |                   |
    |     Line One      |
    |                   |
    |     Line Two      |
    |___________________|

    I don't think FLTK allows you to control the line spacing (hmm, not sure why that is),
    but you can derive a class from Fl_Button, and then handle the text drawing bit yourself,
    drawing each line where you want it with separarte fl_draw() calls to handle the text.

    Or, if it's a fixed message, you could just render the text as an image in a paint program
    and save it as an .xpm, then just #include the xpm and use it as the image() for the button..
    similar to how an xpm image is assigned to an Fl_Box in this demo:
    http://seriss.com/people/erco/fltk/#DraggableBoxes

    To assign an image you don't need to derive a class from Fl_Button, just assign the image()
    to it with e.g.

        #include "my_text.xpm"
        [..]
        static Fl_Pixmap my_text_pixmap(my_text);
        Fl_Button *but = new Fl_Button(..);
        but->image(my_text_pixmap);

Philip Rose

lugemata,
11. aug 2021, 11:31:4511.08.21
kuni fltkg...@googlegroups.com

Hi Daniel,

 

Read Ian’s reply to you. He has pointed out a particular demo (rotated_text) to look at. It’ll be in the fltk package somewhere.

 

Phil.

 

Sent from Mail for Windows

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/8d0968e3-1d57-4da6-ac26-085d4fb90fe3n%40googlegroups.com.

 

Greg Ercolano

lugemata,
11. aug 2021, 11:33:1711.08.21
kuni fltkg...@googlegroups.com

On 8/11/21 8:15 AM, Daniel Santos wrote:

It could be rotated text, how do I rotate it?

    Try the test/rotated_text.cxx example included with the FLTK source code.



Vasta kõigile
Vasta autorile
Saada edasi
0 uut sõnumit