How do I add text/label to a custom component?

Home Forums General Programming How do I add text/label to a custom component?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #69793
    Peter_EP
    Participant
      • Topics: 5
      • Replies: 19
      • Total: 24

      I have a uiCustomComponent on which I have successfully drawn a graph, I now want to add text on the x and y axis, nothing special just “+10dB”, “0dB”, “1kHz” – question is how do I do it?

      I could use uiLabel but I don’t know if to link it to uiCustomComponent, maybe as part of a Group, or I suspect there is a better way to “draw” the text in the same way we use drawLine().

      I’ve seen reference to drawText( ) in another post, looked at JUCE for a definition, that has DrawableText() and no co-ords.

      Also I want to place the text using x,y co-ords within the uiCustomComponent

      Any clues please?

      • This topic was modified 7 years, 8 months ago by Peter_EP. Reason: I need co-ords
      #69796
      goodweather
      Participant
        • Topics: 45
        • Replies: 550
        • Total: 595
        • ★★★

        No idea (but will also look when I have some time and to learn)…
        You can maybe use the workaround to use classical uiLabels in Ctrlr and to position them in front of the uiCustomComponent?
        At least this would be a temporary solution (not so nice but working) 🙂

        #69797
        goodweather
        Participant
          • Topics: 45
          • Replies: 550
          • Total: 595
          • ★★★

          Hi again. I searched in Juce API and found the details…

          In a custom component you have used different functions like graphics.drawLine().
          So, you are using the Graphics class.
          In that class there are different drawText() functions available 🙂

          Direct link: https://www.juce.com/doc/classGraphics

          #69798
          Peter_EP
          Participant
            • Topics: 5
            • Replies: 19
            • Total: 24

            Thanks, to save face a little, I did look though the JUCE list but I must have not seen the drawText() thing. However!

            Here’s the definition:-

            void Graphics::drawText ( const String & text,
            		int  	x,
            		int  	y,
            		int  	width,
            		int  	height,
            		Justification  	justificationType,
            		bool  	useEllipsesIfTooBig = true 
            	) 		const

            my code is: g:drawText("+10dB", 30, 40, 30, 20, 2, false)

            and the error is:`Error message: No matching overload found, candidates:
            void drawText(Graphics const&,String const&,Rectangle const&,Justification,bool)
            void drawText(Graphics const&,String const&,int,int,int,int,Justification,bool)`

            So why hasn’t this worked?

            Thanks again for the assistance, I do appreciate it.

            #69804
            Peter_EP
            Participant
              • Topics: 5
              • Replies: 19
              • Total: 24

              phew! – now I know drawText is valid I did another search of this website and it seems I didn’t understand the definition, anyway this worked:

              g:drawText(“+10dB”, 30, 40, 30, 20, Justification(Justification.right), false)

              it was the Justification part that confused me.

              #69806
              goodweather
              Participant
                • Topics: 45
                • Replies: 550
                • Total: 595
                • ★★★

                🙂

              Viewing 6 posts - 1 through 6 (of 6 total)
              • The forum ‘Programming’ is closed to new topics and replies.
              There is currently 0 users and 122 guests online
              No users are currently active
              Forum Statistics
              Threads: 2,495, Posts: 17,374, Members: 77,605
              Most users ever online was 12 on January 22, 2019 3:47 pm
              Ctrlr