|
|
Home » Community » Newbie corner » LineEdit event on click on scrollbar
LineEdit event on click on scrollbar [message #38965] |
Thu, 31 January 2013 01:20  |
mircerlancerous
Messages: 4 Registered: January 2013
|
Junior Member |
|
|
Hey I'm looking for a way to get an event to trigger on a click of the LineEdit scrollbar. The leftdown even doesn't trigger unless you're actually clicking in the main field. Maybe I'm missing something easy?
While we're at it a quick example of how to add the leftdown event to the LineEdit (through subclassing?) would help as I had to make a bit of an ugly hack to get it to go.
Thanks.
|
|
|
|
|
Re: LineEdit event on click on scrollbar [message #38969 is a reply to message #38968] |
Fri, 01 February 2013 02:01   |
navi
Messages: 107 Registered: February 2012 Location: Sydney, Australia
|
Experienced Member |
|
|
mircerlancerous wrote on Fri, 01 February 2013 01:01 | Now I'm confused. Does all that code go in the main app or in the LineEdit.cpp or TestEdit.h?
|
nothing ever goes into LineEdit.cpp or any other u++ source files in that matter. Never change U++ source files. bad idea.
What we are doing here is Extending the LineEdit Class of U++. you can either put that extended class definitional in you in a separate .h/cpp file or can even put in a separate project to use as sup-projects in multiple apps.
Quote: | output.WhenScrollChange << THISBACK(ScrollLeftDown);
|
you got the operator wrong. In this case "=" not "<<"
output.WhenScrollChange = THISBACK(ScrollChange);
Here is a full example. In this example we have 2 LineEditExtended ctrl. we used the 'e' ctrls callback trigger to set the scroll pos for 'f' ctrl. meaning when e scrolls, f scroll with e. but f's WhenScrollChange is not used so f can scroll independently. for 'f' we set the callback to scrollbar's left click using the function SetScrollbarLeftClickCallback() that we added in LineEditExtended. if 'f' scroll bar is clicked, it prompts a message box.
note 'e' is the one on the left and 'f' is the one on the right.
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class LineEditExtended : public LineEdit{
public:
void SetScrollbarLeftClickCallback(Callback cb){ sb.WhenLeftClick=cb; }
virtual void NewScrollPos(){ WhenScrollChange();}
Callback WhenScrollChange;
};
class mywindow : public TopWindow{
typedef mywindow CLASSNAME;
public:
mywindow();
void When_e_Scroll(){ f.SetScrollPos(e.GetScrollPos()); }
void When_f_Scroll_click() { PromptOK("Scroll Bar click"); }
private:
LineEditExtended e,f;
};
mywindow::mywindow()
{
String s;
SetRect(0,0,430,200);
e.LeftPos(10, 200).VSizePos(10,10);
f.RightPos(10, 200).VSizePos(10,10);
for(int i=0; i<100; i++) s<<"Hello World! #"<<i<<"\n";
e.Set(s);
f.Set(s);
e.WhenScrollChange=THISBACK(When_e_Scroll);
f.SetScrollbarLeftClickCallback(THISBACK(When_f_Scroll_click));
this<<e<<f;
}
GUI_APP_MAIN
{
mywindow().Run();
}
see these for more example on callbacks. Basic Callbacks, callback section in overview
Attach is the same code as Upp project.
regards
navi
[Updated on: Fri, 01 February 2013 02:28] Report message to a moderator
|
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 01:47:16 CEST 2025
Total time taken to generate the page: 0.03697 seconds
|
|
|