Skip to content

Commit 29970fd

Browse files
committed
Add needsAutoPosition property to monitor
1 parent 24ca4f8 commit 29970fd

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

include/scratchcpp/monitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class LIBSCRATCHCPP_EXPORT Monitor : public Entity
8686
void setDiscrete(bool discrete);
8787

8888
static Rect getInitialPosition(const std::vector<std::shared_ptr<Monitor>> &other, int monitorWidth, int monitorHeight);
89+
bool needsAutoPosition() const;
8990

9091
private:
9192
spimpl::unique_impl_ptr<MonitorPrivate> impl;

src/scratch/monitor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ int Monitor::x() const
180180
void Monitor::setX(int x)
181181
{
182182
impl->x = x;
183+
impl->needsAutoPosition = false;
183184

184185
if (impl->iface)
185186
impl->iface->onXChanged(x);
@@ -195,6 +196,7 @@ int Monitor::y() const
195196
void Monitor::setY(int y)
196197
{
197198
impl->y = y;
199+
impl->needsAutoPosition = false;
198200

199201
if (impl->iface)
200202
impl->iface->onYChanged(y);
@@ -251,6 +253,12 @@ void Monitor::setDiscrete(bool discrete)
251253
impl->discrete = discrete;
252254
}
253255

256+
/*! Returns true if the monitor needs auto positioning. */
257+
bool Monitor::needsAutoPosition() const
258+
{
259+
return impl->needsAutoPosition;
260+
}
261+
254262
/*! Returns the initial position of a monitor. */
255263
Rect Monitor::getInitialPosition(const std::vector<std::shared_ptr<Monitor>> &other, int monitorWidth, int monitorHeight)
256264
{

src/scratch/monitor_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct MonitorPrivate
3232
double sliderMin = 0;
3333
double sliderMax = 0;
3434
bool discrete = false;
35+
bool needsAutoPosition = true;
3536
static IRandomGenerator *rng;
3637
};
3738

test/scratch_classes/monitor_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ TEST(MonitorTest, Constructors)
2929
ASSERT_EQ(monitor.opcode(), "test");
3030
ASSERT_TRUE(monitor.block());
3131
ASSERT_EQ(monitor.block()->opcode(), "test");
32+
ASSERT_TRUE(monitor.needsAutoPosition());
3233
}
3334

3435
TEST(MonitorTest, Id)
@@ -189,6 +190,7 @@ TEST(MonitorTest, X)
189190
EXPECT_CALL(handler, onXChanged(-78));
190191
monitor.setX(-78);
191192
ASSERT_EQ(monitor.x(), -78);
193+
ASSERT_FALSE(monitor.needsAutoPosition());
192194
}
193195

194196
TEST(MonitorTest, Y)
@@ -203,6 +205,7 @@ TEST(MonitorTest, Y)
203205
EXPECT_CALL(handler, onYChanged(150));
204206
monitor.setY(150);
205207
ASSERT_EQ(monitor.y(), 150);
208+
ASSERT_FALSE(monitor.needsAutoPosition());
206209
}
207210

208211
TEST(MonitorTest, Visible)

0 commit comments

Comments
 (0)