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 » LineEdit, EditFields, DocEdit » Wrap EditString Rect to text
Wrap EditString Rect to text [message #40900] Sat, 05 October 2013 11:08 Go to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
I use EditString field as a TreeCtrl node for editing like in MS Word's list and for hiding it boundary i use edit.SetFrame(NullFrame()); But
all the same around EditString hidden indents exist. How to wrap border to text?
Re: Wrap EditString Rect to text [message #40919 is a reply to message #40900] Mon, 07 October 2013 20:22 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13467
Registered: November 2005
Ultimate Member
Not sure I understand the question, all seems OK to me. Can you provide example and/or commented screenshot?
Re: Wrap EditString Rect to text [message #40923 is a reply to message #40919] Tue, 08 October 2013 18:39 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Mirek, please check this example
class EditableTree : public TreeCtrl {
public:
	typedef EditableTree CLASSNAME;
	
	EditableTree() : selId_(0) {
		editNode_.SetCtrl(edit_);
		edit_.SetFrame(NullFrame());
		OpenDeep(0, true);
		
		WhenSel = THISBACK(OnSelect);		
	}
	
	void AddNode() {
		CloseEdit();
		
		selId_ = Add(0);
		Open(selId_);
		BeginEdit();
	}
	
	void BeginEdit() {
		editNode_.image = selNode_.image;
		SetNode(selId_, editNode_);
		
		String editval = "NODE" + AsString(selId_);
	   	edit_.SetData(editval);
   		edit_.Show();
    	edit_.AutoSize();
		edit_.SetFocus();//todo: at first not select because IsOpen is false*.
		edit_.SetSelection(editval.GetCount()); 
	}
	
	void CloseEdit() {
		if (selId_ > 0) {
			selNode_.value = ~edit_;
			SetNode(selId_, Node(~edit_));
			edit_.Hide();
		}
	}
	
	void OnSelect()
	{
		CloseEdit();
		selId_ = GetSel()[0];
		selNode_ = GetNode(selId_);
		BeginEdit();
	}
	
private:
	int selId_;
        EditString edit_;
   	Node selNode_;
   	Node editNode_;
};

GUI_APP_MAIN
{	
	TopWindow wnd;
	Button btn;
	wnd.Add(btn.SetLabel("Add").LeftPos(10).TopPos(10));
	
	EditableTree tree;
	wnd.Add(tree.VSizePos(40).HSizePos());

	btn <<= callback(&tree, &EditableTree::AddNode);
    wnd.Run();
}


In edit mode (when select) text shifts in horizontal
Re: Wrap EditString Rect to text [message #40927 is a reply to message #40923] Tue, 08 October 2013 20:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13467
Registered: November 2005
Ultimate Member
OK, that is because internal margin of EditField.

I have now added NoInternalMargin, which removes it. Use

edit_.NoInternalMargin().SetFrame(NullFrame());

Mirek
Re: Wrap EditString Rect to text [message #40942 is a reply to message #40927] Fri, 11 October 2013 09:57 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
http://i051.radikal.ru/1310/db/60428f3ba190.jpg

This code illustrate also a setting user defined font size, where some trouble occur with changing initial text's position
enum {fntSize = 19};

struct AppNodeSize : public Display {
	virtual void Paint(Draw& w,const Rect& r, const Value& q,Color ink,Color paper,dword style) const {
    	w.DrawRect(r, paper);
    	w.DrawText(r.left, r.top, (String)q, StdFont().Height(fntSize), ink);
  	}
  
  	Size GetStdSize(const Value& q) const { 
  		//1.5 is a empirical multiplier for increasing row height when fntSize used in (1) and (2);  		
  		//how to universally set it based on fntSize?
	 	return 1.5 * StdDisplay().GetStdSize(q);
	}
};
	
class EditableTree : public TreeCtrl {
public:
	typedef EditableTree CLASSNAME;
		
	EditableTree() : selId_(0) {
		NoRoot();

		editNode_.SetCtrl(edit_);
		edit_.NoInternalMargin().SetFrame(NullFrame());//crashes when NoInternalMargin
		edit_.SetFont(StdFont().Height(fntSize));//(1)
				
		WhenSel = THISBACK(OnSelect);		
	}
	
	void AddNode() {
		CloseEdit();
		
		//with some ico in /**/ offset lines more visible
		selNode_ = Node(/*espudImg::secExpand(), */"NODE" + AsString(GetChildCount(0) + 1));
		selNode_.SetDisplay(Single<AppNodeSize>());//(2)
                 
        selId_ = Add(0, selNode_);		
		BeginEdit();
	}
			
	void OnSelect() {
		CloseEdit();
		
		selId_ = GetSel()[0];
		selNode_ = GetNode(selId_);

		BeginEdit();
	}
	
private:
	int selId_;
   	Node selNode_;

    EditString edit_;
   	Node editNode_;
   	
	void BeginEdit() {
		editNode_.image = selNode_.image;
		SetNode(selId_, editNode_);

		String val = selNode_.value;	
   		edit_.SetData(val);
    	edit_.AutoSize();
		edit_.Show();
		edit_.SetFocus();
    	edit_.SetSelection(val.GetCount()); 
	}
	
	void CloseEdit() {
		if (selId_ > 0) {
			selNode_.value = ~edit_;
			SetNode(selId_, selNode_);
			edit_.Hide();
		}
	}   	
};

[Updated on: Fri, 11 October 2013 10:00]

Report message to a moderator

Re: Wrap EditString Rect to text [message #40946 is a reply to message #40942] Fri, 11 October 2013 11:46 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Another interesting task of setting the cursor when editing based on the current mouse position, i.e. like in Word's list. Additionaly with selection on hover. This may be a good example future.
Re: Wrap EditString Rect to text [message #40974 is a reply to message #40946] Wed, 16 October 2013 08:35 Go to previous message
mirek is currently offline  mirek
Messages: 13467
Registered: November 2005
Ultimate Member
NoInternalMargin fixed, the method definition you seek is

Size GetStdSize(const Value& q) const {
return GetTextSize((String)q, StdFont().Height(fntSize));
}

However, there are still some minor problems (selected node is vertically shifting); will fix those soon.

Mirek

P.S.: Complete testcase (for my reference):

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

enum {fntSize = 19};

struct AppNodeSize : public Display {
	virtual void Paint(Draw& w,const Rect& r, const Value& q,Color ink,Color paper,dword style) const {
    	w.DrawRect(r, paper);
    	w.DrawText(r.left, r.top, (String)q, StdFont().Height(fntSize), ink);
  	}
  
  	Size GetStdSize(const Value& q) const { 
	 	return GetTextSize((String)q, StdFont().Height(fntSize));
	}
};
	
class EditableTree : public TreeCtrl {
public:
	typedef EditableTree CLASSNAME;
		
	EditableTree() : selId_(0) {
		NoRoot();

		editNode_.SetCtrl(edit_);
		edit_.NoInternalMargin().SetFrame(NullFrame());
		edit_.SetFont(StdFont().Height(fntSize));
				
		WhenSel = THISBACK(OnSelect);		
	}
	
	void AddNode() {
		CloseEdit();
		
		//with some ico in /**/ offset lines more visible
		selNode_ = Node(/*espudImg::secExpand(), */"NODE" + AsString(GetChildCount(0) + 1));
		selNode_.SetDisplay(Single<AppNodeSize>());//(2)
                 
        selId_ = Add(0, selNode_);		
		BeginEdit();
	}
			
	void OnSelect() {
		CloseEdit();
		
		selId_ = GetSel()[0];
		selNode_ = GetNode(selId_);

		BeginEdit();
	}
	
private:
	int selId_;
   	Node selNode_;

    EditString edit_;
   	Node editNode_;
   	
	void BeginEdit() {
		editNode_.image = selNode_.image;
		SetNode(selId_, editNode_);

		String val = selNode_.value;	
   		edit_.SetData(val);
    	edit_.AutoSize();
		edit_.Show();
		edit_.SetFocus();
    	edit_.SetSelection(val.GetCount()); 
	}
	
	void CloseEdit() {
		if (selId_ > 0) {
			selNode_.value = ~edit_;
			SetNode(selId_, selNode_);
			edit_.Hide();
		}
	}   	
};

GUI_APP_MAIN
{	
	TopWindow wnd;
	Button btn;
	wnd.Add(btn.SetLabel("Add").LeftPos(10).TopPos(10));
	
	EditableTree tree;
	wnd.Add(tree.VSizePos(40).HSizePos());

	btn <<= callback(&tree, &EditableTree::AddNode);
    wnd.Run();
}
Previous Topic: Should EditField::Paint respect IsEditable method???
Next Topic: Please help debug this program (Re: EditDouble with customized Convert)
Goto Forum:
  


Current Time: Mon Dec 06 15:55:19 CET 2021

Total time taken to generate the page: 0.01035 seconds