Krotos Modules 3
Loading...
Searching...
No Matches
DragComponent.cpp
Go to the documentation of this file.
1#include "DragComponent.h"
2
3namespace krotos
4{
5 DragComponent::DragComponent(const String& labelText)
6 : m_labelText(labelText), m_textWidth(calculateTextWidth(labelText))
7 {
9 Drawable::createFromImageData(KrotosBinaryData::Move_Icon_svg, KrotosBinaryData::Move_Icon_svgSize);
10
12 setSize(width, Layout::height);
13 }
14
15 void DragComponent::paint(Graphics& g)
16 {
17 // Draw the rounded rectangle
18 g.setColour(m_colours.backgroundColour);
19 g.fillRoundedRectangle(getLocalBounds().toFloat(), Layout::borderRadius);
20 g.setColour(m_colours.borderColour);
21 g.drawRoundedRectangle(getLocalBounds().toFloat(), Layout::borderRadius, Layout::borderThickness);
22
23 // Draw the icon image
25 {
26 m_dragIconImage->drawWithin(
28 RectanglePlacement::centred, 1.0f);
29 }
30
31 // Draw the text
32 g.setColour(m_colours.textColour);
33 g.setFont(Font("Open Sans", Layout::fontSize, Font::bold));
35 Justification::centred, true);
36 }
37
38 int DragComponent::calculateTextWidth(const String& text) const
39 {
40 Font font("Open Sans", Layout::fontSize, Font::bold);
41 font.setExtraKerningFactor(Layout::kerningFactor);
42 return font.getStringWidth(text);
43 }
44
45} // namespace krotos
String m_labelText
Definition DragComponent.h:54
void paint(Graphics &g) override
Definition DragComponent.cpp:15
std::unique_ptr< Drawable > m_dragIconImage
Definition DragComponent.h:53
int m_textWidth
Definition DragComponent.h:52
DragComponent(const String &labelText)
Definition DragComponent.cpp:5
struct krotos::DragComponent::ColourDefinitions m_colours
int calculateTextWidth(const String &text) const
Definition DragComponent.cpp:38
Definition AirAbsorptionFilter.cpp:2
const Colour textColour
Definition DragComponent.h:31
const Colour borderColour
Definition DragComponent.h:30
const Colour backgroundColour
Definition DragComponent.h:29
static constexpr int iconY
Definition DragComponent.h:40
static constexpr float kerningFactor
Definition DragComponent.h:49
static constexpr float borderThickness
Definition DragComponent.h:44
static constexpr int height
Definition DragComponent.h:38
static constexpr int textHeight
Definition DragComponent.h:48
static constexpr int iconWidth
Definition DragComponent.h:41
static constexpr int iconX
Definition DragComponent.h:39
static constexpr int textY
Definition DragComponent.h:47
static constexpr int textX
Definition DragComponent.h:46
static constexpr float borderRadius
Definition DragComponent.h:43
static constexpr int iconHeight
Definition DragComponent.h:42
static constexpr float fontSize
Definition DragComponent.h:45