GithubHelp home page GithubHelp logo

Comments (6)

rodrigocfd avatar rodrigocfd commented on June 18, 2024

It seems you are correct, NMLVCUSTOMDRAW should me mutable. Let me know if it's working for you now.

I'm unsure about all other nm_custom_draw being mutable, though.

from winsafe.

mattg23 avatar mattg23 commented on June 18, 2024

That was fast, thank you @rodrigocfd !

I can confirm, it works as expected.

One note: I needed to assign the colors this way:

let txt_clr = COLORREF::new(highlight.fg_color.0, highlight.fg_color.1, highlight.fg_color.2);
unsafe {
    *draw.clrText.as_mut() = txt_clr.raw();
}

If i do it any other way the compiler optimizes it away in release mode 🤷. But i assume that's a skill issue on my side.

from winsafe.

rodrigocfd avatar rodrigocfd commented on June 18, 2024

Won't this work for you?

self.lst_entries.on().nm_custom_draw(|p| {

	let blue = w::COLORREF::new(0x00, 0x00, 0xff);

	p.clrText = blue; // simple assignment!

	// ...

	Ok(co::CDRF::DODEFAULT)
});

from winsafe.

mattg23 avatar mattg23 commented on June 18, 2024

Unfortunately not.
I made a quick repo reproducing the behavior if you want to try it out.
Do you have any ideas what is happening here?

This is a learning project for me, so it's not a problem if i have to use unsafe.
But it would be nice to understand what exactly is going on here.

Edit: Added a profile with lto to the repo. This removes all colors, even the unsafe version doesn't work.

from winsafe.

rodrigocfd avatar rodrigocfd commented on June 18, 2024

The root cause was way deeper than the message handling itself. The lambda parameter was originally const, then later cast to mutable, thus causing undefined behavior.This is a rule that comes from C++, which I fortunately already faced in my C++ days.

I still don't know how this change will propagate throughout all WM_NOTIFY events, but so far everything seems fine.

Your example is working for me with all profiles now. Let me know if it works for you.

from winsafe.

mattg23 avatar mattg23 commented on June 18, 2024

I've done some small testing with max optimizations enabled.
So far everything works fine. Thank you so much for the support!

Also thanks for the info. I checked your changes and the stackoverflow post you linked.
This makes sense to me now.

I still have a bunch of features to implement, so i keep an eye out for anything suspicious.

from winsafe.

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.