Krotos Modules 3
Loading...
Searching...
No Matches
topBarComponent.cpp
Go to the documentation of this file.
1namespace krotos
2{
3 TopBarComponent::TopBarComponent(bool isSelectable, const String& parentID)
4 {
5 setComponentID("TopBar");
6 setAlwaysOnTop(true);
7 m_isSelectable = isSelectable;
8
9 // Select Button
11 {
12 addAndMakeVisible(m_selectButton);
13 m_selectButton.setColour(TextButton::ColourIds::buttonColourId, juce::Colours::whitesmoke);
14 m_selectButton.onClick = [&]() {
15 if (onSelect)
16 onSelect(parentID);
17 };
18 }
19
20 // Delete Button
21 addAndMakeVisible(m_deleteButton);
22 m_deleteButton.setButtonText("X");
23 m_deleteButton.onClick = [&]() {
24 if (onDelete)
25 onDelete(parentID);
26 };
27
28 // Minimise Button
29 addAndMakeVisible(m_minimiseButton);
30 m_minimiseButton.setButtonText("-");
31 m_minimiseButton.setClickingTogglesState(true);
32 m_minimiseButton.onClick = [=]() {
33 if (onMinimise)
34 {
35 if (m_minimiseButton.getToggleState() == false)
36 {
37 onMinimise(false);
38 }
39
40 else
41 onMinimise(true);
42 }
43 };
44
45 // Kwidget Label
46 m_label.setText(parentID, NotificationType::dontSendNotification);
47 m_label.setInterceptsMouseClicks(false, false);
48 addAndMakeVisible(m_label);
49 }
50
52 {
53 m_currentBounds = getBounds();
54
55 auto deleteBounds =
56 Rectangle<int>(m_currentBounds.getRight() - (m_buttonSize + m_padding),
58 .reduced(static_cast<int>(m_borderThickness));
59 m_deleteButton.setBounds(deleteBounds);
60
61 auto minimiseBounds =
62 Rectangle<int>(m_currentBounds.getRight() - 2 * (m_buttonSize + m_padding),
64 .reduced(static_cast<int>(m_borderThickness));
65 m_minimiseButton.setBounds(minimiseBounds);
66
67 auto selectBounds =
68 Rectangle<int>(m_currentBounds.getCentreX(),
70 .reduced(static_cast<int>(m_borderThickness));
71 m_selectButton.setBounds(selectBounds);
72
73 auto labelBounds = Rectangle<int>(m_currentBounds.getX() + m_padding,
74 m_currentBounds.getY() + static_cast<int>(m_borderThickness),
76 .reduced(static_cast<int>(m_borderThickness));
77 m_label.setBounds(labelBounds);
78 }
79
80 void TopBarComponent::paint(Graphics& g)
81 {
82 g.setColour(m_borderColour);
83 g.drawRoundedRectangle(getLocalBounds().reduced(3).toFloat(), m_topBarCornerSize, m_borderThickness);
84 }
85
86 void TopBarComponent::mouseDown(const MouseEvent& event) { getParentComponent()->mouseDown(event); }
87
88 void TopBarComponent::mouseDrag(const MouseEvent& event) { getParentComponent()->mouseDrag(event); }
89} // namespace krotos
const int m_padding
Definition topBarComponent.h:51
TopBarComponent(bool isSelectable, const String &parentID)
Definition topBarComponent.cpp:3
Label m_label
Definition topBarComponent.h:49
const int m_buttonSize
Definition topBarComponent.h:53
std::function< void(const String &)> onDelete
Definition topBarComponent.h:32
std::function< void(bool isMinimised)> onMinimise
Definition topBarComponent.h:37
TextButton m_deleteButton
Definition topBarComponent.h:40
void resized() override
Definition topBarComponent.cpp:51
const float m_borderThickness
Definition topBarComponent.h:52
std::function< void(const String &)> onSelect
Definition topBarComponent.h:27
void paint(Graphics &g) override
Definition topBarComponent.cpp:80
const float m_topBarCornerSize
Definition topBarComponent.h:55
TextButton m_selectButton
Definition topBarComponent.h:39
bool m_isSelectable
Definition topBarComponent.h:57
Rectangle< int > m_currentBounds
Definition topBarComponent.h:47
void mouseDrag(const MouseEvent &event) override
Definition topBarComponent.cpp:88
void mouseDown(const MouseEvent &event) override
Definition topBarComponent.cpp:86
TextButton m_minimiseButton
Definition topBarComponent.h:41
Colour m_borderColour
Definition topBarComponent.h:48
Definition AirAbsorptionFilter.cpp:2