/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved. * * Description: TjdUiUtils.h * * Author: luziquan@ss-tjd.com * * Create: 2024-11-07 *--------------------------------------------------------------------------*/ #ifndef TJD_UI_COMMON_TJDUIUTILS_H #define TJD_UI_COMMON_TJDUIUTILS_H #include "components/ui_scroll_view.h" #include "components/ui_view.h" #include namespace TJD { class TjdUiUtils final { public: static inline int16_t HorizontalCenter(int16_t width, int16_t target) { return (target - width) / 2; } static inline int16_t VerticalCenter(int16_t height, int16_t target) { return (target - height) / 2; } /** * @brief 计算到控件中心到底部的距离 * @param screenBottomView * @return int16_t */ static int16_t CalculateBottomHidePos(OHOS::UIView &screenBottomView); /** * @brief 设置默认的滚动效果 * @param view */ static void SetDefaultRollingEffect(OHOS::UIScrollView &view); /** * @brief 滑动到顶部 * @param view */ static void ScrollByTop(OHOS::UIScrollView &view); /** * @brief 请求焦点 * @param view */ static void ViewRequestFocus(OHOS::UIView &view); enum class MsgBoxPosition { MSG_BOX_CENTER, MSG_BOX_BOTTOM, }; /** * @brief 显示消息框 * @param msg 显示内容 * @param position 显示位置 */ static void ShowMsgBox(const char *msg, TjdUiUtils::MsgBoxPosition position, uint32_t color = 0xFF555555, uint32_t opa = 0xFF); /** * @brief 控件水平居中,默认为屏幕宽度466 * @param view * @param parentWidth 父控件宽度 */ static void AutoAlignHorizontalCenter(OHOS::UIView &view, int16_t parentWidth = 466); /** * @brief 控件垂直居中,默认为屏幕宽度466 * @param view * @param parentWidth 父控件宽度 */ static void AutoAlignVerticalCenter(OHOS::UIView &view, int16_t parentHeight = 466); /** * @brief 调整当前控件基于目标控件某个方向上的偏移量 * @param curView 当前控件 * @param targetView 目标控件 * @param offsetX 偏移量 * @param direction 偏移方向 */ enum class OffsetDirection { OFFSET_LEFT,// 基于目标控件左偏移 OFFSET_RIGHT,// 基于目标控件右偏移 OFFSET_TOP,// 基于目标控件上偏移 OFFSET_BOTTOM,// 基于目标控件下偏移 }; static void AdjustViewOffset(OHOS::UIView &curView, OHOS::UIView &targetView, int16_t offset, OffsetDirection direction); private: TjdUiUtils() = delete; ~TjdUiUtils() = delete; }; } // namespace TJD #endif // TJD_UI_COMMON_TJDUIUTILS_H