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