File tree Expand file tree Collapse file tree 4 files changed +13
-0
lines changed Expand file tree Collapse file tree 4 files changed +13
-0
lines changed Original file line number Diff line number Diff 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;
Original file line number Diff line number Diff line change @@ -180,6 +180,7 @@ int Monitor::x() const
180180void 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
195196void 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. */
255263Rect Monitor::getInitialPosition (const std::vector<std::shared_ptr<Monitor>> &other, int monitorWidth, int monitorHeight)
256264{
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
3435TEST (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
194196TEST (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
208211TEST (MonitorTest, Visible)
You can’t perform that action at this time.
0 commit comments