Skip to content

Commit 66ae3d7

Browse files
committed
More coverage
1 parent ca7acec commit 66ae3d7

6 files changed

Lines changed: 126 additions & 2 deletions

File tree

modules/yup_gui/buttons/yup_TextButton.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ void TextButton::setButtonText (StringRef newButtonText)
4848
{
4949
buttonText = newButtonText;
5050

51-
resized();
52-
repaint();
51+
updateTextLayout();
5352
}
5453
}
5554

@@ -64,6 +63,13 @@ void TextButton::paintButton (Graphics& g)
6463
//==============================================================================
6564

6665
void TextButton::resized()
66+
{
67+
updateTextLayout();
68+
}
69+
70+
//==============================================================================
71+
72+
void TextButton::updateTextLayout()
6773
{
6874
auto textBounds = getTextBounds();
6975
auto font = ApplicationTheme::getGlobalTheme()->getDefaultFont();
@@ -78,6 +84,8 @@ void TextButton::resized()
7884

7985
if (buttonText.isNotEmpty())
8086
modifier.appendText (buttonText, font.withHeight (getHeight() * 0.35f));
87+
88+
repaint();
8189
}
8290

8391
//==============================================================================

modules/yup_gui/buttons/yup_TextButton.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class YUP_API TextButton : public Button
5959
StyledText& getStyledText() const noexcept { return const_cast<StyledText&> (styledText); }
6060

6161
private:
62+
void updateTextLayout();
63+
6264
String buttonText;
6365
StyledText styledText;
6466
};

tests/yup_audio_gui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
#include "yup_audio_gui/yup_AudioThumbnail.cpp"
2525
#include "yup_audio_gui/yup_AudioViewComponent.cpp"
2626
#include "yup_audio_gui/yup_CartesianPlane.cpp"
27+
#include "yup_audio_gui/yup_KMeterComponent.cpp"
2728
#include "yup_audio_gui/yup_SpectrumAnalyzerComponent.cpp"

tests/yup_audio_gui/KMeterComponent.cpp renamed to tests/yup_audio_gui/yup_KMeterComponent.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
using namespace yup;
2727

28+
namespace yup
29+
{
30+
extern std::unique_ptr<yup::GraphicsContext> yup_constructHeadlessGraphicsContext (yup::GraphicsContext::Options);
31+
} // namespace yup
32+
2833
//==============================================================================
2934
TEST (KMeterComponentTests, DefaultsAreConfigured)
3035
{
@@ -57,3 +62,18 @@ TEST (KMeterComponentTests, SettersUpdateState)
5762
EXPECT_DOUBLE_EQ (1.5, meterState.getPeakHoldTime());
5863
EXPECT_EQ (KMeterState::OverCounterMode::total, meter.getOverCounterMode());
5964
}
65+
66+
TEST (KMeterComponentTests, PaintWithThemeDoesNotCrash)
67+
{
68+
KMeterState meterState (48000.0, 2);
69+
KMeterComponent meter (meterState, 0);
70+
meter.setBounds (0.0f, 0.0f, 60.0f, 240.0f);
71+
72+
auto context = yup_constructHeadlessGraphicsContext ({});
73+
auto renderer = context->makeRenderer (120, 240);
74+
Graphics g (*context, *renderer);
75+
76+
meter.paint (g);
77+
78+
EXPECT_TRUE (true);
79+
}

tests/yup_gui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@
3232
#include "yup_gui/yup_SwitchButton.cpp"
3333
#include "yup_gui/yup_TextButton.cpp"
3434
#include "yup_gui/yup_TextEditor.cpp"
35+
#include "yup_gui/yup_ThemeVersion1.cpp"
3536
#include "yup_gui/yup_ToggleButton.cpp"
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2026 - kunitoki@gmail.com
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+
#include <yup_audio_gui/yup_audio_gui.h>
23+
24+
#include <gtest/gtest.h>
25+
26+
using namespace yup;
27+
28+
namespace yup
29+
{
30+
extern std::unique_ptr<yup::GraphicsContext> yup_constructHeadlessGraphicsContext (yup::GraphicsContext::Options);
31+
} // namespace yup
32+
33+
TEST (ThemeVersion1Tests, PaintsCoreComponents)
34+
{
35+
auto context = yup_constructHeadlessGraphicsContext ({});
36+
auto renderer = context->makeRenderer (800, 600);
37+
Graphics g (*context, *renderer);
38+
39+
Slider slider (Slider::LinearHorizontal);
40+
slider.setRange (0.0, 1.0);
41+
slider.setValue (0.25);
42+
slider.setBounds (20.0f, 20.0f, 240.0f, 40.0f);
43+
slider.paint (g);
44+
45+
TextButton textButton;
46+
textButton.setBounds (20.0f, 80.0f, 140.0f, 40.0f);
47+
textButton.paint (g);
48+
49+
ToggleButton toggleButton;
50+
toggleButton.setToggleState (true, NotificationType::dontSendNotification);
51+
toggleButton.setBounds (20.0f, 140.0f, 160.0f, 40.0f);
52+
toggleButton.paint (g);
53+
54+
SwitchButton switchButton;
55+
switchButton.setToggleState (true, NotificationType::dontSendNotification);
56+
switchButton.setBounds (20.0f, 200.0f, 120.0f, 40.0f);
57+
switchButton.paint (g);
58+
59+
TextEditor textEditor;
60+
textEditor.setText ("Theme", NotificationType::dontSendNotification);
61+
textEditor.setBounds (20.0f, 260.0f, 240.0f, 40.0f);
62+
textEditor.paint (g);
63+
64+
ComboBox comboBox;
65+
comboBox.addItem ("Item 1", 1);
66+
comboBox.setSelectedId (1, NotificationType::dontSendNotification);
67+
comboBox.setBounds (20.0f, 320.0f, 200.0f, 40.0f);
68+
comboBox.paint (g);
69+
70+
Label label;
71+
label.setText ("Label", NotificationType::dontSendNotification);
72+
label.setBounds (20.0f, 380.0f, 200.0f, 30.0f);
73+
label.paint (g);
74+
75+
ScrollBar scrollBar (ScrollBar::Orientation::horizontal);
76+
scrollBar.setRangeLimits (0.0, 100.0);
77+
scrollBar.setCurrentRange (20.0, 40.0);
78+
scrollBar.setBounds (20.0f, 430.0f, 240.0f, 18.0f);
79+
scrollBar.paint (g);
80+
81+
ProgressBar progressBar;
82+
progressBar.setProgress (0.5, NotificationType::dontSendNotification);
83+
progressBar.setBounds (20.0f, 470.0f, 240.0f, 20.0f);
84+
progressBar.paint (g);
85+
86+
KMeterState meterState (48000.0, 2);
87+
KMeterComponent meter (meterState, 0);
88+
meter.setBounds (300.0f, 20.0f, 60.0f, 240.0f);
89+
meter.paint (g);
90+
91+
EXPECT_TRUE (true);
92+
}

0 commit comments

Comments
 (0)