summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-03-10 10:13:29 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-03-10 10:13:29 +0100
commit96c3915adeb68d1dd913d38431540eb52d43ff74 (patch)
tree471f6fce88dc042b704c94f039faf757d3155222
parenta6ddfd13f78d8f1a319cc997c81db90bf4b7b8f2 (diff)
Make cursor move at mouse click.
-rw-r--r--plugingui/lineedit.cc14
-rw-r--r--plugingui/lineedit.h8
2 files changed, 19 insertions, 3 deletions
diff --git a/plugingui/lineedit.cc b/plugingui/lineedit.cc
index c799e32..66d1e59 100644
--- a/plugingui/lineedit.cc
+++ b/plugingui/lineedit.cc
@@ -52,6 +52,19 @@ std::string GUI::LineEdit::text()
return _text;
}
+void GUI::LineEdit::buttonEvent(ButtonEvent *e)
+{
+ if(e->direction == 1) {
+ for(int i = 0; i < (int)_text.length(); i++) {
+ if(e->x < (int)(font.textWidth(_text.substr(0, i)) + BORDER)) {
+ pos = i;
+ break;
+ }
+ }
+ repaintEvent(NULL);
+ }
+}
+
void GUI::LineEdit::keyEvent(GUI::KeyEvent *e)
{
bool change = false;
@@ -108,7 +121,6 @@ void GUI::LineEdit::repaintEvent(GUI::RepaintEvent *e)
p.setColour(Colour(0, 0.4));
p.drawFilledRectangle(3,3,width()-3,height()-3);
- Font font;
p.setColour(Colour(1,1,1));
p.drawRectangle(0,0,width()-1,height()-1);
p.drawRectangle(2,2,width()-3,height()-3);
diff --git a/plugingui/lineedit.h b/plugingui/lineedit.h
index f85b7ae..46fa5bc 100644
--- a/plugingui/lineedit.h
+++ b/plugingui/lineedit.h
@@ -31,6 +31,7 @@
#include <string>
#include "widget.h"
+#include "font.h"
namespace GUI {
@@ -44,13 +45,16 @@ public:
void setText(std::string text);
//protected:
- void keyEvent(KeyEvent *e);
- void repaintEvent(RepaintEvent *e);
+ virtual void keyEvent(KeyEvent *e);
+ virtual void repaintEvent(RepaintEvent *e);
+ virtual void buttonEvent(ButtonEvent *e);
protected:
virtual void textChanged() {}
private:
+ Font font;
+
std::string _text;
size_t pos;
};