Skip to content

Commit

Permalink
* Apply Guichan's changes from b50089aa71c0625f5273c468ac169b71f8bba6…
Browse files Browse the repository at this point in the history
…64 (August 28th 2008)

Widget::getTop has been added.
  • Loading branch information
Jarod42 committed Aug 31, 2024
1 parent fd9c3bc commit 9e556f9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 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 b50089aa71c0625f5273c468ac169b71f8bba664
* Continue rebasing from 8090b4fbd0cb73c092307a5b551929275b8aef5a
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
24 changes: 19 additions & 5 deletions include/guisan/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ namespace gcn
*/
virtual Widget* getParent() const;

/**
* Gets the top widget, or top parent, of this widget.
*
* @return The top widget, or top parent, of this widget.
* NULL if no top widget exists
* (that is this widget doesn't have a parent).
* @since 1.1.0
*/
virtual Widget* getTop() const;

/**
* Sets the width of the widget.
*
Expand Down Expand Up @@ -883,37 +893,41 @@ namespace gcn
* Moves a widget to the top of this widget. The moved widget will be
* drawn above all other widgets in this widget.
*
* This method is safe to call at any times.
*
* @param widget The widget to move to the top.
* @see moveToBottom
* @since 0.1.0
*/
virtual void moveToTop(Widget* widget) { };
virtual void moveToTop(Widget* widget) {}

/**
* Moves a widget in this widget to the bottom of this widget.
* The moved widget will be drawn below all other widgets in this widget.
*
* This method is safe to call at any times.
*
* @param widget The widget to move to the bottom.
* @see moveToTop
* @since 0.1.0
*/
virtual void moveToBottom(Widget* widget) { };
virtual void moveToBottom(Widget* widget) {}

/**
* Focuses the next widget in the widget.
*
* @see moveToBottom
* @since 0.1.0
*/
virtual void focusNext() { };
virtual void focusNext() {}

/**
* Focuses the previous widget in the widget.
*
* @see moveToBottom
* @since 0.1.0
*/
virtual void focusPrevious() { };
virtual void focusPrevious() {}

/**
* Tries to show a specific part of a widget by moving it. Used if the
Expand All @@ -923,7 +937,7 @@ namespace gcn
* @param area The area to show.
* @since 0.1.0
*/
virtual void showWidgetPart(Widget* widget, Rectangle area) { };
virtual void showWidgetPart(Widget* widget, Rectangle area) {}

/**
* Sets an id of a widget. An id can be useful if a widget needs to be
Expand Down
16 changes: 16 additions & 0 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,20 @@ namespace gcn
mParent->showWidgetPart(this, rectangle);
}
}

Widget* Widget::getTop() const
{
if (getParent() == NULL) return NULL;

Widget* widget = getParent();
Widget* parent = getParent()->getParent();

while (parent != NULL)
{
widget = parent;
parent = parent->getParent();
}

return widget;
}
}

0 comments on commit 9e556f9

Please sign in to comment.