Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Aug 25, 2024
2 parents e6ce273 + cac5cdb commit e8f4929
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Continue rebasing from a154429864dc2a948d29f21cdcdf688177bb54a8
* Continue rebasing from a451b58f3da13d686702689ccbe92c44b8362c6e
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
15 changes: 6 additions & 9 deletions include/guisan/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,9 @@

#include "guisan/platform.hpp"


#ifdef _MSC_VER
#if _MSC_VER <= 1200
#define __FUNCTION__ "?"
#endif
#endif
# ifndef __FUNCTION__
# define __FUNCTION__ "?"
# endif

/*
* A macro used to create a standard exception object.
Expand All @@ -83,9 +80,9 @@ namespace gcn
{
/**
* An exception containing a message, a file and a line number
* where the exception occured. Guisan will only throw exceptions
* of this class.
*
* where the exception occured. Guisan will only throw exceptions
* of this class.
*
* You can use this class for your own exceptions that has
* something to do with a GUI exception. A nifty feature of the
* excpetion class is that it can tell you from which line and
Expand Down
2 changes: 1 addition & 1 deletion include/guisan/widgets/textbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace gcn
*
* @param row The row to add.
*/
virtual void addRow(const std::string row);
virtual void addRow(const std::string& row);

/**
* Checks if the text box is opaque. An opaque text box will draw
Expand Down
23 changes: 22 additions & 1 deletion include/guisan/widgets/textfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ namespace gcn
*/
void adjustHeight();

/**
* Checks if the text field is editable.
*
* @return True it the text field is editable, false otherwise.
* @see setEditable
*/
bool isEditable() const { return mEditable; }

/**
* Sets the text field to be editable or not. A text field is editable
* by default.
*
* @param editable True if the text field should be editable, false
* otherwise.
*/
void setEditable(bool editable) { mEditable = editable; }

/**
* Sets the caret position. As there is only one line of text
* in a text field the position is the caret's x coordinate.
Expand Down Expand Up @@ -145,7 +162,6 @@ namespace gcn
virtual void mousePressed(MouseEvent& mouseEvent);

virtual void mouseDragged(MouseEvent& mouseEvent);


// Inherited from KeyListener

Expand Down Expand Up @@ -184,6 +200,11 @@ namespace gcn
* text needs to scroll in order to show the last type character.
*/
int mXScroll;

/**
* True if the text field is editable, false otherwise.
*/
bool mEditable;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ namespace gcn
return mEditable;
}

void TextBox::addRow(const std::string row)
void TextBox::addRow(const std::string& row)
{
mTextRows.push_back(row);
adjustSize();
Expand Down
12 changes: 6 additions & 6 deletions src/widgets/textfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

namespace gcn
{
TextField::TextField()
TextField::TextField() : mEditable(true)
{
mCaretPosition = 0;
mXScroll = 0;
Expand All @@ -79,7 +79,7 @@ namespace gcn
adjustHeight();
}

TextField::TextField(const std::string& text)
TextField::TextField(const std::string& text) : mEditable(true)
{
mCaretPosition = 0;
mXScroll = 0;
Expand Down Expand Up @@ -128,7 +128,7 @@ namespace gcn
graphics->setColor(getBackgroundColor());
graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));

if (isFocused())
if (isFocused() && isEditable())
{
drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
}
Expand Down Expand Up @@ -183,12 +183,12 @@ namespace gcn
++mCaretPosition;
}

else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size())
else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size() && mEditable)
{
mText.erase(mCaretPosition, 1);
}

else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0)
else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0 && mEditable)
{
mText.erase(mCaretPosition - 1, 1);
--mCaretPosition;
Expand All @@ -210,7 +210,7 @@ namespace gcn
}

else if (key.isCharacter() && key.getValue() != Key::TAB && !keyEvent.isAltPressed()
&& !keyEvent.isControlPressed())
&& !keyEvent.isControlPressed() && mEditable)
{
if (keyEvent.isShiftPressed() && key.isLetter())
{
Expand Down

0 comments on commit e8f4929

Please sign in to comment.