Skip to content

Commit 61d9bb3

Browse files
authored
Add a juce Text Editor subclass with style sheet (#155)
Basically keep the class the same but brige our style colors to the look and feel
1 parent 6db614a commit 61d9bb3

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ add_library(${PROJECT_NAME} STATIC
169169
src/sst/jucegui/components/NamedPanelDivider.cpp
170170
src/sst/jucegui/components/SevenSegmentControl.cpp
171171
src/sst/jucegui/components/TabularizedTreeViewer.cpp
172+
src/sst/jucegui/components/TextEditor.cpp
172173
src/sst/jucegui/components/TextPushButton.cpp
173174
src/sst/jucegui/components/ToggleButton.cpp
174175
src/sst/jucegui/components/ToggleButtonRadioGroup.cpp
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* sst-jucegui - an open source library of juce widgets
3+
* built by Surge Synth Team.
4+
*
5+
* Copyright 2023-2024, various authors, as described in the GitHub
6+
* transaction log.
7+
*
8+
* sst-jucegui is released under the MIT license, as described
9+
* by "LICENSE.md" in this repository. This means you may use this
10+
* in commercial software if you are a JUCE Licensee. If you use JUCE
11+
* in the open source / GPL3 context, your combined work must be
12+
* released under GPL3.
13+
*
14+
* All source in sst-jucegui available at
15+
* https://github.com/surge-synthesizer/sst-jucegui
16+
*/
17+
18+
#ifndef INCLUDE_SST_JUCEGUI_COMPONENTS_TEXTEDITOR_H
19+
#define INCLUDE_SST_JUCEGUI_COMPONENTS_TEXTEDITOR_H
20+
21+
#include <juce_gui_basics/juce_gui_basics.h>
22+
#include <string>
23+
#include <sst/jucegui/style/StyleAndSettingsConsumer.h>
24+
#include <sst/jucegui/style/StyleSheet.h>
25+
#include "BaseStyles.h"
26+
27+
namespace sst::jucegui::components
28+
{
29+
struct TextEditor : public juce::TextEditor,
30+
public style::StyleConsumer,
31+
public style::SettingsConsumer
32+
{
33+
struct Styles : base_styles::Outlined, base_styles::ValueGutter, base_styles::BaseLabel
34+
{
35+
using sclass = style::StyleSheet::Class;
36+
using sprop = style::StyleSheet::Property;
37+
static constexpr sclass styleClass{"texteditor"};
38+
39+
static void initialize()
40+
{
41+
style::StyleSheet::addClass(styleClass)
42+
.withBaseClass(base_styles::Outlined::styleClass)
43+
.withBaseClass(base_styles::BaseLabel::styleClass)
44+
.withBaseClass(base_styles::ValueGutter::styleClass);
45+
}
46+
};
47+
48+
TextEditor();
49+
50+
void setAllText(const std::string &s);
51+
52+
void onStyleChanged() override;
53+
54+
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TextEditor)
55+
};
56+
} // namespace sst::jucegui::components
57+
58+
#endif // SST_JUCEGUI_LABEL_H
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* sst-jucegui - an open source library of juce widgets
3+
* built by Surge Synth Team.
4+
*
5+
* Copyright 2023-2024, various authors, as described in the GitHub
6+
* transaction log.
7+
*
8+
* sst-jucegui is released under the MIT license, as described
9+
* by "LICENSE.md" in this repository. This means you may use this
10+
* in commercial software if you are a JUCE Licensee. If you use JUCE
11+
* in the open source / GPL3 context, your combined work must be
12+
* released under GPL3.
13+
*
14+
* All source in sst-jucegui available at
15+
* https://github.com/surge-synthesizer/sst-jucegui
16+
*/
17+
18+
#include "sst/jucegui/components/TextEditor.h"
19+
20+
namespace sst::jucegui::components
21+
{
22+
TextEditor::TextEditor() : style::StyleConsumer(Styles::styleClass) { setAccessible(true); }
23+
24+
void TextEditor::setAllText(const std::string &text)
25+
{
26+
setText(text, juce::NotificationType::dontSendNotification);
27+
if (style())
28+
{
29+
applyFontToAllText(style()->getFont(Styles::styleClass, Styles::labelfont));
30+
applyColourToAllText(style()->getColour(Styles::styleClass, Styles::labelcolor));
31+
}
32+
}
33+
34+
void TextEditor::onStyleChanged()
35+
{
36+
setColour(juce::TextEditor::outlineColourId, getColour(Styles::outline));
37+
setColour(juce::TextEditor::focusedOutlineColourId, getColour(Styles::brightoutline));
38+
setColour(juce::TextEditor::textColourId, getColour(Styles::labelcolor));
39+
40+
setColour(juce::TextEditor::ColourIds::backgroundColourId, getColour(Styles::gutter));
41+
setColour(juce::TextEditor::ColourIds::highlightedTextColourId,
42+
getColour(Styles::labelcolor_hover));
43+
setFont(style()->getFont(Styles::styleClass, Styles::labelfont));
44+
setIndents(3, 3);
45+
setJustification(juce::Justification::topLeft);
46+
47+
applyFontToAllText(style()->getFont(Styles::styleClass, Styles::labelfont));
48+
applyColourToAllText(style()->getColour(Styles::styleClass, Styles::labelcolor));
49+
setText(getText(), juce::NotificationType::dontSendNotification);
50+
resized();
51+
}
52+
53+
} // namespace sst::jucegui::components

src/sst/jucegui/style/StyleSheet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <sst/jucegui/components/TabularizedTreeViewer.h>
2929
#include <sst/jucegui/components/MenuButton.h>
3030
#include <sst/jucegui/components/TextPushButton.h>
31+
#include <sst/jucegui/components/TextEditor.h>
3132
#include <sst/jucegui/components/ToggleButton.h>
3233
#include <sst/jucegui/components/NamedPanel.h>
3334
#include <sst/jucegui/components/NamedPanelDivider.h>
@@ -647,6 +648,7 @@ void StyleSheet::initializeStyleSheets(std::function<void()> userClassInitialize
647648
n::Viewport::Styles::initialize();
648649
n::TabbedComponent::Styles::initialize();
649650
n::TypeInOverlay::Styles::initialize();
651+
n::TextEditor::Styles::initialize();
650652

651653
n::TabularizedTreeViewer::Styles::initialize();
652654
}

0 commit comments

Comments
 (0)