Opened 6 years ago

Last modified 6 years ago

#11871 new enhancement

BButton class accepting BShape argument for its label

Reported by: konradjr Owned by: stippi
Priority: normal Milestone: R2
Component: User Interface Version:
Keywords: Cc:
Blocked By: Blocking:
Platform: All


At the moment, one can pass a 'text' (const char*) argument to set the text-label of a BButton. Would it be possible to pass a BShape argument to a BButton object in order to create a button with a 'picture' instead of a text label?

I have seen how the mediaplayer solves this (for its 'transport' play/pause/stop buttons), where it overrides the BButton 's methods (especially the Draw() method) in order to achieve this.

In this possible solution, I imagine, there would be a SetShape(BShape* shape) method (corresponding to the SetLabel(const char* label) method of the BButton class.

Would something like that be programmatically possible, especially with regards to Haiku's LayoutManager? I imagine that if it used 'overloading', this solution would not break any previous BeOS or Haiku code.

Change History (1)

comment:1 by pulkomandy, 6 years ago

We already extended BButton with a SetIcon method to use a BBitmap icon, which can be used for this.

Another alternative in some cases is to use nuicode symbols (there are some at least for play/pause/etc, used in Sounds preferences for example).

Finally, when this isn't enough there is also the BPictureButton class, which can use a set of BPictures for drawing the button in various states, allowing complete look customization.

I think restricting to a BShape is not a good idea (unlike BPicture it only allows a single shape and a single color to be used). So, it's better to use the BPictureButton with a BPicture to draw anything you need. You can combine this with BControlLook to draw a standard button frame in your BPictures.

Note: See TracTickets for help on using tickets.