I am attempting to create an image button for a DJ deck that works to play the mp3 file loaded in.
The text button (not the image button) works perfectly but how do I can change it to a image button for the same function?
Thank you to the members of JUCE for your patience with us University of London Goldsmiths comp sci students.
Use the ImageButton and I think it will be fine. Optionally, you can provide an image to your custom LookAndFeel (of the button) and draw it at wherever you like. For example,
#include <juce_gui_basics/juce_gui_basics.h>
#include "../../interface_definitions.hpp"
namespace zlInterface {
class CompactButtonLookAndFeel : public juce::LookAndFeel_V4 {
public:
explicit CompactButtonLookAndFeel(UIBase &base) : uiBase(base) {
}
void drawToggleButton(juce::Graphics &g, juce::ToggleButton &button, bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown) override {
juce::ignoreUnused(shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
auto bounds = button.getLocalBounds().toFloat();
if (withShadow.load()) {
bounds = uiBase.drawShadowEllipse(g, bounds, uiBase.getFontSize() * 0.4f, {});
bounds = uiBase.drawInnerShadowEllipse(g, bounds, uiBase.getFontSize() * 0.15f, {.flip = true});
} else {
bounds = uiBase.getShadowEllipseArea(bounds, uiBase.getFontSize() * 0.3f, {});
g.setColour(uiBase.getBackgroundColor());
to modify the looks and feel… do we like put this code in a new header file or cpp file? Can you show a example of Image button?
Thank you!
zsliu98
January 27, 2024, 12:04am
4
The following documentation of ImageButton is pretty clear. You can construct an ImageButton and provide an(or several) image(s) to it with setImages. Which part do you not understand?
https://docs.juce.com/master/classImageButton.html
Check the ArrowButton too JUCE: ArrowButton Class Reference which you can inspire yourself for the implementation