Coder Social home page Coder Social logo

Comments (6)

MrGVSV avatar MrGVSV commented on June 12, 2024

Does it panic if you move that same resource access into a custom widget?

My guess is that we actually don't have access to World at this point.

from kayak_ui.

Psikik avatar Psikik commented on June 12, 2024

Seems to be that way. I hadn't yet ventured into custom widgets yet. Building a custom widget that checks world.is_err() as in the full_ui example does not panic.

from kayak_ui.

MrGVSV avatar MrGVSV commented on June 12, 2024

Hm, yeah it probably is:

pub fn new<F: Fn(&mut KayakContext)>(f: F) -> Self {
let kayak_context = Arc::new(RwLock::new(KayakContext::new()));
if let Ok(mut kayak_context) = kayak_context.write() {
f(&mut kayak_context);
kayak_context.widget_manager.dirty(true);
}
Self { kayak_context }
}

I think the only way to achieve this unfortunately would be to do so within a widget— where World access is guaranteed— rather than within the constructor function for BevyContext.

This means that we should probably make query_world a pub(crate) access instead of a pub one so other users don't stumble upon the same issue. This should be okay since the only pub access (that I know of) is here:

context.query_world::<(
EventReader<CursorMoved>,
EventReader<MouseButtonInput>,
EventReader<ReceivedCharacter>,
EventReader<KeyboardInput>,
), _, _>(

So that will probably need to be dealt with as well (perhaps by just simply moving the process_event system into the update system).

from kayak_ui.

StarArawn avatar StarArawn commented on June 12, 2024

BevyContext::new( wont have access to world here. Another suggestion would be to load in the resource via the create_ui system.

from kayak_ui.

MrGVSV avatar MrGVSV commented on June 12, 2024

Another suggestion would be to load in the resource via the create_ui system.

Actually, yeah this might be a simpler solution assuming you can pass the resource into the closure (which is probably trivial for your RandomResource type since it could implement Copy).

from kayak_ui.

StarArawn avatar StarArawn commented on June 12, 2024

Since solutions to the problem above have been suggested I'm going to close this for now. Feel free to open up a new issue if you feel there is more to do here.

from kayak_ui.

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.