Hello everyone. I have very little experience, so I’m asking for advice. I need to place a child component on the desktop next to the main component on the right using ComponentPeer. I was trying to find a way to get the parent component’s coordinates relative to the desktop. The only thing I could come up with was placing a timer listener on the DocumentWindow, passing the values via getWindowStateAsString() to global variables, and using them in MainComponent. Everything works perfectly, but I have some doubts: am I doing it correctly? Is it acceptable to use a timer in a DocumentWindow? Maybe there is another way without a timer? The code is below.
Main.h (DocumentWindow)
void timerCallback() override
{
String a = getWindowStateAsString();
StringArray pos;
pos = StringArray::fromTokens (a, " ", {});
pX = pos[0].getIntValue();
pY = pos[1].getIntValue();
}
MainComponent.cpp
void GUI::MainComponent::displaySyncManager() //SYNC
{
showSyncCompInt = 1;
syncComponent.syncPlayer.dragComp.syncPlayerFontInt = 1;
syncComponent.addToDesktop (ComponentPeer::windowIsResizable | ComponentPeer::windowIgnoresKeyPresses);
thuComp_S->addToDesktop (ComponentPeer::windowIsResizable | ComponentPeer::windowIgnoresKeyPresses);
#if JUCE_WINDOWS
syncComponent.setBounds (getWidth() + pX + 1, pY - 29, 600, 230);
thuComp_S->setBounds (getWidth() + pX + 1, 231 + pY - 29, 600, 49);
#else
syncComponent.setBounds (getWidth() + pX + 1, pY - 20, 600, 230);
thuComp_S->setBounds (getWidth() + pX + 1, 231 + pY - 20, 600, 49);
#endif
syncComponent.loadSync();
syncComponent.setVisible (true);
thuComp_S->setVisible (true);
}
And one more thing. ComponentPeer::windowIsResizable works on Mac OS, but not on Windows. Why?
I would be glad to receive any advice.
