Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Apply Guichan's changes from b50089aa71c0625f5273c468ac169b71f8bba6… #61

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}