Comments (8)
It seems logical to me that an element which is not in the graph scene cannot actually requests the focus.
But, having a way to define the default focused element would be good.
from bloc.
Actually it can π
Imagine a scroll list of text editors. Elements that go outside of viewport get removed from scene graph but they still can be focused and can receive keystroke events.
from bloc.
The point here is that requestFocus
could just set focused
to true if element is not in the scene graph. As soon as it is added to the space we check if focused
is true and actually give element focus.
Check how it is done in other graphical frameworks. There users can configure visual elements first (set color, font size, focus if needed) and only then add to the scene
from bloc.
I checked how it is done in other graphical frameworks (android, jquery, Qt, Javafx, iOS UIKit).
All of them have a kind of requestFocus
which has an effect only if the element
is attached to the scene graph.
Specifying the element
that want the focus first is another mechanism, mainly a boolean to mark the element
as the first responder. But this boolean has an effect only when this element
is attached to a scene graph.
An element
which is not attached to a scene graph cannot be an event target and cannot be the focus owner. Simply because at this moment, you cannot know in which space
it is.
I would see the basic focus specs like that:
(i checked what it is already introduced in the current version of Bloc)
- When a
space
is shown we have:- to make it the focused
space
- to request the focus for the first
element
that need it (would be based on mentioned boolean)
- to make it the focused
- When the focus changed we have:
- to toggle the focused
space
- to dispatch blur event to the previous focused
element
- to dispatch focus event to the new focused
element
- When a keyboard navigation is detected, we have:
- to find the next or previous focusable
element
- to request the focus for this
element
- to find the next or previous focusable
- The focus can be changed in 3 ways:
- mouse/touch click
- keyboard navigation
- programmatically (with
requestFocus
)
What do you think ?
from bloc.
Glenn, what you say it totally right and I agree :)
But we are talking about different things.
Of course you can not give focus to an element that is not in the space because you don't know which space. I'm saying that we need a mechanism to request focus to an element, so that only when it is added to the space it will get focus. Here is a pseudo-code example:
space := BlSpace new.
child := BlElement new.
"here goes configuration step. The problem is that we can not always know when element
is going to be added to space and to which space. We just want it to be focused once
it is added to scene graph"
child background: Color red.
child requestFocus.
space root addChild: child. "<- child will get focus AFTER it is added to concrete space"
previous snippet should be consistent with:
space := BlSpace new.
child := BlElement new.
child background: Color red.
space root addChild: child.
child requestFocus. "<- child is in space already and gets focus instantly"
both examples should have the same effect => order should not influence on result.
Android does give focus to the child during adding:
check:
ViewGroup#addViewInner(View child, int index, LayoutParams params,boolean preventRequestLayout)
...
if (child.hasFocus()) {
requestChildFocus(child, child.findFocus());
}
...
Also check View#requestFocusNoSearch(int direction, Rect previouslyFocusedRect)
which is called from requestFocus
.
It marks View as it "has" or should have focus, but it does not actually receive events.
from bloc.
(Reading the View class is so terrible... I forgot that Android was the king of int & boolean flags )
Ok, we need:
- (1) a way to actually request focus for an
element
attached to a scene graph - (2) an option in
element
to make it potentially the default focus owner when it will be added in the scene graph (it depends on the other elements also marked as needing focus)
Currently requestFocus
only does (1) and maybe we have to provide a more high-level API to handle both (1) and (2) in one way. I don't know if requestFocus
is the right place (and name) to do that.
And we have to consider that:
- We need something like a
focusable
option - We need probably a way to define the order of focusable
elements
during keyboard navigation (children order by default)
from bloc.
(Reading the View class is so terrible... I forgot that Android was the king of int & boolean flags )
Ahahah π
Currently requestFocus only does (1) and maybe we have to provide a more high-level API to handle both (1) and (2) in one way.
Exactly! I absolutely agree. Indeed, it would be really nice to have a uniform way to actually request focus and request request focus (sorry for calembour). I personally think that even current requestFocus with a small modification could work in both (1) and (2) cases.
from bloc.
This is fixed
from bloc.
Related Issues (20)
- BlSpace>>hide doesn't work
- Deprecate BlSpace>>#children
- Remove deprecated geometries
- Wrong cursor in shown SDL2 window
- BlMouseDownEvent subclasses should have a #sendTo: HOT 1
- Rename BlTime to BlClock?
- Review "Priority Queue" HOT 2
- Scaling affects layout HOT 11
- BlPolygonGeometry should take corner radius into account HOT 1
- README doesnβt mention the Bloc UI Framework Demo
- Changes to the methods in the Bloc UI Framework Demo canβt be accepted
- Improve performance of a space with many postponed tasks
- Bug in BlLayout: [Post-mortem] #insets was sent to nil HOT 10
- Ghost windows are not closing + system cleanup feature HOT 4
- BlSharedEventDistributor: Only used by tests? HOT 4
- Ghost window impossible to close (Window SDL2 backend) HOT 2
- Add missing equality HOT 3
- First rules for Bloc HOT 3
- Pass on simulation of events HOT 3
- BlParallelUniverse doesn't seem to dispatch any event
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bloc.