ashbb / green_shoes

Green Shoes is one of the colorful Shoes written in pure Ruby.
Other
204 stars 37 forks source link

Allow nil in listbox, setting text to item not in the items list. #67

Open meruby opened 12 years ago

meruby commented 12 years ago

There are times when you don't want anything from selection. To do this I have to add "nil" in item lists. It works, but I think it is not a bad idea to have a option which allows user to clear selected item. You can do this with new option :entry, but user might want to just allow nil as a selected item without allowing user to type anything. Do you think it make sense?

One more thing I think we should add to listbox is if :entry is set to true, allow user to set text value which might not be in the list items.

Once again, thanks for wonderful green_shoes and making changes to it quickly.

ashbb commented 12 years ago

@meruby If you overwrite Shoes::ListBox#text method like this, you can get nil when you don't select anything.

class Shoes::ListBox
  alias :_text :text
  def text
    return unless @real.active_text
    _text
  end
end

Shoes.app do
  lb = list_box items: [1, 2, 3, 4]
  button 'print' do
    p lb.text
  end
end

But in the above code, once you select one of items, you will never clear the selected item. So, IMHO, it's better to add nil in item list like this: list_box items: [1, 2, 3, 4, nil]

One more thing I think we should add to listbox is if :entry is set to true, allow user to set text value which might not be in the list items.

Ah,... what does it mean to add? It means that we should add the user input value to the array of items?

meruby commented 12 years ago

If user has det default value to say 9 in list box, but list contains only [1,2,3,4,5], we should allow 9 to stay in listbox text if :entry is set to true. listbox items list will be still same [1,2,3,4,5].

Samir

On Mon, Aug 27, 2012 at 7:13 AM, ashbb notifications@github.com wrote:

@meruby https://github.com/meruby If you overwrite Shoes::ListBox#text method like this, you can get nilwhen you don't select anything.

class Shoes::ListBox alias :_text :text def text return unless @real.active_text _text endend Shoes.app do lb = list_box items: [1, 2, 3, 4] button 'print' do p lb.text endend

But in the above code, once you select one of items, you will never clear the selected item. So, IMHO, it's better to add nil in item list like this: list_box items: [1, 2, 3, 4, nil]

One more thing I think we should add to listbox is if :entry is set to true, allow user to set text value which might not be in the list items.

Ah,... what does it mean to add? It means that we should add the user input value to the array of items?

— Reply to this email directly or view it on GitHubhttps://github.com/ashbb/green_shoes/issues/67#issuecomment-8052811.

ashbb commented 12 years ago

You mean the following snippet should work well. Right?

Shoes.app do
  lb = list_box items: [1, 2, 3, 4], entry: true, choose: 9
  button 'print' do
    p lb.text
  end
end

If so, I'll be able to update Green Shoes. But if there is still my misunderstanging, please let me know.

meruby commented 12 years ago

Yes, this should work well. Thanks for accepting my suggestion.

Samir

On Tue, Aug 28, 2012 at 9:52 AM, ashbb notifications@github.com wrote:

You mean the following snippet should work well. Right?

Shoes.app do lb = list_box items: [1, 2, 3, 4], entry: true, choose: 9

button 'print' do p lb.text endend

If so, I'll be able to update Green Shoes. But if there is still my misunderstanging, please let me know.

— Reply to this email directly or view it on GitHubhttps://github.com/ashbb/green_shoes/issues/67#issuecomment-8092081.