2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2024-06-10 02:25:43 +08:00
|
|
|
https://axmol.dev/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UIHELPER_H__
|
|
|
|
#define __UIHELPER_H__
|
|
|
|
|
|
|
|
#include <string>
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/PlatformMacros.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "2d/Node.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
|
|
|
|
class Widget;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper class for traversing children in widget tree.
|
|
|
|
* It also provides some helper functions for layout.
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_GUI_DLL Helper
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Find a widget with a specific tag from root widget.
|
|
|
|
* This search will be recursive through all child widgets.
|
|
|
|
* @param root The be searched root widget.
|
|
|
|
* @param tag The widget tag.
|
|
|
|
* @return Widget instance pointer.
|
|
|
|
*/
|
|
|
|
static Widget* seekWidgetByTag(Widget* root, int tag);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Find a widget with a specific name from root widget.
|
|
|
|
* This search will be recursive through all child widgets.
|
|
|
|
*
|
|
|
|
* @param root The be searched root widget.
|
|
|
|
* @param name The widget name.
|
|
|
|
* @return Widget instance pointer.
|
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
static Widget* seekWidgetByName(Widget* root, std::string_view name);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Find a widget with a specific action tag from root widget
|
|
|
|
* This search will be recursive through all child widgets.
|
|
|
|
*@param root The be searched root widget.
|
|
|
|
*@param tag The widget action's tag.
|
|
|
|
*@return Widget instance pointer.
|
|
|
|
*/
|
|
|
|
static Widget* seekActionWidgetByActionTag(Widget* root, int tag);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Get a UTF8 substring from a std::string with a given start position and length
|
|
|
|
* Sample: std::string str = "中国中国中国"; substr = getSubStringOfUTF8String(str,0,2) will = "中国"
|
|
|
|
*
|
|
|
|
* @param str The source string.
|
|
|
|
* @param start The start position of the substring.
|
|
|
|
* @param length The length of the substring in UTF8 count
|
|
|
|
* @return a UTF8 substring
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
static std::string getSubStringOfUTF8String(std::string_view str,
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string::size_type start,
|
|
|
|
std::string::size_type length);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Refresh object and it's children layout state
|
|
|
|
*
|
|
|
|
*@param rootNode A Node* or Node* descendant instance pointer.
|
|
|
|
*
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static void doLayout(Node* rootNode);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the active property of Layout's @see `LayoutComponent`
|
|
|
|
*@param active A boolean value.
|
|
|
|
*/
|
|
|
|
static void changeLayoutSystemActiveState(bool active);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
*@brief restrict capInsetSize, when the capInsets's width is larger than the textureSize, it will restrict to 0,
|
|
|
|
* the height goes the same way as width.
|
|
|
|
*@param capInsets A user defined capInsets.
|
|
|
|
*@param textureSize The size of a scale9enabled texture
|
|
|
|
*@return a restricted capInset.
|
|
|
|
*/
|
2021-10-23 23:27:14 +08:00
|
|
|
static Rect restrictCapInsetRect(const Rect& capInsets, const Vec2& textureSize);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*@brief Convert a node's boundingBox rect into screen coordinates.
|
|
|
|
*
|
|
|
|
* @param node Any node pointer.
|
|
|
|
*
|
|
|
|
* @return A Rect in screen coordinates.
|
|
|
|
*/
|
|
|
|
static Rect convertBoundingBoxToScreen(Node* node);
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif /* defined(__CocoGUI__UISystem__) */
|