Giter Site home page Giter Site logo

Focus Issues about tgui HOT 1 CLOSED

CasualYT31 avatar CasualYT31 commented on August 26, 2024
Focus Issues

from tgui.

Comments (1)

texus avatar texus commented on August 26, 2024 1

Thanks again for the detailed information on what happens and figuring out where the issue lies.

After looking into this I believed that you fix was the best option (although I was going to apply the fix directly in Widget::setFocused as the other location where canGainFocus is called doesn't require the recursive check). However, I accidentally fixed it in a completely different way.

I changed the order of operations in all widgets that override the setFocused function. Instead of letting TextArea set its m_caretVisible to true and then changing the focused state with the Widget::setFocused call, I decided to first call Widget::setFocused and only set m_caretVisible to true if m_focused actually became true (which wouldn't be the case with your canGainFocus patch). Doing the same in the Container class has a very surprising side-effect: failing to focus the container would unfocus its child widgets.

So the following now happens:

  • You call TextArea::setFocused
  • The text area tells its parent that is has been focused
  • The container tries to focus itself but fails because it is disabled
  • The container notices that the text area is focused and tells it to unfocus (at the end of Container::setFocused)

This means that edit box ends up unfocused, without changing how canGainFocus works. Hopefully the change I just made doesn't break a bunch of other situations though.

the caret will not show (I assume this is because its immediate parent no longer has a focused widget?

This is because Widget::setFocused won't set m_focused to true if canGainFocus returns false. The caret is only shown when both m_caretVisible and m_focused are true. Technically m_caretVisible is never supposed to be true when m_focused is false, but the value of m_caretVisible is simply ignored if m_focused is false so it still worked correctly even though m_caretVisible was wrong.

Which I think makes the most sense, even if it might cause confusion if one attempts to invoke setFocused(true) on an indirectly disabled widget.

It agree that not allowing the focus is the best solution. It's easy to explain why focusing doesn't work in that case, and it can be easily implemented.

I feel like it would be nice to be able to apply set focus once the Group is re-enabled, though I imagine this will be more complicated

Yeah, that would probably be too complex to implement, and the focusing code is already quite complicated.

from tgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.