Skip to content

Commit 722811d

Browse files
committed
More improvements
1 parent 075ff2d commit 722811d

File tree

6 files changed

+160
-54
lines changed

6 files changed

+160
-54
lines changed

examples/graphics/source/examples/Audio.h

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,56 @@ class Oscilloscope : public yup::Component
104104
{
105105
auto bounds = getLocalBounds();
106106

107-
g.setFillColor (0xff101010);
107+
auto backgroundColor = yup::Color (0xff101010);
108+
g.setFillColor (backgroundColor);
108109
g.fillAll();
109110

110-
g.setStrokeColor (0xff4b4bff);
111-
g.setStrokeWidth (1.0f);
112-
g.strokeRect (bounds);
113-
111+
auto lineColor = yup::Color (0xff4b4bff);
114112
if (renderData.empty())
115113
return;
116114

117115
float xSize = getWidth() / float (renderData.size());
116+
float centerY = getHeight() * 0.5f;
118117

118+
// Build the main waveform path
119119
path.clear();
120120
path.reserveSpace ((int) renderData.size());
121-
122121
path.moveTo (0.0f, (renderData[0] + 1.0f) * 0.5f * getHeight());
123122

124123
for (std::size_t i = 1; i < renderData.size(); ++i)
125124
path.lineTo (i * xSize, (renderData[i] + 1.0f) * 0.5f * getHeight());
126125

126+
// Outermost glow layer
127+
g.setStrokeColor (lineColor.withAlpha(0.1f));
128+
g.setStrokeWidth (12.0f);
129+
g.setStrokeCap (yup::StrokeCap::Round);
130+
g.setStrokeJoin (yup::StrokeJoin::Round);
131+
g.strokePath (path);
132+
133+
// Second glow layer
134+
g.setStrokeColor (lineColor.withAlpha(0.2f));
135+
g.setStrokeWidth (8.0f);
136+
g.strokePath (path);
137+
138+
// Third glow layer
139+
g.setStrokeColor (lineColor.withAlpha(0.4f));
140+
g.setStrokeWidth (5.0f);
141+
g.strokePath (path);
142+
143+
// Main stroke
144+
g.setStrokeColor (lineColor.withAlpha(0.8f));
145+
g.setStrokeWidth (2.5f);
146+
g.strokePath (path);
147+
148+
// Bright center line
149+
g.setStrokeColor (lineColor.brighter(0.3f));
127150
g.setStrokeWidth (1.0f);
128151
g.strokePath (path);
152+
153+
// Ultra-bright core
154+
g.setStrokeColor (yup::Colors::white.withAlpha(0.9f));
155+
g.setStrokeWidth (0.3f);
156+
g.strokePath (path);
129157
}
130158

131159
private:

examples/graphics/source/examples/TextEditor.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ class TextEditorDemo : public yup::Component
102102

103103
void paint (yup::Graphics& g) override
104104
{
105-
// Background
106-
g.setFillColor (yup::Colors::lightgray);
107-
g.fillAll();
108-
109105
// Header separator
110106
g.setStrokeColor (yup::Colors::darkgray);
111107
g.setStrokeWidth (2.0f);

examples/graphics/source/main.cpp

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,58 @@ class CustomWindow
7474
}
7575
*/
7676

77-
// Add the demos
78-
int demo = 4;
79-
80-
if (demo == 0)
8177
{
78+
auto button = std::make_unique<yup::TextButton> ("Audio");
79+
button->onClick = [this] { selectComponent (0); };
80+
addAndMakeVisible (button.get());
81+
buttons.add (std::move (button));
82+
8283
components.add (std::make_unique<AudioExample> (font));
83-
addAndMakeVisible (components.getLast());
84+
addChildComponent (components.getLast());
8485
}
8586

86-
if (demo == 1)
8787
{
88+
auto button = std::make_unique<yup::TextButton> ("Layout Fonts");
89+
button->onClick = [this] { selectComponent (1); };
90+
addAndMakeVisible (button.get());
91+
buttons.add (std::move (button));
92+
8893
components.add (std::make_unique<LayoutFontsExample> (font));
89-
addAndMakeVisible (components.getLast());
94+
addChildComponent (components.getLast());
9095
}
9196

92-
if (demo == 2)
9397
{
98+
auto button = std::make_unique<yup::TextButton> ("Variable Fonts");
99+
button->onClick = [this] { selectComponent (2); };
100+
addAndMakeVisible (button.get());
101+
buttons.add (std::move (button));
102+
94103
components.add (std::make_unique<VariableFontsExample> (font));
95-
addAndMakeVisible (components.getLast());
104+
addChildComponent (components.getLast());
96105
}
97106

98-
if (demo == 3)
99107
{
108+
auto button = std::make_unique<yup::TextButton> ("Paths");
109+
button->onClick = [this] { selectComponent (3); };
110+
addAndMakeVisible (button.get());
111+
buttons.add (std::move (button));
112+
100113
components.add (std::make_unique<PathsExample>());
101-
addAndMakeVisible (components.getLast());
114+
addChildComponent (components.getLast());
102115
}
103116

104-
if (demo == 4)
105117
{
118+
auto button = std::make_unique<yup::TextButton> ("Text Editor");
119+
button->onClick = [this] { selectComponent (4); };
120+
addAndMakeVisible (button.get());
121+
buttons.add (std::move (button));
122+
106123
components.add (std::make_unique<TextEditorDemo>());
107-
addAndMakeVisible (components.getLast());
124+
addChildComponent (components.getLast());
108125
}
109126

127+
selectComponent (0);
128+
110129
// Timer
111130
startTimerHz (10);
112131
}
@@ -117,8 +136,15 @@ class CustomWindow
117136

118137
void resized() override
119138
{
139+
auto bounds = getLocalBounds().reduced (5);
140+
auto buttonBounds = bounds.removeFromTop (30);
141+
142+
const auto buttonWidth = buttonBounds.getWidth() / buttons.size();
143+
for (auto& button : buttons)
144+
button->setBounds (buttonBounds.removeFromLeft (buttonWidth));
145+
120146
for (auto& component : components)
121-
component->setBounds (getLocalBounds());
147+
component->setBounds (bounds);
122148
}
123149

124150
void paint (yup::Graphics& g) override
@@ -176,6 +202,14 @@ class CustomWindow
176202
yup::YUPApplication::getInstance()->systemRequestedQuit();
177203
}
178204

205+
void selectComponent (int index)
206+
{
207+
for (auto& component : components)
208+
component->setVisible (false);
209+
210+
components[index]->setVisible (true);
211+
}
212+
179213
private:
180214
void updateWindowTitle()
181215
{
@@ -194,6 +228,7 @@ class CustomWindow
194228
setTitle (title);
195229
}
196230

231+
yup::OwnedArray<yup::TextButton> buttons;
197232
yup::OwnedArray<yup::Component> components;
198233

199234
yup::Font font;

modules/yup_gui/themes/theme_v1/yup_ThemeVersion1.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,23 @@ void paintTextEditor (Graphics& g, const ApplicationTheme& theme, const TextEdit
119119
// Draw background
120120
auto backgroundColor = t.findColor (TextEditor::Colors::backgroundColorId).value_or (Colors::white);
121121
g.setFillColor (backgroundColor);
122-
g.fillRoundedRect (bounds, cornerRadius);
122+
g.fillRoundedRect (bounds.reduced (1.0f), cornerRadius);
123123

124124
// Draw outline
125125
auto outlineColor = t.hasKeyboardFocus()
126-
? t.findColor (TextEditor::Colors::focusedOutlineColorId).value_or (Colors::blue)
126+
? t.findColor (TextEditor::Colors::focusedOutlineColorId).value_or (Colors::cornflowerblue)
127127
: t.findColor (TextEditor::Colors::outlineColorId).value_or (Colors::gray);
128128
g.setStrokeColor (outlineColor);
129129

130130
float strokeWidth = t.hasKeyboardFocus() ? 2.0f : 1.0f;
131131
g.setStrokeWidth (strokeWidth);
132132

133-
g.strokeRoundedRect (bounds.reduced (strokeWidth * 0.5f), cornerRadius);
133+
g.strokeRoundedRect (bounds.reduced (1.0f), cornerRadius);
134134

135135
// Draw selection background
136136
if (t.hasSelection())
137137
{
138-
auto selectionColor = t.findColor (TextEditor::Colors::selectionColorId).value_or (Colors::lightblue.withAlpha (0.7f));
138+
auto selectionColor = t.findColor (TextEditor::Colors::selectionColorId).value_or (Colors::cornflowerblue.withAlpha (0.5f));
139139
g.setFillColor (selectionColor);
140140

141141
// Get all selection rectangles for proper multiline selection rendering
@@ -177,13 +177,13 @@ void paintTextButton (Graphics& g, const ApplicationTheme& theme, const TextButt
177177

178178
if (b.isButtonDown())
179179
{
180-
backgroundColor = b.findColor (TextButton::Colors::backgroundPressedColorId).value_or (Colors::white);
181-
textColor = b.findColor (TextButton::Colors::textPressedColorId).value_or (Colors::darkgray);
180+
backgroundColor = b.findColor (TextButton::Colors::backgroundPressedColorId).value_or (Colors::gray);
181+
textColor = b.findColor (TextButton::Colors::textPressedColorId).value_or (Colors::dimgray);
182182
}
183183
else
184184
{
185-
backgroundColor = b.findColor (TextButton::Colors::backgroundColorId).value_or (Colors::lightgray);
186-
textColor = b.findColor (TextButton::Colors::textColorId).value_or (Colors::gray);
185+
backgroundColor = b.findColor (TextButton::Colors::backgroundColorId).value_or (Colors::gray);
186+
textColor = b.findColor (TextButton::Colors::textColorId).value_or (Colors::white);
187187
}
188188

189189
if (b.isButtonOver())
@@ -194,18 +194,18 @@ void paintTextButton (Graphics& g, const ApplicationTheme& theme, const TextButt
194194

195195
// Draw background with flat color (no gradient for modern flat design)
196196
g.setFillColor (backgroundColor);
197-
g.fillRoundedRect (bounds, cornerRadius);
197+
g.fillRoundedRect (bounds.reduced (1.0f), cornerRadius);
198198

199199
// Draw modern outline
200200
Color outlineColor = b.hasKeyboardFocus()
201-
? b.findColor (TextButton::Colors::outlineFocusedColorId).value_or (Colors::blue)
202-
: b.findColor (TextButton::Colors::outlineColorId).value_or (Colors::gray);
201+
? b.findColor (TextButton::Colors::outlineFocusedColorId).value_or (Colors::cornflowerblue)
202+
: b.findColor (TextButton::Colors::outlineColorId).value_or (Colors::dimgray);
203203
g.setStrokeColor (outlineColor);
204204

205205
float strokeWidth = b.hasKeyboardFocus() ? 2.0f : 1.0f;
206206
g.setStrokeWidth (strokeWidth);
207207

208-
g.strokeRoundedRect (bounds.reduced (strokeWidth * 0.5f), cornerRadius);
208+
g.strokeRoundedRect (bounds.reduced (1.0f), cornerRadius);
209209

210210
// Draw text
211211
g.setFillColor (textColor);

modules/yup_gui/widgets/yup_TextEditor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,15 @@ int TextEditor::getGlyphIndexAtPosition (const Point<float>& position) const
604604
auto relativePos = position - textBounds.getTopLeft() + scrollOffset;
605605

606606
// Use StyledText's positioning functionality
607-
return const_cast<StyledText&> (styledText).getGlyphIndexAtPosition (relativePos);
607+
return styledText.getGlyphIndexAtPosition (relativePos);
608608
}
609609

610610
//==============================================================================
611611

612612
Rectangle<float> TextEditor::getCaretBounds() const
613613
{
614614
auto textBounds = getTextBounds();
615-
auto caretBounds = const_cast<StyledText&> (styledText).getCaretBounds (caretPosition);
615+
auto caretBounds = styledText.getCaretBounds (caretPosition);
616616

617617
// Adjust bounds to be relative to the text editor's bounds with scroll offset applied
618618
return caretBounds.translated (textBounds.getTopLeft() - scrollOffset);

0 commit comments

Comments
 (0)