2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2014-03-11 17:13:54 +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__
|
|
|
|
|
2014-05-22 10:49:28 +08:00
|
|
|
#include <string>
|
2014-09-10 08:17:07 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-10-09 18:28:09 +08:00
|
|
|
#include "2d/CCNode.h"
|
2014-05-22 10:49:28 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
|
|
|
|
class Widget;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-27 11:02:04 +08:00
|
|
|
* Helper class for traversing children in widget tree.
|
|
|
|
* It also provides some helper functions for layout.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL Helper
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Find a widget with a specific tag from root widget.
|
2015-12-21 07:21:45 +08:00
|
|
|
* This search will be recursive through all child widgets.
|
|
|
|
* @param root The be searched root widget.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param tag The widget tag.
|
|
|
|
* @return Widget instance pointer.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
static Widget* seekWidgetByTag(Widget* root, int tag);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Find a widget with a specific name from root widget.
|
2015-12-21 07:21:45 +08:00
|
|
|
* This search will be recursive through all child widgets.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param root The be searched root widget.
|
|
|
|
* @param name The widget name.
|
2015-10-23 15:37:33 +08:00
|
|
|
* @return Widget instance pointer.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static Widget* seekWidgetByName(Widget* root, std::string_view name);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Find a widget with a specific action tag from root widget
|
2015-12-21 07:21:45 +08:00
|
|
|
* This search will be recursive through all child widgets.
|
2015-03-25 18:17:58 +08:00
|
|
|
*@param root The be searched root widget.
|
|
|
|
*@param tag The widget action's tag.
|
|
|
|
*@return Widget instance pointer.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
static Widget* seekActionWidgetByActionTag(Widget* root, int tag);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-07-28 17:24:37 +08:00
|
|
|
/**
|
2014-07-30 10:45:35 +08:00
|
|
|
* @brief Get a UTF8 substring from a std::string with a given start position and length
|
2014-10-09 17:19:43 +08:00
|
|
|
* Sample: std::string str = "中国中国中国"; substr = getSubStringOfUTF8String(str,0,2) will = "中国"
|
2015-03-27 18:26:14 +08:00
|
|
|
*
|
|
|
|
* @param str The source string.
|
2014-07-28 17:24:37 +08:00
|
|
|
* @param start The start position of the substring.
|
2014-07-30 10:45:35 +08:00
|
|
|
* @param length The length of the substring in UTF8 count
|
|
|
|
* @return a UTF8 substring
|
2015-03-30 21:38:32 +08:00
|
|
|
* @js NA
|
2014-07-28 17:24:37 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +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);
|
|
|
|
|
2014-12-22 11:20:03 +08:00
|
|
|
/**
|
2014-12-23 20:29:53 +08:00
|
|
|
* Refresh object and it's children layout state
|
2014-12-22 11:20:03 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
*@param rootNode A Node* or Node* descendant instance pointer.
|
2014-12-22 11:20:03 +08:00
|
|
|
*
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static void doLayout(Node* rootNode);
|
2014-07-28 17:24:37 +08:00
|
|
|
|
2015-03-25 18:17:58 +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
|
|
|
|
2014-12-17 16:46:48 +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);
|
2015-08-07 17:27:15 +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);
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
#endif /* defined(__CocoGUI__UISystem__) */
|