Gin
Loading...
Searching...
No Matches
SVGButton Class Reference

Button that displays an SVG graphic instead of or alongside text. More...

#include <gin_svgbutton.h>

Inheritance diagram for SVGButton:

Public Member Functions

 SVGButton (const juce::String &name, const juce::String &rawSVG_, int inset_=0)
void setColour (juce::Colour c)
void clearColour ()
std::optional< juce::Colour > getColour () const

Public Attributes

juce::String rawSVG
int inset = 0
std::optional< juce::Colour > colour

Detailed Description

Button that displays an SVG graphic instead of or alongside text.

SVGButton extends TextButton to support rendering SVG graphics. The SVG is stored as raw XML text and can be drawn by a custom LookAndFeel. The button provides an inset parameter to control padding around the SVG.

Note: The actual SVG rendering must be implemented in your LookAndFeel's drawButtonBackground() or drawButtonText() methods. This class only stores the SVG data and inset value.

Usage:

String svgXml = "<svg>...</svg>";
SVGButton button("IconButton", svgXml, 4); // 4 pixel inset
// In your LookAndFeel:
void drawButtonBackground(Graphics& g, Button& btn, ...) override
{
if (auto* svg = dynamic_cast<SVGButton*>(&btn))
{
auto drawable = Drawable::createFromSVG(*XmlDocument::parse(svg->rawSVG));
drawable->drawWithin(g, btn.getLocalBounds().reduced(svg->inset).toFloat(), ...);
}
}
SVGButton(const juce::String &name, const juce::String &rawSVG_, int inset_=0)
Definition gin_svgbutton.h:47
See also
juce::TextButton, juce::Drawable

Constructor & Destructor Documentation

◆ SVGButton()

SVGButton::SVGButton ( const juce::String & name,
const juce::String & rawSVG_,
int inset_ = 0 )

References inset, and rawSVG.

Referenced by SVGPluginButton::SVGPluginButton().

Member Function Documentation

◆ setColour()

void SVGButton::setColour ( juce::Colour c)

References colour.

◆ clearColour()

void SVGButton::clearColour ( )

References colour.

◆ getColour()

std::optional< juce::Colour > SVGButton::getColour ( ) const

References colour.

Member Data Documentation

◆ rawSVG

juce::String SVGButton::rawSVG

Referenced by SVGButton().

◆ inset

int SVGButton::inset = 0

Referenced by SVGButton().

◆ colour

std::optional<juce::Colour> SVGButton::colour

Referenced by clearColour(), getColour(), and setColour().


The documentation for this class was generated from the following file: