How to scroll to a specific element in ScrollRect with Unity UI?

I am going to give you a code snippet of mine because I feel like being helpful. Hope this helps! protected ScrollRect scrollRect; protected RectTransform contentPanel; public void SnapTo(RectTransform target) { Canvas.ForceUpdateCanvases(); contentPanel.anchoredPosition = (Vector2)scrollRect.transform.InverseTransformPoint(contentPanel.position) – (Vector2)scrollRect.transform.InverseTransformPoint(target.position); }

Get HWND on windows with Qt5 (from WId)

In Qt5 winEvent was replaced by nativeEvent: bool winEvent(MSG* pMsg, long* result) is now bool nativeEvent(const QByteArray & eventType, void * message, long *result) And in EcWin7::winEvent you have to cast void to MSG: bool EcWin7::winEvent(void * message, long * result) { MSG* msg = reinterpret_cast<MSG*>(message); if (msg->message == mTaskbarMessageId) { … I was able … Read more

Is it safe to construct Swing/AWT widgets NOT on the Event Dispatch Thread?

Sun has changed the rules in 2004 — before, you were allowed to create the components outside the EDT and only had to move into the EDT once the component had been realized. The new rule now reads: To avoid the possibility of deadlock, you must take extreme care that Swing components and models are … Read more

Given a background color, how to get a foreground color that makes it readable on that background color?

Here’s one I did in both Java and Javascript. It’s loosely based off this one in javascript. I took the Luminance formula from here. The sweet-spot of the threshold from my eye was about 140. Java version: public class Color { private float CalculateLuminance(ArrayList<Integer> rgb){ return (float) (0.2126*rgb.get(0) + 0.7152*rgb.get(1) + 0.0722*rgb.get(2)); } private ArrayList<Integer> … Read more