Skip to content

Commit fd3f326

Browse files
committed
More tweaks to audio widgets
1 parent ca594f2 commit fd3f326

File tree

26 files changed

+1406
-147
lines changed

26 files changed

+1406
-147
lines changed

examples/graphics/source/examples/Audio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class AudioExample
356356
// Add harmonic control sliders (4x4 grid)
357357
for (int i = 0; i < totalRows * totalColumns; ++i)
358358
{
359-
auto slider = sliders.add (std::make_unique<yup::Slider> (yup::String (i)));
359+
auto slider = sliders.add (std::make_unique<yup::Slider> (yup::Slider::RotaryVerticalDrag));
360360

361361
// Configure slider range and default value
362362
slider->setRange ({ 0.0f, 1.0f });
@@ -401,7 +401,7 @@ class AudioExample
401401
addAndMakeVisible (*clearButton);
402402

403403
// Add volume control
404-
volumeSlider = std::make_unique<yup::Slider> ("Volume");
404+
volumeSlider = std::make_unique<yup::Slider> (yup::Slider::LinearHorizontal, "Volume");
405405

406406
// Configure slider range and default value
407407
volumeSlider->setRange ({ 0.0f, 1.0f });

examples/graphics/source/examples/LayoutFonts.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LayoutFontsExample : public yup::Component
2828
public:
2929
LayoutFontsExample()
3030
: Component ("LayoutFontsExample")
31-
, font (yup::ApplicationTheme::getGlobalTheme()->getDefaultFont())
31+
, font (yup::ApplicationTheme::getGlobalTheme()->getDefaultFont().withHeight (16.0f))
3232
{
3333
}
3434

@@ -126,7 +126,7 @@ class LayoutFontsExample : public yup::Component
126126
modifier.setWrap (wrap);
127127

128128
modifier.clear();
129-
modifier.appendText (text, nullptr, font.getFont(), fontSize);
129+
modifier.appendText (text, nullptr, font.withHeight (fontSize));
130130
}
131131
};
132132

examples/graphics/source/examples/Paths.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class PathsExample : public yup::Component
8181
auto modifier = text.startUpdate();
8282
modifier.setMaxSize (area.getSize());
8383
modifier.setHorizontalAlign (yup::StyledText::center);
84-
modifier.appendText (title, yup::ApplicationTheme::getGlobalTheme()->getDefaultFont(), 12.0f);
84+
modifier.appendText (title, yup::ApplicationTheme::getGlobalTheme()->getDefaultFont().withHeight (12.0f));
8585
}
8686

8787
g.setFillColor (yup::Colors::white);

examples/graphics/source/examples/PopupMenu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class PopupMenuDemo : public yup::Component
7272
auto styledText = yup::StyledText();
7373
{
7474
auto modifier = styledText.startUpdate();
75-
modifier.appendText ("PopupMenu Features: Placement, Submenus, Scrolling", yup::ApplicationTheme::getGlobalTheme()->getDefaultFont());
75+
modifier.appendText ("PopupMenu Features: Placement, Submenus, Scrolling", yup::ApplicationTheme::getGlobalTheme()->getDefaultFont().withHeight (16.0f));
7676
}
7777

7878
g.setFillColor (yup::Color (0xffffffff));
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2025 - [email protected]
6+
7+
YUP is an open source library subject to open-source licensing.
8+
9+
The code included in this file is provided under the terms of the ISC license
10+
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
11+
to use, copy, modify, and/or distribute this software for any purpose with or
12+
without fee is hereby granted provided that the above copyright notice and
13+
this permission notice appear in all copies.
14+
15+
YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
16+
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
17+
DISCLAIMED.
18+
19+
==============================================================================
20+
*/
21+
22+
#pragma once
23+
24+
class SliderDemo : public yup::Component
25+
{
26+
public:
27+
SliderDemo()
28+
: Component ("SliderDemo")
29+
{
30+
setupSliders();
31+
setupLabels();
32+
}
33+
34+
private:
35+
void setupSliders()
36+
{
37+
// Horizontal Linear Slider
38+
horizontalSlider = std::make_unique<yup::Slider>(yup::Slider::LinearHorizontal);
39+
horizontalSlider->setRange(0.0, 100.0);
40+
horizontalSlider->setValue(50.0);
41+
horizontalSlider->onValueChanged = [this](double value) {
42+
horizontalLabel->setText("Horizontal: " + yup::String(value, 1), yup::dontSendNotification);
43+
};
44+
addAndMakeVisible(horizontalSlider.get());
45+
46+
// Vertical Linear Slider
47+
verticalSlider = std::make_unique<yup::Slider>(yup::Slider::LinearVertical);
48+
verticalSlider->setRange(0.0, 100.0);
49+
verticalSlider->setValue(30.0);
50+
verticalSlider->onValueChanged = [this](double value) {
51+
verticalLabel->setText("Vertical: " + yup::String(value, 1), yup::dontSendNotification);
52+
};
53+
addAndMakeVisible(verticalSlider.get());
54+
55+
// Rotary Slider (Horizontal Drag)
56+
rotarySlider = std::make_unique<yup::Slider>(yup::Slider::RotaryHorizontalDrag);
57+
rotarySlider->setRange(0.0, 100.0);
58+
rotarySlider->setValue(70.0);
59+
rotarySlider->onValueChanged = [this](double value) {
60+
rotaryLabel->setText("Rotary: " + yup::String(value, 1), yup::dontSendNotification);
61+
};
62+
addAndMakeVisible(rotarySlider.get());
63+
64+
// Bar Horizontal Slider
65+
barHorizontalSlider = std::make_unique<yup::Slider>(yup::Slider::LinearBarHorizontal);
66+
barHorizontalSlider->setRange(0.0, 100.0);
67+
barHorizontalSlider->setValue(75.0);
68+
barHorizontalSlider->onValueChanged = [this](double value) {
69+
barHorizontalLabel->setText("Bar H: " + yup::String(value, 0) + "%", yup::dontSendNotification);
70+
};
71+
addAndMakeVisible(barHorizontalSlider.get());
72+
73+
// Bar Vertical Slider
74+
barVerticalSlider = std::make_unique<yup::Slider>(yup::Slider::LinearBarVertical);
75+
barVerticalSlider->setRange(0.0, 10.0);
76+
barVerticalSlider->setValue(6.0);
77+
barVerticalSlider->onValueChanged = [this](double value) {
78+
barVerticalLabel->setText("Bar V: " + yup::String(value, 1), yup::dontSendNotification);
79+
};
80+
addAndMakeVisible(barVerticalSlider.get());
81+
82+
// Two Value Horizontal Slider
83+
twoValueSlider = std::make_unique<yup::Slider>(yup::Slider::TwoValueHorizontal);
84+
twoValueSlider->setRange(0.0, 100.0);
85+
twoValueSlider->setMinValue(25.0);
86+
twoValueSlider->setMaxValue(75.0);
87+
twoValueSlider->onValueChanged = [this](double) {
88+
twoValueLabel->setText("Range: " + yup::String(twoValueSlider->getMinValue(), 0) +
89+
"-" + yup::String(twoValueSlider->getMaxValue(), 0), yup::dontSendNotification);
90+
};
91+
addAndMakeVisible(twoValueSlider.get());
92+
}
93+
94+
void setupLabels()
95+
{
96+
// Title
97+
titleLabel = std::make_unique<yup::Label>("title");
98+
titleLabel->setText("YUP Slider Demo", yup::dontSendNotification);
99+
addAndMakeVisible(titleLabel.get());
100+
101+
// Value labels
102+
horizontalLabel = std::make_unique<yup::Label>("value1");
103+
horizontalLabel->setText("Horizontal: 50.0", yup::dontSendNotification);
104+
addAndMakeVisible(horizontalLabel.get());
105+
106+
verticalLabel = std::make_unique<yup::Label>("value2");
107+
verticalLabel->setText("Vertical: 30.0", yup::dontSendNotification);
108+
addAndMakeVisible(verticalLabel.get());
109+
110+
rotaryLabel = std::make_unique<yup::Label>("value3");
111+
rotaryLabel->setText("Rotary: 70.0", yup::dontSendNotification);
112+
addAndMakeVisible(rotaryLabel.get());
113+
114+
barHorizontalLabel = std::make_unique<yup::Label>("value4");
115+
barHorizontalLabel->setText("Bar H: 75%", yup::dontSendNotification);
116+
addAndMakeVisible(barHorizontalLabel.get());
117+
118+
barVerticalLabel = std::make_unique<yup::Label>("value5");
119+
barVerticalLabel->setText("Bar V: 6.0", yup::dontSendNotification);
120+
addAndMakeVisible(barVerticalLabel.get());
121+
122+
twoValueLabel = std::make_unique<yup::Label>("value6");
123+
twoValueLabel->setText("Range: 25-75", yup::dontSendNotification);
124+
addAndMakeVisible(twoValueLabel.get());
125+
}
126+
127+
void resized() override
128+
{
129+
auto bounds = getLocalBounds();
130+
auto margin = 20;
131+
auto sliderHeight = 60;
132+
auto labelHeight = 25;
133+
auto spacing = 10;
134+
135+
int y = margin;
136+
137+
// Title
138+
titleLabel->setBounds(yup::Rectangle<float>(
139+
static_cast<float>(margin),
140+
static_cast<float>(y),
141+
static_cast<float>(bounds.getWidth() - 2 * margin),
142+
30.0f));
143+
y += 40;
144+
145+
// Layout in a 2x3 grid
146+
auto sliderWidth = (bounds.getWidth() - 3 * margin) / 2;
147+
auto columnHeight = sliderHeight + labelHeight + spacing;
148+
149+
// Left column
150+
horizontalSlider->setBounds(yup::Rectangle<float>(
151+
static_cast<float>(margin),
152+
static_cast<float>(y),
153+
static_cast<float>(sliderWidth),
154+
static_cast<float>(sliderHeight)));
155+
horizontalLabel->setBounds(yup::Rectangle<float>(
156+
static_cast<float>(margin),
157+
static_cast<float>(y + sliderHeight + 5),
158+
static_cast<float>(sliderWidth),
159+
static_cast<float>(labelHeight)));
160+
161+
barHorizontalSlider->setBounds(yup::Rectangle<float>(
162+
static_cast<float>(margin),
163+
static_cast<float>(y + columnHeight),
164+
static_cast<float>(sliderWidth),
165+
static_cast<float>(sliderHeight)));
166+
barHorizontalLabel->setBounds(yup::Rectangle<float>(
167+
static_cast<float>(margin),
168+
static_cast<float>(y + columnHeight + sliderHeight + 5),
169+
static_cast<float>(sliderWidth),
170+
static_cast<float>(labelHeight)));
171+
172+
twoValueSlider->setBounds(yup::Rectangle<float>(
173+
static_cast<float>(margin),
174+
static_cast<float>(y + 2 * columnHeight),
175+
static_cast<float>(sliderWidth),
176+
static_cast<float>(sliderHeight)));
177+
twoValueLabel->setBounds(yup::Rectangle<float>(
178+
static_cast<float>(margin),
179+
static_cast<float>(y + 2 * columnHeight + sliderHeight + 5),
180+
static_cast<float>(sliderWidth),
181+
static_cast<float>(labelHeight)));
182+
183+
// Right column
184+
auto rightX = margin + sliderWidth + margin;
185+
186+
verticalSlider->setBounds(yup::Rectangle<float>(
187+
static_cast<float>(rightX),
188+
static_cast<float>(y),
189+
80.0f,
190+
static_cast<float>(columnHeight)));
191+
verticalLabel->setBounds(yup::Rectangle<float>(
192+
static_cast<float>(rightX + 90),
193+
static_cast<float>(y),
194+
static_cast<float>(sliderWidth - 90),
195+
static_cast<float>(labelHeight)));
196+
197+
rotarySlider->setBounds(yup::Rectangle<float>(
198+
static_cast<float>(rightX),
199+
static_cast<float>(y + columnHeight),
200+
80.0f,
201+
80.0f));
202+
rotaryLabel->setBounds(yup::Rectangle<float>(
203+
static_cast<float>(rightX + 90),
204+
static_cast<float>(y + columnHeight),
205+
static_cast<float>(sliderWidth - 90),
206+
static_cast<float>(labelHeight)));
207+
208+
barVerticalSlider->setBounds(yup::Rectangle<float>(
209+
static_cast<float>(rightX),
210+
static_cast<float>(y + 2 * columnHeight),
211+
60.0f,
212+
static_cast<float>(columnHeight)));
213+
barVerticalLabel->setBounds(yup::Rectangle<float>(
214+
static_cast<float>(rightX + 70),
215+
static_cast<float>(y + 2 * columnHeight),
216+
static_cast<float>(sliderWidth - 70),
217+
static_cast<float>(labelHeight)));
218+
}
219+
220+
void paint(yup::Graphics& g) override
221+
{
222+
g.setFillColor(yup::Colors::dimgray);
223+
g.fillAll();
224+
225+
// Draw section dividers
226+
g.setStrokeColor(yup::Colors::gray.withAlpha(0.3f));
227+
g.setStrokeWidth(1.0f);
228+
229+
auto bounds = getLocalBounds();
230+
auto margin = 20;
231+
232+
// Horizontal line under title
233+
g.strokeLine(static_cast<float>(margin), 70.0f, static_cast<float>(bounds.getWidth() - margin), 70.0f);
234+
235+
// Vertical line separating columns
236+
auto centerX = bounds.getWidth() / 2;
237+
g.strokeLine(static_cast<float>(centerX), 80.0f, static_cast<float>(centerX), static_cast<float>(bounds.getHeight() - margin));
238+
}
239+
240+
private:
241+
// Title
242+
std::unique_ptr<yup::Label> titleLabel;
243+
244+
// Sliders
245+
std::unique_ptr<yup::Slider> horizontalSlider;
246+
std::unique_ptr<yup::Slider> verticalSlider;
247+
std::unique_ptr<yup::Slider> rotarySlider;
248+
std::unique_ptr<yup::Slider> barHorizontalSlider;
249+
std::unique_ptr<yup::Slider> barVerticalSlider;
250+
std::unique_ptr<yup::Slider> twoValueSlider;
251+
252+
// Labels
253+
std::unique_ptr<yup::Label> horizontalLabel;
254+
std::unique_ptr<yup::Label> verticalLabel;
255+
std::unique_ptr<yup::Label> rotaryLabel;
256+
std::unique_ptr<yup::Label> barHorizontalLabel;
257+
std::unique_ptr<yup::Label> barVerticalLabel;
258+
std::unique_ptr<yup::Label> twoValueLabel;
259+
260+
YUP_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SliderDemo)
261+
};

examples/graphics/source/examples/VariableFonts.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class VariableFontsExample : public yup::Component
5959
label->setFont (font);
6060
addAndMakeVisible (label);
6161

62-
auto slider = sliders.add (std::make_unique<yup::Slider> (axisInfo->tagName));
62+
auto slider = sliders.add (std::make_unique<yup::Slider> (yup::Slider::Rotary, axisInfo->tagName));
6363
slider->setDefaultValue (axisInfo->defaultValue);
6464
slider->setRange ({ axisInfo->minimumValue, axisInfo->maximumValue });
6565
slider->setValue (axisInfo->defaultValue);
@@ -92,7 +92,7 @@ class VariableFontsExample : public yup::Component
9292
modifier.setOverflow (yup::StyledText::visible);
9393
modifier.setWrap (yup::StyledText::wrap);
9494
modifier.clear();
95-
modifier.appendText (text, font.getFont(), fontSize);
95+
modifier.appendText (text, font.withHeight (fontSize));
9696
}
9797

9898
bounds = bounds.reduced (10);
@@ -164,7 +164,7 @@ class VariableFontsExample : public yup::Component
164164
label->setFont (font);
165165
addAndMakeVisible (label);
166166

167-
auto slider = sliders.add (std::make_unique<yup::Slider> (name));
167+
auto slider = sliders.add (std::make_unique<yup::Slider> (yup::Slider::Rotary, name));
168168
slider->setDefaultValue (defaultValue);
169169
slider->setRange ({ minValue, maxValue });
170170
slider->setValue (defaultValue);

examples/graphics/source/examples/Widgets.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ class WidgetsDemo : public yup::Component
102102
*/
103103

104104
// Slider
105-
slider = std::make_unique<yup::Slider> ("slider");
106-
slider->setRange (yup::Range<float> (0.0f, 100.0f));
105+
slider = std::make_unique<yup::Slider> (yup::Slider::Rotary, "slider");
106+
slider->setRange (yup::Range<double> (0.0, 100.0));
107107
slider->setValue (50.0);
108108
slider->onValueChanged = [this] (float value)
109109
{

examples/graphics/source/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "examples/OpaqueDemo.h"
4545
#include "examples/Paths.h"
4646
#include "examples/PopupMenu.h"
47+
#include "examples/SliderDemo.h"
4748
#include "examples/TextEditor.h"
4849
#include "examples/Svg.h"
4950
#include "examples/VariableFonts.h"
@@ -109,6 +110,7 @@ class CustomWindow
109110
#endif
110111
registerDemo<PopupMenuDemo> ("Popup Menu", counter++);
111112
registerDemo<FileChooserDemo> ("File Chooser", counter++);
113+
registerDemo<SliderDemo> ("Sliders", counter++);
112114
registerDemo<WidgetsDemo> ("Widgets", counter++);
113115
registerDemo<ArtboardDemo> ("Artboard", counter++, [] (auto& artboard)
114116
{

examples/plugin/source/ExampleEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ExampleEditor::ExampleEditor (ExamplePlugin& processor)
3535
: audioProcessor (processor)
3636
, gainParameter (audioProcessor.getParameters()[0])
3737
{
38-
x = std::make_unique<ExampleSlider> ("Slider");
38+
x = std::make_unique<ExampleSlider> ();
3939
x->setMouseCursor (yup::MouseCursor::Hand);
4040
x->setValue (gainParameter->getValue());
4141
x->onDragStart = [this] (const yup::MouseEvent&)

0 commit comments

Comments
 (0)