Nux

Merge lp:~azzar1/nux/fix-888819 into lp:nux/2.0

Proposed by Andrea Azzarone
Status: Merged
Approved by: Jay Taoko
Approved revision: 535
Merged at revision: 530
Proposed branch: lp:~azzar1/nux/fix-888819
Merge into: lp:nux/2.0
Diff against target: 378 lines (+287/-5)
7 files modified
Nux/ScrollView.cpp (+5/-0)
Nux/VScrollBar.h (+0/-2)
configure.ac (+1/-1)
tests/Makefile.am (+19/-2)
tests/scrollbar-test.cpp (+138/-0)
tests/test-scrollview.cpp (+73/-0)
tests/test-scrollview.h (+51/-0)
To merge this branch: bzr merge lp:~azzar1/nux/fix-888819
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Tim Penhey (community) Needs Information
Review via email: mp+85441@code.launchpad.net

Description of the change

Makes sure that the scroll wheel works with nux::VScrollbar

To post a comment you must log in.
lp:~azzar1/nux/fix-888819 updated
531. By Andrea Azzarone

Fixes.

Revision history for this message
Tim Penhey (thumper) wrote :

Is there a way to fake an event and show in a test that this all works?

review: Needs Information
Revision history for this message
Andrea Azzarone (azzar1) wrote :

@Tim, it's how nux scrollbars work :) By the way I can write a simple test.

lp:~azzar1/nux/fix-888819 updated
532. By Andrea Azzarone

Add a simple test.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Is there a way to fake an event and show in a test that this all works?

Done. I've used

  test.ViewSendMouseClick(bla bla bla, 4);

to fake a mouse scroll in the test.

Revision history for this message
Jay Taoko (jaytaoko) wrote :

@Andrea

When using the default scrollbar in Nux the mouse wheel over the scrollbar works. However, that wasn't the case with the scrollbar defined in Unity (with custom rendering).
The fix in Nux/ScrollView.cpp is correct. However, I think there is no need for the fix in Nux/VScrollBar.cpp. Can you test your fix without the change to Nux/VScrollBar.cpp and report what happens?

review: Needs Information
lp:~azzar1/nux/fix-888819 updated
533. By Andrea Azzarone

Fixes.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

> @Andrea
>
> When using the default scrollbar in Nux the mouse wheel over the scrollbar
> works. However, that wasn't the case with the scrollbar defined in Unity (with
> custom rendering).
> The fix in Nux/ScrollView.cpp is correct. However, I think there is no need
> for the fix in Nux/VScrollBar.cpp. Can you test your fix without the change to
> Nux/VScrollBar.cpp and report what happens?

Done.

lp:~azzar1/nux/fix-888819 updated
534. By Andrea Azzarone

Ops.

535. By Andrea Azzarone

Update abi version.

Revision history for this message
Jay Taoko (jaytaoko) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/ScrollView.cpp'
2--- Nux/ScrollView.cpp 2011-10-17 20:57:35 +0000
3+++ Nux/ScrollView.cpp 2012-01-02 22:23:24 +0000
4@@ -100,6 +100,9 @@
5 &ScrollView::ScrollUp));
6 _vscrollbar->OnScrollDown.connect(sigc::mem_fun(this,
7 &ScrollView::ScrollDown));
8+ _vscrollbar->mouse_wheel.connect(sigc::mem_fun(this,
9+ &ScrollView::RecvMouseWheel));
10+
11 _vscrollbar->UnReference();
12 }
13
14@@ -113,6 +116,8 @@
15 &ScrollView::ScrollUp));
16 _vscrollbar->OnScrollDown.connect(sigc::mem_fun(this,
17 &ScrollView::ScrollDown));
18+ _vscrollbar->mouse_wheel.connect(sigc::mem_fun(this,
19+ &ScrollView::RecvMouseWheel));
20 }
21
22 ScrollView::~ScrollView()
23
24=== modified file 'Nux/VScrollBar.h'
25--- Nux/VScrollBar.h 2011-10-10 01:52:00 +0000
26+++ Nux/VScrollBar.h 2012-01-02 22:23:24 +0000
27@@ -91,8 +91,6 @@
28 float m_color_factor;
29
30 protected:
31- void RecvMouseWheel(int x, int y, int wheel_delta, long button_flags, unsigned long key_flags);
32-
33 // When the Scrollbar is used standalone, it is necessary to call ComputeScrolling at the end of the layout.
34 virtual long PostLayoutManagement(long LayoutResult);
35
36
37=== modified file 'configure.ac'
38--- configure.ac 2011-12-08 17:50:54 +0000
39+++ configure.ac 2012-01-02 22:23:24 +0000
40@@ -22,7 +22,7 @@
41 # The number format is : year/month/day
42 # e.g.: december 5th, 2011 is: 20111205
43 # So far there is no provision for more than one break in a day.
44-m4_define([nux_abi_version], [20111208])
45+m4_define([nux_abi_version], [20111209])
46
47 m4_define([nux_version],
48 [nux_major_version.nux_minor_version.nux_micro_version])
49
50=== modified file 'tests/Makefile.am'
51--- tests/Makefile.am 2011-12-11 18:26:59 +0000
52+++ tests/Makefile.am 2012-01-02 22:23:24 +0000
53@@ -9,7 +9,8 @@
54 mouse-buttons-test \
55 hgrid-key-navigation-test \
56 hlayout-key-navigation-test \
57- vlayout-key-navigation-test
58+ vlayout-key-navigation-test \
59+ scrollbar-test
60
61 # Please keep alphabetical
62 test_nux_SOURCES = \
63@@ -178,6 +179,21 @@
64 vlayout_key_navigation_test_LDFLAGS = -lpthread -lXtst
65
66
67+scrollbar_test_SOURCES = scrollbar-test.cpp \
68+ nux_test_framework.cpp \
69+ nux_test_framework.h \
70+ nux_automated_test_framework.cpp \
71+ nux_automated_test_framework.h \
72+ test-scrollview.cpp \
73+ test-scrollview.h \
74+ test-view.cpp \
75+ test-view.h
76+
77+scrollbar_test_CPPFLAGS = $(TestFlags)
78+scrollbar_test_LDADD = $(TestLibs)
79+scrollbar_test_LDFLAGS = -lpthread -lXtst
80+
81+
82 #run make test as part of make check
83 check-local: test gtest test-apps
84
85@@ -187,7 +203,7 @@
86 gtest: gtest-nux-core
87 ./gtest-nux-core
88
89-test-apps: test-graphics-display test-empty-window button-xtest mouse-events-test mouse-buttons-test hgrid-key-navigation-test hlayout-key-navigation-test vlayout-key-navigation-test
90+test-apps: test-graphics-display test-empty-window button-xtest mouse-events-test mouse-buttons-test hgrid-key-navigation-test hlayout-key-navigation-test vlayout-key-navigation-test scrollbar-test
91 ./test-graphics-display
92 ./test-empty-window
93 ./button-xtest
94@@ -196,6 +212,7 @@
95 ./hgrid-key-navigation-test
96 ./hlayout-key-navigation-test
97 ./vlayout-key-navigation-test
98+ ./scrollbar-test
99
100 check-report:
101 @gtester -k -o=test-nux-results.xml -k ./test-nux \
102
103=== added file 'tests/scrollbar-test.cpp'
104--- tests/scrollbar-test.cpp 1970-01-01 00:00:00 +0000
105+++ tests/scrollbar-test.cpp 2012-01-02 22:23:24 +0000
106@@ -0,0 +1,138 @@
107+/*
108+ * Copyright 2011 Inalogic Inc.
109+ *
110+ * This program is free software: you can redistribute it and/or modify it
111+ * under the terms of the GNU General Public License version 3, as published
112+ * by the Free Software Foundation.
113+ *
114+ * This program is distributed in the hope that it will be useful, but
115+ * WITHOUT ANY WARRANTY; without even the implied warranties of
116+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
117+ * PURPOSE. See the GNU General Public License for more details.
118+ *
119+ * You should have received a copy of the GNU General Public License
120+ * version 3 along with this program. If not, see
121+ * <http://www.gnu.org/licenses/>
122+ *
123+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
124+ *
125+ */
126+
127+#include "Nux/Nux.h"
128+#include "Nux/WindowThread.h"
129+#include "Nux/VLayout.h"
130+#include <X11/extensions/XTest.h>
131+#include <X11/keysym.h>
132+#include "nux_test_framework.h"
133+#include "nux_automated_test_framework.h"
134+#include "test-scrollview.h"
135+#include "test-view.h"
136+
137+class ScrollBarTest : public NuxTestFramework
138+{
139+public:
140+ ScrollBarTest(const char* program_name, int window_width, int window_height, int program_life_span);
141+ ~ScrollBarTest();
142+
143+ virtual void UserInterfaceSetup();
144+
145+ nux::VLayout* layout_;
146+ TestScrollView* scroll_view_;
147+ nux::VLayout* in_layout_;
148+ TestView* test_view_;
149+};
150+
151+ScrollBarTest::ScrollBarTest(const char *program_name,
152+ int window_width,
153+ int window_height,
154+ int program_life_span)
155+ : NuxTestFramework(program_name, window_width, window_height, program_life_span)
156+{
157+}
158+
159+ScrollBarTest::~ScrollBarTest()
160+{
161+}
162+
163+void ScrollBarTest::UserInterfaceSetup()
164+{
165+ layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
166+ layout_->SetPadding(20, 20);
167+
168+ scroll_view_ = new TestScrollView();
169+ layout_->AddView(scroll_view_);
170+
171+ in_layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
172+ scroll_view_->SetLayout(in_layout_);
173+
174+ test_view_ = new TestView();
175+ test_view_->SetMinimumHeight(1000);
176+ in_layout_->AddView(test_view_);
177+
178+ static_cast<nux::WindowThread*>(window_thread_)->SetLayout(layout_);
179+
180+ nux::ColorLayer background(nux::Color(0xFF4D4D4D));
181+ static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
182+}
183+
184+ScrollBarTest* scrollbar_test;
185+
186+void TestingThread(nux::NThread *thread, void *user_data)
187+{
188+ while (scrollbar_test->ReadyToGo() == false)
189+ {
190+ nuxDebugMsg("Waiting to start");
191+ nux::SleepForMilliseconds(300);
192+ }
193+ nux::SleepForMilliseconds(1000);
194+
195+ nux::WindowThread *wnd_thread = static_cast<nux::WindowThread*>(user_data);
196+ NuxAutomatedTestFramework test(wnd_thread);
197+ test.Startup();
198+
199+ test.TestReportMsg(scrollbar_test->scroll_view_, "TestScrollView created");
200+
201+ scrollbar_test->scroll_view_->ResetEvents();
202+ test.ViewSendMouseMotionToCenter(scrollbar_test->scroll_view_);
203+ test.ViewSendMouseClick(scrollbar_test->scroll_view_, 4);
204+ nux::SleepForMilliseconds(1000);
205+ test.TestReportMsg(scrollbar_test->scroll_view_->registered_scroll_, "Scroll on the center of the scrollview");
206+
207+
208+ scrollbar_test->scroll_view_->ResetEvents();
209+ test.ViewSendMouseMotionToCenter(scrollbar_test->scroll_view_->GetVScrollbar());
210+ test.ViewSendMouseClick(scrollbar_test->scroll_view_->GetVScrollbar(), 4);
211+ nux::SleepForMilliseconds(1000);
212+ test.TestReportMsg(scrollbar_test->scroll_view_->registered_scroll_, "Scroll on the scrollbar");
213+
214+ if (test.WhenDoneTerminateProgram())
215+ {
216+ nux::SleepForMilliseconds(1000);
217+ wnd_thread->NuxMainLoopQuit();
218+ }
219+ nuxDebugMsg("Exit testing thread");
220+}
221+
222+int main(int argc, char **argv)
223+{
224+ int xstatus = XInitThreads();
225+ nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
226+
227+ scrollbar_test = new ScrollBarTest("Scrollbar Test", 500, 400, 13000);
228+ scrollbar_test->Startup();
229+ scrollbar_test->UserInterfaceSetup();
230+
231+ nux::SystemThread* test_thread = nux::CreateSystemThread(scrollbar_test->GetWindowThread(), &TestingThread, scrollbar_test->GetWindowThread());
232+
233+ test_thread->Start(scrollbar_test);
234+
235+ scrollbar_test->Run();
236+
237+ delete test_thread;
238+ delete scrollbar_test;
239+
240+ return 0;
241+}
242+
243+
244+
245
246=== added file 'tests/test-scrollview.cpp'
247--- tests/test-scrollview.cpp 1970-01-01 00:00:00 +0000
248+++ tests/test-scrollview.cpp 2012-01-02 22:23:24 +0000
249@@ -0,0 +1,73 @@
250+/*
251+ * Copyright 2011 Inalogic Inc.
252+ *
253+ * This program is free software: you can redistribute it and/or modify it
254+ * under the terms of the GNU General Public License version 3, as published
255+ * by the Free Software Foundation.
256+ *
257+ * This program is distributed in the hope that it will be useful, but
258+ * WITHOUT ANY WARRANTY; without even the implied warranties of
259+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
260+ * PURPOSE. See the GNU General Public License for more details.
261+ *
262+ * You should have received a copy of the GNU General Public License
263+ * version 3 along with this program. If not, see
264+ * <http://www.gnu.org/licenses/>
265+ *
266+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
267+ *
268+ */
269+
270+#include "Nux/Nux.h"
271+#include "test-scrollview.h"
272+
273+/*
274+ TestScrollView:
275+ This class is a Nux scrollview that process the mouse wheel events
276+ to make sure that everyghing work well.
277+*/
278+
279+NUX_IMPLEMENT_OBJECT_TYPE(TestScrollView);
280+
281+TestScrollView::TestScrollView(NUX_FILE_LINE_DECL)
282+ : nux::ScrollView(NUX_FILE_LINE_PARAM)
283+ , registered_scroll_(false)
284+ , normal_color_(nux::color::Green)
285+ , current_color_(normal_color_)
286+{
287+ EnableVerticalScrollBar(true);
288+ EnableHorizontalScrollBar(true);
289+
290+ scrolling.connect(sigc::mem_fun(this, &TestScrollView::OnScrolling));
291+}
292+
293+TestScrollView::~TestScrollView()
294+{
295+
296+}
297+
298+void TestScrollView::ResetEvents()
299+{
300+ registered_scroll_ = false;
301+
302+ current_color_ = normal_color_;
303+}
304+
305+nux::Color TestScrollView::GetColor() const
306+{
307+ return current_color_;
308+}
309+
310+void TestScrollView::Draw(nux::GraphicsEngine &graphics_engine, bool force_draw)
311+{
312+ nux::Geometry geo = GetGeometry();
313+ graphics_engine.QRP_Color(geo.x, geo.y, geo.width, geo.height, current_color_);
314+}
315+
316+void TestScrollView::OnScrolling(int hscroll, int vscroll)
317+{
318+ registered_scroll_ = true;
319+
320+ QueueDraw();
321+}
322+
323
324=== added file 'tests/test-scrollview.h'
325--- tests/test-scrollview.h 1970-01-01 00:00:00 +0000
326+++ tests/test-scrollview.h 2012-01-02 22:23:24 +0000
327@@ -0,0 +1,51 @@
328+/*
329+ * Copyright 2011 Inalogic Inc.
330+ *
331+ * This program is free software: you can redistribute it and/or modify it
332+ * under the terms of the GNU General Public License version 3, as published
333+ * by the Free Software Foundation.
334+ *
335+ * This program is distributed in the hope that it will be useful, but
336+ * WITHOUT ANY WARRANTY; without even the implied warranties of
337+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
338+ * PURPOSE. See the GNU General Public License for more details.
339+ *
340+ * You should have received a copy of the GNU General Public License
341+ * version 3 along with this program. If not, see
342+ * <http://www.gnu.org/licenses/>
343+ *
344+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
345+ *
346+ */
347+
348+#ifndef TEST_SCROLLVIEW_H
349+#define TEST_SCROLLVIEW_H
350+
351+#include "Nux/ScrollView.h"
352+#include "Nux/VScrollBar.h"
353+
354+class TestScrollView: public nux::ScrollView
355+{
356+ NUX_DECLARE_OBJECT_TYPE(TestView, ScrollView);
357+public:
358+ TestScrollView(NUX_FILE_LINE_PROTO);
359+ ~TestScrollView();
360+
361+ nux::Color GetColor() const;
362+ void ResetEvents();
363+ nux::VScrollBar* GetVScrollbar() {return _vscrollbar;}
364+
365+ bool registered_scroll_;
366+
367+protected:
368+ void Draw(nux::GraphicsEngine &graphics_engine, bool force_draw);
369+ void OnScrolling(int hscroll, int vscroll);
370+
371+private:
372+ nux::Color normal_color_;
373+ nux::Color current_color_;
374+
375+};
376+
377+#endif // TEST_VIEW_H
378+

Subscribers

People subscribed via source and target branches

to all changes: