1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_MODEL_H
18 
19 #include <functional>
20 #include <optional>
21 
22 #include "core/components_ng/base/frame_node.h"
23 
24 namespace OHOS::Ace {
25 struct MenuItemProperties {
26     std::string content;
27     std::optional<ImageSourceInfo> startIcon;
28     std::optional<ImageSourceInfo> endIcon;
29     std::optional<std::string> labelInfo;
30     std::optional<std::function<void()>> buildFunc;
31     std::function<void(WeakPtr<NG::FrameNode>)> startApply;
32     std::function<void(WeakPtr<NG::FrameNode>)> endApply;
33 };
34 class ACE_FORCE_EXPORT MenuItemModel {
35 public:
36     static MenuItemModel* GetInstance();
37     virtual ~MenuItemModel() = default;
38 
39     // createMenuItem with custom
40     virtual void Create(const RefPtr<NG::UINode>& customNode);
41     virtual void Create(const MenuItemProperties& props);
42     virtual void SetSelected(bool isSelected = false);
43     virtual void SetSelectIcon(bool isShow = false);
44     virtual void SetSelectIconSymbol(std::function<void(WeakPtr<NG::FrameNode>)> &&symbolApply);
45     virtual void SetSelectIconSrc(const std::string& src);
46     virtual void SetOnChange(std::function<void(bool)>&& onChange);
47     virtual void SetFontSize(const Dimension& fontSize);
48     virtual void SetFontWeight(FontWeight weight);
49     virtual void SetFontStyle(Ace::FontStyle style);
50     virtual void SetFontColor(const std::optional<Color>& color);
51     virtual void SetFontFamily(const std::vector<std::string>& families);
52     virtual void SetLabelFontSize(const Dimension& fontSize);
53     virtual void SetLabelFontWeight(FontWeight weight);
54     virtual void SetLabelFontStyle(Ace::FontStyle style);
55     virtual void SetLabelFontColor(const std::optional<Color>& color);
56     virtual void SetLabelFontFamily(const std::vector<std::string>& families);
57     virtual void SetSelectedChangeEvent(std::function<void(bool)>&& selectedChangeEvent);
58 
59 private:
60     static std::unique_ptr<MenuItemModel> instance_;
61     static std::mutex mutex_;
62 };
63 } // namespace OHOS::Ace
64 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_MODEL_H
65