Hey RDS. I like Myra, it’s a nice framework. I’ve been studying your source code and borrowing ideas here and there for some of my own project work. While playing around with things I came across a need to implement some focus switching/handling logic in my own game and looked to Myra source code for any inspiration.
If it wouldn’t be a problem, maybe you could enlighten me on a few details? This question also relates to using Myra itself, so this question isn’t 100% self serving and might be useful for others to know as well. : )
The way which a Window(or any Widget) handles focus generally seems to be that the Desktop environment checks its internal ‘_widgets’ observable collection and iterates through it (GetActiveWidget()) and grabs the first widget which is set IsEnabled and IsVisible.
What manner do you go about changing the active focus if there are multiple windows in the desktop environment? I did try to find an answer to this but couldn’t find anything here or in the documentation. As near as I can tell, GetActiveWidget() only ever grabs the first widget even if other windows are enabled and visible.
for (var i = ChildrenCopy.Count - 1; i >= 0; --i)
{
var w = ChildrenCopy[i];
if (w.Visible && w.Enabled)
{
return w;
}
}
^ This block here. If there are 3 active windows on the desktop, only the first one in the collection is grabbed and given input priority. The only means I see of controlling which window has current input focus(input focus meaning accepting mouse button clicks to change active window) would be to re-order the widgets in the desktop’s environment. Or, programatically setting IsEnabled to false outside the Myra API to change which windows get skipped by GetActiveWidget (is that the intended method?) Only problem with the latter method is that in order to set that window back to Enabled, it needs to know when it’s being clicked on, and I don’t see a way to natively do this as now that it’s disabled it can no longer receive any mouse events of any kind. I could circumvent the Myra API and do this with my own code, but that feels a bit like a hack and that I must be missing something.
It’s late and I’ve been awake a long time so I feel like I’m being dumb or something, lol. But if you have a minute, I’d be interested to hear from you. Thanks.