HISE Logo Forum
    • Categories
    • Register
    • Login

    Laf function triggers twice for each setLocalLookAndFeel ?

    Scheduled Pinned Locked Moved Scripting
    8 Posts 3 Posters 380 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      observantsound
      last edited by

      I'm trying to draw 2 triangles for "previous" and "next" buttons.
      In my Laf I have a condition to check the object.text name to either rotate it to the left or the right.
      But it's not working and print returns this when I run it

      Interface: btnPrevious
      Interface: btnPrevious
      Interface: false
      Interface: btnNext
      Interface: btnNext
      Interface: false
      

      Here's my code for it

      // Select Buttons
      const var btnPrevious = Content.addButton("btnPrevious", a[0] + 15, a[1] + 5);
      const var btnNext = Content.addButton("btnNext", a[0] + 45, a[1] + 5);
      
      const LafButton = Content.createLocalLookAndFeel();
      LafButton.registerFunction("drawToggleButton", function(g, obj){ 	
      	 //Console.print(trace(obj)); // trace converts contents of object into a string
      	 var area = obj.area; 	// get "area" property from obj and save into a var for quick access
      	 var border = 3; 
      	
      	g.setColour(Colours.withAlpha(obj.itemColour1, alpha)); 
      	
      	Console.print(obj.text);
      	if (Console.print(obj.text) == "btnPrevious"){
      		g.fillTriangle([0, 0, 20, 20], Math.toRadians(270));
      		Console.print("true");
      	}
      	else{
      		g.fillTriangle([0, 0, 20, 20], Math.toRadians(90));	
      		Console.print("false");
      	}
      });
      
      btnPrevious.setLocalLookAndFeel(LafButton);
      btnNext.setLocalLookAndFeel(LafButton);
      
      Christoph HartC 1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart @observantsound
        last edited by

        @observantsound lookandfeel functions are triggered whenever the OS decides to repaint an area or the entire UI element so it‘s absolutely fine for it to be executed multiple times and any logic that depends on it being called only when you assume it‘s necessary should be considered as flawed.

        O 1 Reply Last reply Reply Quote 0
        • O
          observantsound @Christoph Hart
          last edited by

          @Christoph-Hart I just caught my own mistake.

          The wrong line was...

          if (Console.print(obj.text) == "btnPrevious"){
          

          When it should have been...

          if (obj.text == "btnPrevious"){
          

          Is there a way to make this more fool proof though?
          To not make it dependent on exact button names?

          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @observantsound
            last edited by

            @observantsound Use a separate laf function for each button

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            O 1 Reply Last reply Reply Quote 0
            • O
              observantsound @d.healey
              last edited by

              @d-healey What if I know that I'll definitely re-use this for other buttons?

              One pair might be called "btnPreviousSample" or "btnPreviousFX" etc.

              d.healeyD 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @observantsound
                last edited by d.healey

                @observantsound The part that will be reused can be placed in an inline function. The stuff that is different goes in the individual laf functions, from which you can call the inline function. I thought I'd made a video about this but I can't find it now, maybe I imagined it...

                Ah I think this is the video I was thinking of. It's for paint routines but the same principle applies to laf.

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey
                  last edited by

                  Another option is to use the text property as a value. So you could set the text of one button to 270 and another to 90 and you use that value in your .toRadians call.

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  O 1 Reply Last reply Reply Quote 0
                  • O
                    observantsound @d.healey
                    last edited by

                    @d-healey Using the txt property seems like a nice idea.
                    The video was also helpful. Thx!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post

                    15

                    Online

                    1.7k

                    Users

                    11.8k

                    Topics

                    103.1k

                    Posts