|
|
Home » U++ Library support » StatusBar&InfoCtrl » howto add more InfoCtrl's to StatusBar?
|
|
|
|
|
|
Re: howto add more InfoCtrl's to StatusBar? [message #233 is a reply to message #232] |
Sun, 04 December 2005 23:07 |
|
mirek
Messages: 14059 Registered: November 2005
|
Ultimate Member |
|
|
Quote: |
I felt that... but I haven't been successful. What would be the correct way then?
|
#include <CtrlLib/CtrlLib.h>
class MyClassWindow : public TopWindow {
private:
StatusBar status1; //edited: was MyStatusBar
InfoCtrl info2;
public:
typedef MyClassWindow CLASSNAME;
MyClassWindow();
};
MyClassWindow::MyClassWindow()
{
status1.AddFrame(info2.Width(250));
info2="info2: Welcome to the Ultimate++ !";
AddFrame(status1.Height(25));
}
GUI_APP_MAIN
{
MyClassWindow().Title("MyClassWindow1").Zoomable().Sizeable().Run();
MyClassWindow().SetRect(0, 0, 260, 80);
}
Note once again that this is basically the wrong code - I am just demonstrating that in similar situation, creating separate class is not necessarry - and not creating it is better, as you will have to access that "info2" from MyClassWindow anyway.
The lesson to learn is that in U++, class composition does not have to follow GUI hierarchy. It is not uncommon to e.g. have TopWindow as member variable and put "self" into it:
struct Foo : Button {
TopWindow win;
void Perform() { win.Run(); }
Foo() {
win.Add(SizePos());
}
};
[Updated on: Mon, 05 December 2005 11:09] by Moderator Report message to a moderator
|
|
|
Re: howto add more InfoCtrl's to StatusBar? [message #275 is a reply to message #233] |
Mon, 05 December 2005 22:51 |
|
mirek
Messages: 14059 Registered: November 2005
|
Ultimate Member |
|
|
I have to apologize... this time you understood my code better than me "Set" is further level of division, you are really supposed to use AddFrame to add more "fields".
I have created this nice reference example to demonstrate StatusBar:
#include <CtrlLib/CtrlLib.h>
struct PosDisplay : Display {
Color color;
virtual void Paint(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const {
int i = q;
w.DrawRect(0, 0, i, r.Height(), color);
w.DrawRect(i, 0, r.Width() - i, r.Height(), SWhite);
}
};
struct App : TopWindow {
StatusBar status;
InfoCtrl pos;
InfoCtrl x, y;
PosDisplay dx, dy;
virtual void MouseMove(Point p, dword)
{
pos.Set(0, AsString(p.x), 40);
pos.Set(1, AsString(p.y), 40);
x.Set(PaintRect(dx, 100 * p.x / GetSize().cx));
y.Set(PaintRect(dy, 100 * p.y / GetSize().cy));
}
virtual void LeftDown(Point, dword)
{
status.Temporary("Left mouse button pressed!");
}
App() {
Sizeable();
SetFrame(FieldFrame());
AddFrame(status);
status.AddFrame(pos.Right(100));
status.AddFrame(x.Left(100));
status.AddFrame(y.Left(100));
dx.color = LtRed;
dy.color = LtGreen;
}
};
GUI_APP_MAIN
{
App().Run();
}
Once again, sorry for misinformation, last time I visited StatusBar was two years ago and never used it above simple assigning text to it....
|
|
|
Re: howto add more InfoCtrl's to StatusBar? [message #12940 is a reply to message #275] |
Thu, 29 November 2007 15:29 |
digodigo
Messages: 4 Registered: November 2007
|
Junior Member |
|
|
luzr wrote on Mon, 05 December 2005 22:51 | I have to apologize... this time you understood my code better than me "Set" is further level of division, you are really supposed to use AddFrame to add more "fields".
I have created this nice reference example to demonstrate StatusBar:
#include <CtrlLib/CtrlLib.h>
struct PosDisplay : Display {
Color color;
virtual void Paint(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const {
int i = q;
w.DrawRect(0, 0, i, r.Height(), color);
w.DrawRect(i, 0, r.Width() - i, r.Height(), SWhite);
}
};
struct App : TopWindow {
StatusBar status;
InfoCtrl pos;
InfoCtrl x, y;
PosDisplay dx, dy;
virtual void MouseMove(Point p, dword)
{
pos.Set(0, AsString(p.x), 40);
pos.Set(1, AsString(p.y), 40);
x.Set(PaintRect(dx, 100 * p.x / GetSize().cx));
y.Set(PaintRect(dy, 100 * p.y / GetSize().cy));
}
virtual void LeftDown(Point, dword)
{
status.Temporary("Left mouse button pressed!");
}
App() {
Sizeable();
SetFrame(FieldFrame());
AddFrame(status);
status.AddFrame(pos.Right(100));
status.AddFrame(x.Left(100));
status.AddFrame(y.Left(100));
dx.color = LtRed;
dy.color = LtGreen;
}
};
GUI_APP_MAIN
{
App().Run();
}
Once again, sorry for misinformation, last time I visited StatusBar was two years ago and never used it above simple assigning text to it....
|
THANKS CHAMPZ !!!
it's did help me too !!!
|
|
|
|
|
Re: howto add more InfoCtrl's to StatusBar? [message #14520 is a reply to message #14448] |
Thu, 28 February 2008 17:09 |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Yes I was too. A test case might be tricky to make as it only stopped working recenty. However, I do have some news which might help your confusion.
When I replace the term (sz.cx-300)/2) with the number 300 say, it all works fine. I thought this could be a number thing. However, when I replace it with this
int n = (sz.cx-300)/2;
status.AddFrame(m_progHolder2.Right(n));//(sz.cx-300)/2));
status.AddFrame(m_progHolder1.Right(n));//(sz.cx-300)/2));
it still doesn't work but when I do this
int n = max(200,(sz.cx-300)/2);
status.AddFrame(m_progHolder2.Right(n));//(sz.cx-300)/2));
status.AddFrame(m_progHolder1.Right(n));//(sz.cx-300)/2));
it works fine so I guess that using GetSize() in the TopWindow constructor is a bad idea and that it doesn't actually have a size till later. Thing is though this code used to work. I can live with it either way so if you think a bug has slipped in or not thats fine with me.
Nick
[Updated on: Thu, 28 February 2008 17:10] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Oct 12 12:09:15 CEST 2024
Total time taken to generate the page: 0.03284 seconds
|
|
|