Jump to content


Photo

Can a function disable property?


  • Please log in to reply
4 replies to this topic

#1 frenetic_friend

frenetic_friend

    Member

  • Normal Members
  • PipPip
  • 53 posts
  • Gender:Male
  • Location:Moscow

Posted 16 August 2017 - 17:24

I have resizeable buttons in my tool, and when button height is more than 17, I'd like it to display text. If less - no text.

So, I'm trying to do sometning like this
 

	local function text_or_not(h)
		if h > 17 then
			return someText
			else
			return ""
                        --return nil
		end
	end
	
	vb:button { 
		height = h,               
		text = text_or_not(h)
	}

If return nil, it shows error. If return "" then no text is shown, BUT button behaves like it contains text, i.e. it's height equals font height, which is not good. What should I do?


Edited by frenetic_friend, 16 August 2017 - 18:06.


#2 dblue

dblue

    Dodgy Geezer

  • Admins
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5595 posts
  • Gender:Male
  • Location:Berlin
  • Interests:Code. Music. Graphics.

Posted 16 August 2017 - 21:35

A blank string is still considered a string, so the button will use the minimum height that the font allows.

Setting the button text to nil instead will allow you to freely resize it, even down to 1 or 2 pixels high if you really wish.

I quickly tested your function here but modified it to return nil instead of "", and it seemed to work just fine.
 
local function text_or_not(h)
  if h > 17 then
    return "Awesome Button"
  else
    return nil
  end
end
What is the exact error you're getting?

Are you sure it's caused by that portion of your code, and not something else nearby?

#3 frenetic_friend

frenetic_friend

    Member

  • Normal Members
  • PipPip
  • 53 posts
  • Gender:Male
  • Location:Moscow

Posted 17 August 2017 - 06:55

Now it works, sorry.

Same thing happened yesterday when song():undo() was freezing Renoise. I was going to post a question already but then Renoise restarted and the problem was gone by itself.



#4 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1467 posts
  • Gender:Not Telling
  • Location:Sweden
  • Interests:music, philosophy, engineering

Posted 17 August 2017 - 07:29

Here is a more compact alternative, if you prefer:

vb:button {
  height = h,
  text = h > 17 and "Awesome Button" or nil
}

  • frenetic_friend likes this

#5 frenetic_friend

frenetic_friend

    Member

  • Normal Members
  • PipPip
  • 53 posts
  • Gender:Male
  • Location:Moscow

Posted 17 August 2017 - 07:43

 

Here is a more compact alternative

Thank you! I knew this construction but it slipped my mind


Edited by frenetic_friend, 17 August 2017 - 07:43.