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 » U++ Library support » StatusBar&InfoCtrl » howto add more InfoCtrl's to StatusBar?
howto add more InfoCtrl's to StatusBar? [message #214] Sat, 03 December 2005 18:29 Go to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
howto add more InfoCtrl's to StatusBar?
Re: howto add more InfoCtrl's to StatusBar? [message #216 is a reply to message #214] Sun, 04 December 2005 18:11 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
ok, I did this way:

#include <CtrlLib/CtrlLib.h>

class MyStatusBar : public StatusBar {
	InfoCtrl  info2;	
public:
	typedef MyStatusBar CLASSNAME;
	MyStatusBar();
};

MyStatusBar::MyStatusBar()
{	
	AddFrame(info2.Width(250));
	info2="info2: Welcome to the Ultimate++ !";
}


class MyClassWindow : public TopWindow {
private:
	MyStatusBar  status1;
public:
	typedef MyClassWindow CLASSNAME;
	MyClassWindow();
};


MyClassWindow::MyClassWindow()
{
	AddFrame(status1.Height(25));  //can't have in MyStatusBar
}

	
GUI_APP_MAIN
{
 	MyClassWindow().Title("MyClassWindow1").Zoomable().Sizeable().Run();
 	MyClassWindow().SetRect(0, 0, 260, 80);
}


Now the 1. question is: howto change their appearance?
2. howto change default text?
Re: howto add more InfoCtrl's to StatusBar? [message #217 is a reply to message #214] Sun, 04 December 2005 18:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12015
Registered: November 2005
Ultimate Member
fudadmin wrote on Sat, 03 December 2005 12:29

howto add more InfoCtrl's to StatusBar?


Well, to add more "fields" to your StatusBar, do not add InfoCtrl's, but use one of "Set" methods of InfoCtrl (StatusBar is derived from InfoCtrl).

To change the appearance, employ Set variant with PaintRect - you can specify the reference to Display and Value in PaintRect.
Re: howto add more InfoCtrl's to StatusBar? [message #218 is a reply to message #216] Sun, 04 December 2005 18:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12015
Registered: November 2005
Ultimate Member
fudadmin wrote on Sun, 04 December 2005 12:11

ok, I did this way:

#include <CtrlLib/CtrlLib.h>

class MyStatusBar : public StatusBar {
	InfoCtrl  info2;	
public:
	typedef MyStatusBar CLASSNAME;
	MyStatusBar();
};

MyStatusBar::MyStatusBar()
{	
	AddFrame(info2.Width(250));
	info2="info2: Welcome to the Ultimate++ !";
}


class MyClassWindow : public TopWindow {
private:
	MyStatusBar  status1;
public:
	typedef MyClassWindow CLASSNAME;
	MyClassWindow();
};


MyClassWindow::MyClassWindow()
{
	AddFrame(status1.Height(25));  //can't have in MyStatusBar
}

	
GUI_APP_MAIN
{
 	MyClassWindow().Title("MyClassWindow1").Zoomable().Sizeable().Run();
 	MyClassWindow().SetRect(0, 0, 260, 80);
}


Now the 1. question is: howto change their appearance?
2. howto change default text?



While this code is basically, I would like to use it to demonstrate one thing: MyStatusBar in unnecessary - you should rather place "info2" to MyClassWindow.
Re: howto add more InfoCtrl's to StatusBar? [message #219 is a reply to message #218] Sun, 04 December 2005 18:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12015
Registered: November 2005
Ultimate Member
Default text: use InfoCtrl::SetDefault
Re: howto add more InfoCtrl's to StatusBar? [message #232 is a reply to message #218] Sun, 04 December 2005 22:41 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
Quote:


MyStatusBar in unnecessary - you should rather place "info2" to MyClassWindow.



I felt that... but I haven't been successful. What would be the correct way then?
Re: howto add more InfoCtrl's to StatusBar? [message #233 is a reply to message #232] Sun, 04 December 2005 23:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12015
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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12015
Registered: November 2005
Ultimate Member
I have to apologize... this time you understood my code better than me Smile "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 Go to previous messageGo to next message
digodigo is currently offline  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 Smile "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 #14412 is a reply to message #275] Mon, 25 February 2008 20:12 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Hey Mirek,

Any chance you could add a couple of ProgressInfo items to your already crowded StatusBar please?

I use the Temporary space at the left plus two InfoCtrls embedded each one in its own InfoCtrl and added to the right then two more InfoCtrls to display other information also added to the right. Like this

// in header
...
	StatusBar 				status;
	InfoCtrl    			m_pos;
	InfoCtrl				m_val;
	InfoCtrl				m_progHolder1;
	InfoCtrl				m_progHolder2;
	ProgressInfo			m_prog1;
	ProgressInfo			m_prog2;

...

// in TopWindow-derived constructor
...
	AddFrame(status);

	Size sz = GetSize();

	m_prog1 = ProgressInfo(m_progHolder1);
	m_prog2 = ProgressInfo(m_progHolder2);
	m_prog1.Text("");
	m_prog1.Width(10);
	m_prog2.Text("");
	m_prog2.Width(10);
	status.AddFrame(m_progHolder2.Right((sz.cx-300)/2));
	status.AddFrame(m_progHolder1.Right((sz.cx-300)/2));
	
	status.AddFrame(m_val.Right(125));
	m_val.Set("No Value");

	status.AddFrame(m_pos.Right(125));
...


It all used to work but now I don't see m_pos or m_val until I've used at least one of the progress controls to load up a large file using multithreading and posting callbacks.

Is there a way to initialise all these controls so that they are all visible from the start please?

Nick


Re: howto add more InfoCtrl's to StatusBar? [message #14448 is a reply to message #14412] Tue, 26 February 2008 21:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12015
Registered: November 2005
Ultimate Member
I have to say I am confused. Testcase possible?

Mirek
Re: howto add more InfoCtrl's to StatusBar? [message #14520 is a reply to message #14448] Thu, 28 February 2008 17:09 Go to previous message
nixnixnix is currently offline  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

Previous Topic: Statusbar disappears
Next Topic: Using SizeGrip on StatusBar locks mouse on Kubuntu Linux
Goto Forum:
  


Current Time: Mon Sep 16 06:11:40 CEST 2019

Total time taken to generate the page: 0.01496 seconds