Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Question on a widget on top of a widget **BUG STATEMENTS NOT COMPLETED BEFORE NEXT STATEMENT
icon8.gif  Question on a widget on top of a widget **BUG STATEMENTS NOT COMPLETED BEFORE NEXT STATEMENT [message #33281] Fri, 22 July 2011 13:38 Go to next message
silverx is currently offline  silverx
Messages: 62
Registered: March 2011
Member
How do I have a widget appear on top of another widget. Example a push button that is large, that has another widget on top of it that is currently .Show(false), but when you push the button, it changes the .Show(true) for the other widget.

I want to keep the push button there and be visible.

I have tried, all kinds of refresh and it still doesn't work?

I can post the complete code but it is kind of long.

[Updated on: Fri, 22 July 2011 21:40]

Report message to a moderator

Re: Question on a widget on top of a widget [message #33287 is a reply to message #33281] Fri, 22 July 2011 16:16 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi silverx,

If I understand correctly, you wan't to do something like this:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;

class App:public TopWindow {
	typedef App CLASSNAME;
	Button b;
	EditString e;
public:
	App(){
		b.SetLabel("Click me!"); //set the button text
		Add(b.HCenterPos(100).VCenterPosZ(30)); //add button to the window
		b.Add(e.HCenterPos(80).VCenterPos(20)); //add editfield to the button,
		                                        //positioning is relative to the button
		b<<=THISBACK(SwitchEdit);  // assign function to the button click
		e.Hide();                  // hide the editfield initialy
	}
	void SwitchEdit(){
		e.Show(!e.IsShown()); // switch the visibility
	}
};

GUI_APP_MAIN{
	App().Sizeable().Run();
}


As you can see, you can just easily Add a Ctrl into any other Ctrl. Simple solutions are often the best Wink

Best regards,
Honza

PS: Forgot to mention that if you're using layouts, you can use the button from layout, but the "second layer" ctrl must be added in code. (Well, actually you COULD, but it is bit more complicated and seldom necessary...). Also, you can add more than one widget or even entire layout.

[Updated on: Fri, 22 July 2011 16:21]

Report message to a moderator

Re: Question on a widget on top of a widget [message #33288 is a reply to message #33287] Fri, 22 July 2011 17:02 Go to previous messageGo to next message
silverx is currently offline  silverx
Messages: 62
Registered: March 2011
Member
Thanks for the information, but it still didn't work.

What is the difference between .Hide and .Show(false)?

That is what I was using. The other thing is all items where added from layout and not from any code. Why should that make any difference?

I would prefer to build it in Layout instead of in code, if possible.

But if I do set it in code I need to set the size and position with .SetRect, is the x and y based upon the item it is added to?


Also I tried your code, but changing from App to T5, Code is:

#include <CtrlLib/CtrlLib.h>
using namespace Upp;

class T5:public TopWindow {
typedef T5 CLASSNAME;
Button b;
EditString e;
public:
T5(){
b.SetLabel("Click me!"); //set the button text
Add(b.HCenterPos(100).VCenterPosZ(30)); //add button to the window
b.Add(e.HCenterPos(80).VCenterPos(20)); //add editfield to the button,
//positioning is relative to the button
b<<=THISBACK(SwitchEdit); // assign function to the button click
e.Hide(); // hide the editfield initialy
}
void SwitchEdit(){
e.Show(!e.IsShown()); // switch the visibility
}
};

GUI_APP_MAIN{
T5().Sizeable().Run();
}

And I get the following error:

t5: 1 file(s) built in (0:02.35), 2356 msecs / file, duration = 2356 msecs, parallelization 0%
Linking...
LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\upp\out\MSC9.Debug.Debug_full\t5.exe : fatal error LNK1120: 1 unresolved externals

There were errors. (0:02.88)


In addition I tried to do the add of the object in my code to my program, and just set position and FrameSet so I could see it. When I execute the code it does show up, but then when I start using it, it never comes back. The only way it shows up is if I do a PromptOK after I do the .Show.

I did the add in code using the following. It is for my own widget, that I have defined, after button.

W1.Add(E1.HCenterPos(10).VCenterPos(10));
W2.Add(E2.HCenterPos(10).VCenterPos(10));

E1.SetFrame(BlackFrame());
E2.SetFrame(BlackFrame());

I am using a image in the both cases, I just want the second image to show up for about 1 second then hide it again on top of the other image.


I think it is a bug on Windows Vista.
Re: Question on a widget on top of a widget [message #33289 is a reply to message #33288] Fri, 22 July 2011 17:48 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

silverx wrote on Fri, 22 July 2011 17:02

What is the difference between .Hide and .Show(false)
There is no difference, Hide() exists just for convenience.

silverx wrote on Fri, 22 July 2011 17:02

That is what I was using. The other thing is all items where added from layout and not from any code. Why should that make any difference?

I would prefer to build it in Layout instead of in code, if possible.
Everything in layout is automatically Add()ed to the TopWindow. Well, IIRC, calling Add() on already added Ctrl is legal (it calls remove first), so theoretically you can put it in layout, but you still need to call the Add() in the code and probably also reposition it.

silverx wrote on Fri, 22 July 2011 17:02

But if I do set it in code I need to set the size and position with .SetRect, is the x and y based upon the item it is added to?
Yes, everything is then positioned relatively to the top-left corner of the parent Ctrl.

silverx wrote on Fri, 22 July 2011 17:02

Also I tried your code, but changing from App to T5, Code is:

...

And I get the following error:

t5: 1 file(s) built in (0:02.35), 2356 msecs / file, duration = 2356 msecs, parallelization 0%
Linking...
LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\upp\out\MSC9.Debug.Debug_full\t5.exe : fatal error LNK1120: 1 unresolved externals

There were errors. (0:02.88)

You forget to add a GUI flag Wink

silverx wrote on Fri, 22 July 2011 17:02

In addition I tried to do the add of the object in my code to my program, and just set position and FrameSet so I could see it. When I execute the code it does show up, but then when I start using it, it never comes back. The only way it shows up is if I do a PromptOK after I do the .Show.

I did the add in code using the following. It is for my own widget, that I have defined, after button.

W1.Add(E1.HCenterPos(10).VCenterPos(10));
W2.Add(E2.HCenterPos(10).VCenterPos(10));

E1.SetFrame(BlackFrame());
E2.SetFrame(BlackFrame());

I am using a image in the both cases, I just want the second image to show up for about 1 second then hide it again on top of the other image.


I think it is a bug on Windows Vista.


I don't see anything wrong with the posted line, the problem is probably somewhere else. Can't say where without seeing more of the code. Anyway, I am pretty sure that it is not related to Windows Smile

Honza
Re: Question on a widget on top of a widget [message #33291 is a reply to message #33289] Fri, 22 July 2011 19:16 Go to previous messageGo to next message
silverx is currently offline  silverx
Messages: 62
Registered: March 2011
Member
Here is the code. I added the hide and Show buttons, they work, but when I run the code and do the start it loads a question and some pictures on to the window. Select the right or wrong answer should result in E1 or E2 showing either a green block or a red X block on top of the item.

It is supposed to wait 1 second before going onto the next question, while showing the right or wrong answer. If you do the right answer it goes to another question. If not, it stays there and waits for you to select the correct answer.

Thanks

David
icon8.gif  Re: Question on a widget on top of a widget [message #33293 is a reply to message #33291] Fri, 22 July 2011 21:38 Go to previous messageGo to next message
silverx is currently offline  silverx
Messages: 62
Registered: March 2011
Member
It appears that the code to do things stop working when I have Sleep(x) after the command.

Things are not processed in order, and continue with the next command after the previous command is completed.

To me this is a bug in the system. It should complete the previous command before starting the next command.

Any way to force a commands to complete before starting the next command in the program?

David
Re: Question on a widget on top of a widget [message #33294 is a reply to message #33293] Fri, 22 July 2011 23:07 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

silverx wrote on Fri, 22 July 2011 21:38

It appears that the code to do things stop working when I have Sleep(x) after the command.

Things are not processed in order, and continue with the next command after the previous command is completed.

To me this is a bug in the system. It should complete the previous command before starting the next command.

Any way to force a commands to complete before starting the next command in the program?

David

Yes this is one of the problems. It is not a bug, it works exactly as intended. Sleep just sleeps, halting all the code execution. To force the changes to be drawn to screen, you can call Sync() method, which causes all the areas marked to be refreshed to be redrawn.

The second thing is that overriding the Paint() method seems like an overkill, at least in the example code you sent. You are using SetImage to cover the entire area of button, so the changes you did to the painting routine are not visible anyway. And if I understood it correctly the only intention was to hide the borders, which can be achieved in simpler way just by calling Hide() in constructor and Show() when starting the quiz Wink

Honza
Re: Question on a widget on top of a widget [message #33335 is a reply to message #33294] Mon, 25 July 2011 15:27 Go to previous message
silverx is currently offline  silverx
Messages: 62
Registered: March 2011
Member
The use of the Sync() did it. And I had to change to use code to add the widgets, but it worked great.

thank you.
Previous Topic: adding version and company info?
Next Topic: Block indent and dedent
Goto Forum:
  


Current Time: Fri Apr 19 23:17:30 CEST 2024

Total time taken to generate the page: 0.06006 seconds