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 Sep 8, 2024
2 parents 9ec18e1 + 7d31434 commit e04e6ca
Show file tree
Hide file tree
Showing 10 changed files with 796 additions and 711 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 21cd51b5a5c512f19c3aa2deebcee4bcf12e0787
* Continue rebasing from 3acee30c0bb2540b2104ee2f803d8cd2844af0b9
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
10 changes: 8 additions & 2 deletions include/guisan/basiccontainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace gcn
{
/**
* A base class for containers. The class implements the most
* common things for a container. If you are implementing a
* common things for a container. If you are implementing a
* container, consider inheriting from this class.
*
* @see Container
Expand Down Expand Up @@ -119,6 +119,7 @@ namespace gcn

virtual Widget *getWidgetAt(int x, int y);

virtual std::list<Widget*> getWidgetsIn(const Rectangle& area, Widget* ignore = NULL);

// Inherited from DeathListener

Expand Down Expand Up @@ -180,7 +181,7 @@ namespace gcn
* @see remove, clear
*/
virtual void clear();

/**
* Draws the children widgets of the basic container.
*
Expand All @@ -205,6 +206,11 @@ namespace gcn
*/
virtual Widget* findWidgetById(const std::string& id);

/**
* Resizes the BasicContainer to fit it's content exactly.
*/
void resizeToContent();

typedef std::list<Widget *> WidgetList;
typedef WidgetList::iterator WidgetListIterator;
typedef WidgetList::reverse_iterator WidgetListReverseIterator;
Expand Down
35 changes: 32 additions & 3 deletions include/guisan/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,29 @@ namespace gcn
* A utility class to ease working with text in widgets such as
* TextBox and TextField. The class wraps common text operations
* such as inserting and deleting text.
*
* @since 1.1.0
*/
class GCN_CORE_DECLSPEC Text
{
public:
/**
* Constructor.
* @since 1.1.0
*/
Text();

/**
* Constructor.
*
* @param content The content of the text.
* @since 1.1.0
*/
Text(const std::string& content);

/**
* Destructor.
* @since 1.1.0
*/
virtual ~Text();

Expand All @@ -84,13 +89,15 @@ namespace gcn
* any previous text and reset the caret position.
*
* @param content The content of the text.
* @since 1.1.0
*/
virtual void setContent(const std::string& text);

/**
* Gets the content of the text.
*
* @return The content of the text.
* @since 1.1.0
*/
virtual std::string getContent() const;

Expand All @@ -99,6 +106,7 @@ namespace gcn
*
* @param row The row to set the text of.
* @throws Exception when the row does not exist.
* @since 1.1.0
*/
virtual void setRow(unsigned int row, const std::string& content);

Expand All @@ -107,6 +115,7 @@ namespace gcn
* not change the current caret position.
*
* @param row The row to add.
* @since 1.1.0
*/
virtual void addRow(const std::string& row);

Expand All @@ -116,13 +125,15 @@ namespace gcn
* @param row The row to get the content of.
* @return The content of a row.
* @throws Exception when no such row exists.
* @since 1.1.0
*/
virtual std::string getRow(unsigned int row) const;

/**
* Inserts a character at the current caret position.
*
* @parameter character The character to insert.
* @param character The character to insert.
* @since 1.1.0
*/
virtual void insert(int character);

Expand All @@ -137,14 +148,16 @@ namespace gcn
* removed the row with the line feed will be merged
* with the row above the line feed.
*
* @numberOfCharacters The number of characters to remove.
* @param numberOfCharacters The number of characters to remove.
* @since 1.1.0
*/
virtual void remove(int numberOfCharacters);

/**
* Gets the caret position.
*
* @return The caret position;
* @return The caret position.
* @since 1.1.0
*/
virtual int getCaretPosition() const;

Expand All @@ -153,6 +166,7 @@ namespace gcn
* clamp to the dimension of the content.
*
* @param position The position of the caret.
* @since 1.1.0
*/
virtual void setCaretPosition(int position);

Expand All @@ -163,20 +177,23 @@ namespace gcn
* @param x The x coordinate of the caret.
* @param y The y coordinate of the caret.
* @param font The font to use when calculating the position.
* @since 1.1.0
*/
virtual void setCaretPosition(int x, int y, Font* font);

/**
* Gets the column the caret is currently in.
*
* @return The column the caret is currently in.
* @since 1.1.0
*/
virtual int getCaretColumn() const;

/**
* Gets the row the caret is currently in.
*
* @return The row the caret is currently in.
* @since 1.1.0
*/
virtual int getCaretRow() const;

Expand All @@ -185,6 +202,7 @@ namespace gcn
* will be clamp to the current row.
*
* @param column The column the caret should be in.
* @since 1.1.0
*/
virtual void setCaretColumn(int column);

Expand All @@ -198,6 +216,7 @@ namespace gcn
* column.
*
* @param row The row the caret should be in.
* @since 1.1.0
*/
virtual void setCaretRow(int row);

Expand All @@ -206,6 +225,7 @@ namespace gcn
*
* @param font The font to use when calculating the x coordinate.
* @return The x coorinate of the caret in pixels.
* @since 1.1.0
*/
virtual int getCaretX(Font* font) const;

Expand All @@ -214,6 +234,7 @@ namespace gcn
*
* @param font The font to use when calculating the y coordinate.
* @return The y coorinate of the caret in pixels.
* @since 1.1.0
*/
virtual int getCaretY(Font* font) const;

Expand All @@ -223,6 +244,7 @@ namespace gcn
*
* @param font The font to use when calculating the dimension.
* @return The dimension in pixels of the text given a font.
* @since 1.1.0
*/
virtual Rectangle getDimension(Font* font) const;

Expand All @@ -233,6 +255,7 @@ namespace gcn
*
* @param font The font to use when calculating the dimension.
* @return The dimension of the caret.
* @since 1.1.0
*/
virtual Rectangle getCaretDimension(Font* font) const;

Expand All @@ -242,13 +265,15 @@ namespace gcn
*
* @param row The row to get the width of.
* @return The width in pixels of a row.
* @since 1.1.0
*/
virtual int getWidth(int row, Font* font) const;

/**
* Gets the maximum row the caret can be in.
*
* @return The maximum row the caret can be in.
* @since 1.1.0
*/
virtual unsigned int getMaximumCaretRow() const;

Expand All @@ -257,20 +282,23 @@ namespace gcn
*
* @param row The row of the caret.
* @return The maximum column of a row the caret can be in.
* @since 1.1.0
*/
virtual unsigned int getMaximumCaretRow(unsigned int row) const;

/**
* Gets the number of rows in the text.
*
* @return The number of rows in the text.
* @since 1.1.0
*/
virtual unsigned int getNumberOfRows() const;

/**
* Gets the number of characters in the text.
*
* @return The number of characters in the text.
* @since 1.1.0
*/
virtual unsigned int getNumberOfCharacters() const;

Expand All @@ -281,6 +309,7 @@ namespace gcn
* @param row The row to get the number of characters in.
* @return The number of characters in a certain row, or zero
* if the row does not exist.
* @since 1.1.0
*/
virtual unsigned int getNumberOfCharacters(unsigned int row) const;

Expand Down
15 changes: 14 additions & 1 deletion include/guisan/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ namespace gcn
virtual bool isModalMouseInputFocused() const;

/**
* Gets a widget from a certain position in the widget.
* Gets a widget at a certain position in the widget.
* This function is used to decide which gets mouse input,
* thus it can be overloaded to change that behaviour.
*
Expand All @@ -836,6 +836,19 @@ namespace gcn
*/
virtual Widget *getWidgetAt(int x, int y);

/**
* Gets all widgets inside a certain area of the widget.
*
* NOTE: This always returns an empty list if the widget is not
* a container.
*
* @param area The area to check.
* @param ignore If supplied, this widget will be ignored.
* @return A list of widgets. An empty list if no widgets was found.
* @since 1.1.0
*/
virtual std::list<Widget*> getWidgetsIn(const Rectangle& area, Widget* ignore = NULL);

/**
* Gets the mouse listeners of the widget.
*
Expand Down
5 changes: 5 additions & 0 deletions include/guisan/widgets/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ namespace gcn
*/
const std::list<Widget*>& getChildren() const;

/**
* Resizes the Container's size to fit te content exactly.
*/
void resizeToContent();

// Inherited from Widget

virtual void draw(Graphics* graphics);
Expand Down
60 changes: 39 additions & 21 deletions src/basiccontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,25 +403,43 @@ namespace gcn
{
Widget* widget = basicContainer->findWidgetById(id);

if (widget != nullptr)
{
return widget;
}
}
}

return nullptr;
}

void BasicContainer::_moveToTopWithNoChecks(Widget* widget)
{
mWidgets.remove(widget);
mWidgets.push_back(widget);
}

void BasicContainer::_moveToBottomWithNoChecks(Widget* widget)
{
mWidgets.remove(widget);
mWidgets.push_front(widget);
}
void BasicContainer::_moveToBottomWithNoChecks(Widget* widget)
{
mWidgets.remove(widget);
mWidgets.push_front(widget);
}

void BasicContainer::resizeToContent()
{
int w = 0, h = 0;

for (WidgetListIterator it = mWidgets.begin(); it != mWidgets.end(); it++)
{
if ((*it)->getX() + (*it)->getWidth() > w)
{
w = (*it)->getX() + (*it)->getWidth();
}

if ((*it)->getY() + (*it)->getHeight() > h)
{
h = (*it)->getY() + (*it)->getHeight();
}
}

setSize(w, h);
}

std::list<Widget*> BasicContainer::getWidgetsIn(const Rectangle& area, Widget* ignore)
{
std::list<Widget*> result;

for (std::list<Widget*>::const_iterator iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
{
Widget* widget = (*iter);
if (ignore != widget && widget->getDimension().isIntersecting(area))
result.push_back(widget);
}

return result;
}
}
Loading

0 comments on commit e04e6ca

Please sign in to comment.