Skip to content

Commit 6495212

Browse files
committed
TextBubble: Move to front when text is set
1 parent 5161321 commit 6495212

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/scratch/textbubble.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <scratchcpp/textbubble.h>
44
#include <scratchcpp/value.h>
5+
#include <scratchcpp/iengine.h>
56

67
#include "textbubble_p.h"
78

@@ -70,6 +71,13 @@ void TextBubble::setText(const std::string &text)
7071
impl->text = converted.substr(0, limit);
7172

7273
impl->textChanged(impl->text);
74+
75+
if (!impl->text.empty()) {
76+
IEngine *eng = engine();
77+
78+
if (eng)
79+
eng->moveDrawableToFront(this);
80+
}
7381
}
7482

7583
/*! Emits when the text changes. */

test/scratch_classes/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ add_executable(
9898

9999
target_link_libraries(
100100
textbubble_test
101-
GTest::gtest_main
101+
GTest::gmock_main
102+
scratchcpp
103+
scratchcpp_mocks
102104
scratchcpp
103105
)
104106

test/scratch_classes/textbubble_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <scratchcpp/textbubble.h>
2+
#include <enginemock.h>
23

34
#include "../common.h"
45

@@ -36,8 +37,12 @@ TEST(TextBubbleTest, BubbleText)
3637
bubble.setText("hello");
3738
ASSERT_EQ(bubble.text(), "hello");
3839

40+
EngineMock engine;
41+
bubble.setEngine(&engine);
42+
EXPECT_CALL(engine, moveDrawableToFront(&bubble));
3943
bubble.setText("world");
4044
ASSERT_EQ(bubble.text(), "world");
45+
bubble.setEngine(nullptr);
4146

4247
// longstr.length = 384, should be limited to 330 in bubble text
4348
std::string longstr =

0 commit comments

Comments
 (0)