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 » U++ Core » Problem. How to convert AttrText to String?
icon5.gif  Problem. How to convert AttrText to String? [message #27846] Fri, 06 August 2010 11:47 Go to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
Value v=AttrText("text");
String s=v; // ups - invalid conversion RawValueRep<AttrText> -> String
Is something missed?

It happens when I try to insert Values into WithDropChoice<EditString> with Monospace font.
  ...
  list.AddList(AttrText("option 1").SetFont(Monospace()));
  list.AddList(AttrText("option 2").SetFont(Monospace()));
  ...
But when I select string from drop down list I have empty string as a result Shocked

ps: Upp2467

[Updated on: Fri, 06 August 2010 11:53]

Report message to a moderator

Re: Problem. How to convert AttrText to String? [message #27848 is a reply to message #27846] Fri, 06 August 2010 12:44 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
String s;
if(IsType<AttrText>(v)){
	const AttrText& at = ValueTo<AttrText>(v);
	s = at.text.ToString();
}
Re: Problem. How to convert AttrText to String? [message #27859 is a reply to message #27848] Sat, 07 August 2010 01:06 Go to previous messageGo to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
Try this out:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;

struct Example : TopWindow {
	typedef Example CLASSNAME;
	WithDropChoice<EditString> item;
	Example() {
		SetRect(0,0,200,32);Title("Feel the difference");
		item.AddList(AttrText("one").SetFont(Monospace()));
		item.AddList(AttrText("two").SetFont(Monospace()));
		item.AddList(AttrText("three").SetFont(Monospace()));
		item.AddList("1");
		item.AddList("2");
		item.AddList("3");
		item.SetText("zero");
		item.HSizePosZ(8, 8).TopPosZ(8, 19);
		Add(item);
	}
};

GUI_APP_MAIN {
	Example().Run();
}
The question is what should I write to force this work?
Re: Problem. How to convert AttrText to String? [message #27867 is a reply to message #27859] Sat, 07 August 2010 23:33 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
I think you have to create a new Convert class, knowing about AttrText.
Re: Problem. How to convert AttrText to String? [message #27900 is a reply to message #27846] Tue, 10 August 2010 08:24 Go to previous messageGo to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
Why there is no such class?
Could anybody show how to write ValueRep or how to do Value convertor or any example or hint
Re: Problem. How to convert AttrText to String? [message #27909 is a reply to message #27900] Tue, 10 August 2010 15:35 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
Ok, you have to override EditString::SetData method:

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

class MyEditString : public EditString {
public:
	virtual void SetData(const Value& data){
		if(IsType<AttrText>(data)){
			EditString::SetData(ValueTo<AttrText>(data).text.ToString());
		}else{
			EditString::SetData(data);
		}
	}
};

struct Example : TopWindow {
	typedef Example CLASSNAME;
	WithDropChoice<MyEditString> item;
	Example() {
		item.SetDisplay(StdDisplay());
		SetRect(0,0,200,32);Title("Feel the difference");
		item.AddList(AttrText("one").SetFont(Monospace()));
		item.AddList(AttrText("two").SetFont(Monospace()));
		item.AddList(AttrText("three").SetFont(Monospace()));
		item.AddList("1");
		item.AddList("2");
		item.AddList("3");
		item.SetText("zero");
		item.HSizePosZ(8, 8).TopPosZ(8, 19);
		Add(item);
	}
};


GUI_APP_MAIN
{
	Example().Run();
}
Re: Problem. How to convert AttrText to String? [message #28018 is a reply to message #27846] Fri, 13 August 2010 11:00 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kov_serg wrote on Fri, 06 August 2010 05:47

Value v=AttrText("text");
String s=v; // ups - invalid conversion RawValueRep<AttrText> -> String
Is something missed?

It happens when I try to insert Values into WithDropChoice<EditString> with Monospace font.
  ...
  list.AddList(AttrText("option 1").SetFont(Monospace()));
  list.AddList(AttrText("option 2").SetFont(Monospace()));
  ...
But when I select string from drop down list I have empty string as a result Shocked

ps: Upp2467


AttrText was concieved as simple means to put something more formatted to StdDisplay (and thus to everything that is using StdDisplay as default). No further use of such value was expected...
Re: Problem. How to convert AttrText to String? [message #28171 is a reply to message #28018] Fri, 20 August 2010 09:43 Go to previous messageGo to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
I understand.

But the question is how to do combobox with drop down items that have same Monotype font.

What is the simplest solutiong for this problem?

Write my own Display class or write my own WithDropChoice2 or MyEditString with overrided SetData or something different?

[Updated on: Fri, 20 August 2010 09:45]

Report message to a moderator

Re: Problem. How to convert AttrText to String? [message #28404 is a reply to message #28171] Tue, 31 August 2010 19:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kov_serg wrote on Fri, 20 August 2010 03:43

I understand.

But the question is how to do combobox with drop down items that have same Monotype font.

What is the simplest solutiong for this problem?

Write my own Display class or write my own WithDropChoice2 or MyEditString with overrided SetData or something different?


Display class.

Mirek
Re: Problem. How to convert AttrText to String? [message #28411 is a reply to message #28171] Tue, 31 August 2010 22:22 Go to previous message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
Yes, see the Display package in reference assembly.
Previous Topic: Portable Delay() function ?
Next Topic: VectorMap<String,String> = Seg Fault
Goto Forum:
  


Current Time: Thu Apr 25 14:14:50 CEST 2024

Total time taken to generate the page: 0.02888 seconds