Merge lp:~gordallott/nux/nux-keynav-fixes-17-03-11 into lp:nux
- nux-keynav-fixes-17-03-11
- Merge into trunk
Proposed by
Gord Allott
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 274 | ||||||||
Proposed branch: | lp:~gordallott/nux/nux-keynav-fixes-17-03-11 | ||||||||
Merge into: | lp:nux | ||||||||
Diff against target: |
507 lines (+175/-23) 12 files modified
Nux/Area.cpp (+1/-1) Nux/Area.h (+3/-0) Nux/GridHLayout.cpp (+58/-5) Nux/GridHLayout.h (+2/-2) Nux/HLayout.cpp (+2/-2) Nux/Layout.cpp (+12/-1) Nux/Layout.h (+3/-4) Nux/ScrollView.cpp (+41/-0) Nux/ScrollView.h (+4/-0) Nux/View.cpp (+29/-3) Nux/View.h (+8/-0) examples/focus.cpp (+12/-5) |
||||||||
To merge this branch: | bzr merge lp:~gordallott/nux/nux-keynav-fixes-17-03-11 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jay Taoko (community) | Approve | ||
Review via email: mp+53777@code.launchpad.net |
Commit message
Description of the change
linked bugs, some keynav fixes
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Nux/Area.cpp' |
2 | --- Nux/Area.cpp 2011-03-17 00:27:16 +0000 |
3 | +++ Nux/Area.cpp 2011-03-17 10:13:29 +0000 |
4 | @@ -825,7 +825,7 @@ |
5 | { |
6 | if (_is_focused == focused) |
7 | return; |
8 | - |
9 | + |
10 | _is_focused = focused; |
11 | FocusChanged.emit (this); |
12 | } |
13 | |
14 | === modified file 'Nux/Area.h' |
15 | --- Nux/Area.h 2011-03-17 00:27:16 +0000 |
16 | +++ Nux/Area.h 2011-03-17 10:13:29 +0000 |
17 | @@ -23,6 +23,7 @@ |
18 | #ifndef BASEOBJECT_H |
19 | #define BASEOBJECT_H |
20 | |
21 | +#include <sigc++/sigc++.h> |
22 | #include "NuxCore/InitiallyUnownedObject.h" |
23 | #include "Focusable.h" |
24 | #include "Utils.h" |
25 | @@ -31,6 +32,7 @@ |
26 | |
27 | |
28 | |
29 | + |
30 | namespace nux |
31 | { |
32 | class WindowThread; |
33 | @@ -297,6 +299,7 @@ |
34 | |
35 | sigc::signal <void, Area *> FocusActivated; |
36 | sigc::signal <void, Area *> FocusChanged; |
37 | + sigc::signal <void, Area*, Area*> ChildFocusChanged; // sends parent + child |
38 | |
39 | //! Queue a relayout |
40 | /*! |
41 | |
42 | === modified file 'Nux/GridHLayout.cpp' |
43 | --- Nux/GridHLayout.cpp 2011-03-10 13:03:38 +0000 |
44 | +++ Nux/GridHLayout.cpp 2011-03-17 10:13:29 +0000 |
45 | @@ -97,17 +97,56 @@ |
46 | return NULL; |
47 | } |
48 | |
49 | + long GridHLayout::DoFocusLeft (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) |
50 | + { |
51 | + // if we are left on an edge, then send up |
52 | + Area* focused_child = GetFocusedChild (); |
53 | + int position = GetChildPos (focused_child); |
54 | + Area *parent = GetParentObject (); |
55 | + |
56 | + if (parent == NULL || position % GetNumColumn ()) |
57 | + { |
58 | + return Layout::DoFocusLeft (ievent, TraverseInfo, ProcessEventInfo); |
59 | + } |
60 | + else |
61 | + { |
62 | + // left edge |
63 | + return SendEventToArea (parent, ievent, TraverseInfo, ProcessEventInfo); |
64 | + } |
65 | + } |
66 | + |
67 | + long GridHLayout::DoFocusRight (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) |
68 | + { |
69 | + // if we are left on an edge, then send up |
70 | + Area* focused_child = GetFocusedChild (); |
71 | + int position = GetChildPos (focused_child); |
72 | + Area *parent = GetParentObject (); |
73 | + |
74 | + if (parent == NULL || (position + 1) % GetNumColumn ()) |
75 | + { |
76 | + return Layout::DoFocusRight (ievent, TraverseInfo, ProcessEventInfo); |
77 | + } |
78 | + else |
79 | + { |
80 | + // Right Edge |
81 | + return SendEventToArea (parent, ievent, TraverseInfo, ProcessEventInfo); |
82 | + } |
83 | + } |
84 | + |
85 | //up and down should pass event to parent |
86 | long GridHLayout::DoFocusUp (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) |
87 | { |
88 | Area* focused_child = GetFocusedChild (); |
89 | int position = GetChildPos (focused_child); |
90 | + Area *parent = GetParentObject (); |
91 | |
92 | if (focused_child == NULL || position < GetNumColumn ()) |
93 | { |
94 | - Area *parent = GetParentObject (); |
95 | + |
96 | if (parent != NULL) |
97 | return SendEventToArea (parent, ievent, TraverseInfo, ProcessEventInfo); |
98 | + else |
99 | + FocusFirstChild (); |
100 | |
101 | } |
102 | else |
103 | @@ -117,7 +156,17 @@ |
104 | focused_child->SetFocused (false); |
105 | focused_child = GetChildAtPosition (position - GetNumColumn ()); |
106 | if (focused_child) |
107 | + { |
108 | focused_child->SetFocused (true); |
109 | + ChildFocusChanged.emit (this, focused_child); |
110 | + } |
111 | + else |
112 | + { |
113 | + if (parent != NULL) |
114 | + return SendEventToArea (parent, ievent, TraverseInfo, ProcessEventInfo); |
115 | + else |
116 | + FocusFirstChild (); |
117 | + } |
118 | } |
119 | |
120 | return TraverseInfo; |
121 | @@ -126,14 +175,14 @@ |
122 | { |
123 | Area* focused_child = GetFocusedChild (); |
124 | int position = GetChildPos (focused_child); |
125 | + Area *parent = GetParentObject (); |
126 | |
127 | if (focused_child == NULL || position > GetNumColumn () * (GetNumRow () - 1)) |
128 | { |
129 | - Area *parent = GetParentObject (); |
130 | if (parent != NULL) |
131 | - { |
132 | return SendEventToArea (parent, ievent, TraverseInfo, ProcessEventInfo); |
133 | - } |
134 | + else |
135 | + FocusLastChild (); |
136 | } |
137 | else |
138 | { |
139 | @@ -144,10 +193,14 @@ |
140 | if (focused_child) |
141 | { |
142 | focused_child->SetFocused (true); |
143 | + ChildFocusChanged.emit (this, focused_child); |
144 | } |
145 | else |
146 | { |
147 | - FocusLastChild (); |
148 | + if (parent != NULL) |
149 | + return SendEventToArea (parent, ievent, TraverseInfo, ProcessEventInfo); |
150 | + else |
151 | + FocusLastChild (); |
152 | } |
153 | } |
154 | |
155 | |
156 | === modified file 'Nux/GridHLayout.h' |
157 | --- Nux/GridHLayout.h 2011-03-09 15:20:56 +0000 |
158 | +++ Nux/GridHLayout.h 2011-03-17 10:13:29 +0000 |
159 | @@ -109,8 +109,8 @@ |
160 | Area* GetChildAtPosition (int pos); |
161 | virtual long DoFocusUp (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); |
162 | virtual long DoFocusDown (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); |
163 | - //virtual long DoFocusLeft (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); |
164 | - //virtual long DoFocusRight (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); |
165 | + virtual long DoFocusLeft (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); |
166 | + virtual long DoFocusRight (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); |
167 | |
168 | private: |
169 | Size _children_size; |
170 | |
171 | === modified file 'Nux/HLayout.cpp' |
172 | --- Nux/HLayout.cpp 2011-03-10 13:03:38 +0000 |
173 | +++ Nux/HLayout.cpp 2011-03-17 10:13:29 +0000 |
174 | @@ -71,7 +71,7 @@ |
175 | if (parent != NULL) |
176 | return SendEventToArea (parent, ievent, TraverseInfo, ProcessEventInfo); |
177 | else |
178 | - FocusFirstChild (); |
179 | + FocusPreviousChild (GetFocusedChild ()); |
180 | |
181 | return TraverseInfo; |
182 | } |
183 | @@ -82,7 +82,7 @@ |
184 | if (parent != NULL) |
185 | return SendEventToArea (parent, ievent, TraverseInfo, ProcessEventInfo); |
186 | else |
187 | - FocusFirstChild (); |
188 | + FocusNextChild (GetFocusedChild ()); |
189 | return TraverseInfo; |
190 | } |
191 | |
192 | |
193 | === modified file 'Nux/Layout.cpp' |
194 | --- Nux/Layout.cpp 2011-03-10 13:03:38 +0000 |
195 | +++ Nux/Layout.cpp 2011-03-17 10:13:29 +0000 |
196 | @@ -80,8 +80,13 @@ |
197 | FocusNextChild ((*it)); |
198 | } |
199 | } |
200 | + |
201 | + (*it)->SetFocused (false); |
202 | } |
203 | |
204 | + sigc::connection onchildfocuscon = _connection_map[bo]; |
205 | + onchildfocuscon.disconnect (); |
206 | + |
207 | if (it != _layout_element_list.end()) |
208 | { |
209 | bo->UnParentObject(); |
210 | @@ -154,6 +159,11 @@ |
211 | return false; |
212 | } |
213 | |
214 | + void Layout::OnChildFocusChanged (Area *parent, Area *child) |
215 | + { |
216 | + ChildFocusChanged.emit (parent, child); |
217 | + } |
218 | + |
219 | // If(stretchfactor == 0): the WidgetLayout geometry will be set to SetGeometry(0,0,1,1); |
220 | // and the children will take their natural size by expending WidgetLayout. |
221 | // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout. |
222 | @@ -198,6 +208,7 @@ |
223 | } |
224 | |
225 | _layout_element_list.push_back (layout); |
226 | + _connection_map[layout] = layout->ChildFocusChanged.connect (sigc::mem_fun (this, &Layout::OnChildFocusChanged)); |
227 | |
228 | //--->> Removed because it cause problem with The splitter widget: ComputeLayout2(); |
229 | } |
230 | @@ -265,6 +276,7 @@ |
231 | |
232 | |
233 | _layout_element_list.push_back (bo); |
234 | + _connection_map[bo] = bo->ChildFocusChanged.connect (sigc::mem_fun (this, &Layout::OnChildFocusChanged)); |
235 | |
236 | //--->> Removed because it cause problem with The splitter widget: ComputeLayout2(); |
237 | } |
238 | @@ -512,7 +524,6 @@ |
239 | return 0; |
240 | } |
241 | |
242 | - |
243 | long ret = 0; |
244 | if ( area->IsView() ) |
245 | { |
246 | |
247 | === modified file 'Nux/Layout.h' |
248 | --- Nux/Layout.h 2011-03-10 12:12:07 +0000 |
249 | +++ Nux/Layout.h 2011-03-17 10:13:29 +0000 |
250 | @@ -231,8 +231,6 @@ |
251 | |
252 | bool HasFocusableEntries (); |
253 | |
254 | - sigc::signal <void, Layout *, Area*> ChildFocusChanged; |
255 | - |
256 | // this should not be public, but has to be because of nux's object setup |
257 | long ProcessFocusEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); |
258 | bool _has_focus_control; |
259 | @@ -252,8 +250,9 @@ |
260 | virtual bool FocusLastChild (); |
261 | virtual bool FocusNextChild (Area *child); |
262 | virtual bool FocusPreviousChild (Area *child); |
263 | - |
264 | - |
265 | + void OnChildFocusChanged (Area *parent, Area *child); |
266 | + |
267 | + std::map<Area*, sigc::connection> _connection_map; // map our children to connections |
268 | |
269 | bool _queued_draw; //<! The rendering of the layout needs to be refreshed. |
270 | |
271 | |
272 | === modified file 'Nux/ScrollView.cpp' |
273 | --- Nux/ScrollView.cpp 2011-03-04 16:42:15 +0000 |
274 | +++ Nux/ScrollView.cpp 2011-03-17 10:13:29 +0000 |
275 | @@ -66,6 +66,8 @@ |
276 | m_ViewContentBottomMargin = 0; |
277 | FormatContent(); |
278 | |
279 | + ChildFocusChanged.connect (sigc::mem_fun (this, &ScrollView::OnChildFocusChanged)); |
280 | + |
281 | } |
282 | |
283 | ScrollView::~ScrollView() |
284 | @@ -75,6 +77,45 @@ |
285 | vscrollbar->Dispose (); |
286 | } |
287 | |
288 | + void ScrollView::OnChildFocusChanged (Area *parent, Area *child) |
289 | + { |
290 | + if (child->IsView ()) |
291 | + { |
292 | + View *view = (View*)child; |
293 | + if (view->HasPassiveFocus ()) |
294 | + { |
295 | + return; |
296 | + } |
297 | + } |
298 | + if (child->IsLayout ()) |
299 | + return; |
300 | + |
301 | + int child_y = child->GetGeometry ().y - GetGeometry ().y; |
302 | + int child_y_diff = child_y - abs (_delta_y); |
303 | + |
304 | + |
305 | + if (child_y_diff + child->GetGeometry ().height < GetGeometry ().height && child_y_diff >= 0) |
306 | + { |
307 | + return; |
308 | + } |
309 | + |
310 | + if (child_y_diff < 0) |
311 | + { |
312 | + ScrollUp (1, abs (child_y_diff)); |
313 | + } |
314 | + else |
315 | + { |
316 | + int size = child_y_diff - GetGeometry ().height; |
317 | + |
318 | + // always keeps the top of a view on the screen |
319 | + size += (child->GetGeometry ().height, GetGeometry ().height) ? child->GetGeometry ().height : GetGeometry ().height; |
320 | + |
321 | + ScrollDown (1, size); |
322 | + } |
323 | + |
324 | + } |
325 | + |
326 | + |
327 | long ScrollView::ProcessEvent (Event &event, long TraverseInfo, long ProcessEventInfo) |
328 | { |
329 | long ret = TraverseInfo; |
330 | |
331 | === modified file 'Nux/ScrollView.h' |
332 | --- Nux/ScrollView.h 2011-03-04 16:42:15 +0000 |
333 | +++ Nux/ScrollView.h 2011-03-17 10:13:29 +0000 |
334 | @@ -25,6 +25,7 @@ |
335 | |
336 | #include "Nux.h" |
337 | |
338 | + |
339 | namespace nux |
340 | { |
341 | class HScrollBar; |
342 | @@ -156,6 +157,9 @@ |
343 | virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw); |
344 | virtual long ProcessEvent (Event &event, long TraverseInfo, long ProcessEventInfo); |
345 | |
346 | + void OnChildFocusChanged (Area *parent, Area *child); |
347 | + |
348 | + |
349 | // Backup texture to speed up scrolling |
350 | ObjectPtr<IOpenGLFrameBufferObject> m_FrameBufferObject; |
351 | |
352 | |
353 | === modified file 'Nux/View.cpp' |
354 | --- Nux/View.cpp 2011-03-17 00:34:40 +0000 |
355 | +++ Nux/View.cpp 2011-03-17 10:13:29 +0000 |
356 | @@ -71,8 +71,11 @@ |
357 | |
358 | Area *parent = GetParentObject (); |
359 | if (parent == NULL) |
360 | + { |
361 | + GetLayout ()->SetFocused (false); |
362 | GetLayout ()->SetFocused (true); // just reset the layout focus becase we are top level |
363 | - |
364 | + } |
365 | + |
366 | if (parent != NULL && parent->IsLayout ()) |
367 | { |
368 | Layout *parent_layout = (Layout *)parent; |
369 | @@ -262,6 +265,7 @@ |
370 | } |
371 | } |
372 | |
373 | +// just leave this here, its helpful for debugging focus issues :) |
374 | // if (GetFocused () && _can_pass_focus_to_composite_layout == false) |
375 | // { |
376 | // GetPainter ().Paint2DQuadColor (GfxContext, GetGeometry (), nux::Color (0.2, 1.0, 0.2, 1.0)); |
377 | @@ -294,7 +298,7 @@ |
378 | //GetWindowCompositor()..AddToDrawList(this); |
379 | WindowThread* application = GetWindowThread (); |
380 | if(application) |
381 | - { |
382 | + { |
383 | application->AddToDrawList(this); |
384 | application->RequestRedraw(); |
385 | //GetWindowCompositor().AddToDrawList(this); |
386 | @@ -372,8 +376,13 @@ |
387 | } |
388 | |
389 | if (m_CompositionLayout) |
390 | + { |
391 | + if (GetFocused ()) |
392 | + m_CompositionLayout->SetFocused (false); |
393 | + |
394 | + _on_focus_changed_handler.disconnect (); |
395 | m_CompositionLayout->UnParentObject(); |
396 | - |
397 | + } |
398 | layout->SetParentObject (this); |
399 | m_CompositionLayout = layout; |
400 | |
401 | @@ -381,9 +390,16 @@ |
402 | if (GetFocused ()) |
403 | layout->SetFocused (true); |
404 | |
405 | + _on_focus_changed_handler = layout->ChildFocusChanged.connect (sigc::mem_fun (this, &View::OnChildFocusChanged)); |
406 | return true; |
407 | } |
408 | |
409 | + //propogate the signal |
410 | + void View::OnChildFocusChanged (Area *parent, Area *child) |
411 | + { |
412 | + ChildFocusChanged.emit (parent, child); |
413 | + } |
414 | + |
415 | bool View::SetCompositionLayout (Layout *layout) |
416 | { |
417 | return SetLayout (layout); |
418 | @@ -542,6 +558,16 @@ |
419 | } |
420 | } |
421 | |
422 | + // if we have a layout, returns true if we pass focus to it |
423 | + // else returns false |
424 | + bool View::HasPassiveFocus () |
425 | + { |
426 | + if (_can_pass_focus_to_composite_layout && GetLayout () != NULL) |
427 | + return true; |
428 | + |
429 | + return false; |
430 | + } |
431 | + |
432 | void View::SetFocusControl (bool focus_control) |
433 | { |
434 | Area *_parent = GetParentObject (); |
435 | |
436 | === modified file 'Nux/View.h' |
437 | --- Nux/View.h 2011-03-17 01:12:20 +0000 |
438 | +++ Nux/View.h 2011-03-17 10:13:29 +0000 |
439 | @@ -180,9 +180,17 @@ |
440 | void SetFocusControl (bool focus_control); |
441 | bool HasFocusControl (); |
442 | |
443 | + /* |
444 | + Returns true if the view has a layout and passes focus to that layout |
445 | + */ |
446 | + bool HasPassiveFocus (); |
447 | + |
448 | protected: |
449 | bool _can_focus; |
450 | |
451 | + void OnChildFocusChanged (Area *parent, Area *child); |
452 | + sigc::connection _on_focus_changed_handler; |
453 | + |
454 | virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) = 0; |
455 | virtual void Draw (GraphicsEngine &GfxContext, bool force_draw) = 0; |
456 | virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw); |
457 | |
458 | === modified file 'examples/focus.cpp' |
459 | --- examples/focus.cpp 2011-03-10 12:12:07 +0000 |
460 | +++ examples/focus.cpp 2011-03-17 10:13:29 +0000 |
461 | @@ -37,7 +37,7 @@ |
462 | return ((float)rand ()) / RAND_MAX; |
463 | } |
464 | |
465 | -static void OnFocusChildChanged (nux::Layout *layout, nux::Area *view) |
466 | +static void OnFocusChildChanged (nux::Area *layout, nux::Area *view) |
467 | { |
468 | g_debug ("focus has changed, woo %i", rand ()); |
469 | } |
470 | @@ -77,11 +77,18 @@ |
471 | nux::VLayout* layout_scroll_container = new nux::VLayout (NUX_TRACKER_LOCATION); |
472 | |
473 | nux::VLayout* layout_scroll_1 = new nux::VLayout(NUX_TRACKER_LOCATION); |
474 | + |
475 | + |
476 | nux::HLayout* layout_scroll_11 = new nux::HLayout(NUX_TRACKER_LOCATION); |
477 | - nux::GridHLayout* layout_scroll_12 = new nux::GridHLayout (NUX_TRACKER_LOCATION); |
478 | + nux::ScrollView *layout_scroll_12 = new nux::ScrollView (NUX_TRACKER_LOCATION); |
479 | + nux::GridHLayout* layout_scroll_12_content = new nux::GridHLayout (NUX_TRACKER_LOCATION); |
480 | + layout_scroll_12->EnableHorizontalScrollBar (false); |
481 | + layout_scroll_12->EnableVerticalScrollBar (true); |
482 | + layout_scroll_12->SetLayout (layout_scroll_12_content); |
483 | + |
484 | |
485 | layout_scroll_1->AddLayout (layout_scroll_11, 0, nux::MINOR_POSITION_TOP); |
486 | - layout_scroll_1->AddLayout (layout_scroll_12, 1, nux::MINOR_POSITION_TOP); |
487 | + layout_scroll_1->AddView (layout_scroll_12, 1, nux::MINOR_POSITION_TOP); |
488 | |
489 | nux::VLayout* layout_scroll_2 = new nux::VLayout(NUX_TRACKER_LOCATION); |
490 | nux::HLayout* layout_scroll_21 = new nux::HLayout(NUX_TRACKER_LOCATION); |
491 | @@ -124,14 +131,14 @@ |
492 | layout_scroll_11->AddView (texture_area, 1, nux::eLeft, nux::eFull); |
493 | } |
494 | |
495 | - for (int i = 0; i < 16; i++) |
496 | + for (int i = 0; i < 128; i++) |
497 | { |
498 | nux::ColorLayer color (nux::Color (0.2, 0.2, 0.4+ frand ()*0.3, 1.0)); |
499 | nux::TextureArea* texture_area = new nux::TextureArea (); |
500 | texture_area->SetPaintLayer (&color); |
501 | texture_area->FocusChanged.connect (sigc::ptr_fun (&OnFocusChanged)); |
502 | //~ //~ |
503 | - layout_scroll_12->AddView (texture_area, 1, nux::eLeft, nux::eFull); |
504 | + layout_scroll_12_content->AddView (texture_area, 1, nux::eLeft, nux::eFull); |
505 | } |
506 | |
507 | for (int i = 0; i < 6; i++) |
Approved