• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_PATTERN_BUTTON_TOGGLE_BUTTON_PAINT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_BUTTON_TOGGLE_BUTTON_PAINT_PROPERTY_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components_ng/base/inspector_filter.h"
21 #include "core/components_ng/property/property.h"
22 #include "core/components_ng/render/paint_property.h"
23 #include "core/components/toggle/toggle_theme.h"
24 #include "core/pipeline_ng/pipeline_context.h"
25 
26 namespace OHOS::Ace::NG {
27 
28 class ToggleButtonPaintProperty : public PaintProperty {
29     DECLARE_ACE_TYPE(ToggleButtonPaintProperty, PaintProperty);
30 
31 public:
32     ToggleButtonPaintProperty() = default;
33     ~ToggleButtonPaintProperty() override = default;
Clone()34     RefPtr<PaintProperty> Clone() const override
35     {
36         auto value = MakeRefPtr<ToggleButtonPaintProperty>();
37         value->PaintProperty::UpdatePaintProperty(DynamicCast<PaintProperty>(this));
38         value->propIsOn_ = CloneIsOn();
39         value->propSelectedColor_ = CloneSelectedColor();
40         value->propBackgroundColor_ = CloneBackgroundColor();
41         value->propSelectedColorSetByUser_ = CloneSelectedColorSetByUser();
42         return value;
43     }
44 
Reset()45     void Reset() override
46     {
47         PaintProperty::Reset();
48         ResetIsOn();
49         ResetSelectedColor();
50         ResetBackgroundColor();
51         ResetSelectedColorSetByUser();
52     }
53 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)54     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
55     {
56         /* no fixed attr below, just return */
57         if (filter.IsFastFilter()) {
58             return;
59         }
60         auto host = GetHost();
61         CHECK_NULL_VOID(host);
62         auto pipeline = host->GetContext();
63         CHECK_NULL_VOID(pipeline);
64         auto toggleTheme = pipeline->GetTheme<ToggleTheme>(host->GetThemeScopeId());
65         CHECK_NULL_VOID(toggleTheme);
66         auto selectedColor = toggleTheme->GetCheckedColor();
67         json->PutExtAttr("type", "ToggleType.Button", filter);
68         json->PutExtAttr("isOn", propIsOn_.value_or(false) ? "true" : "false", filter);
69         json->PutExtAttr("selectedColor", propSelectedColor_.value_or(selectedColor).ColorToString().c_str(), filter);
70     }
71 
72     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsOn, bool, PROPERTY_UPDATE_RENDER);
73     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedColor, Color, PROPERTY_UPDATE_RENDER);
74     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BackgroundColor, Color, PROPERTY_UPDATE_RENDER);
75     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedColorSetByUser, bool, PROPERTY_UPDATE_RENDER);
76     ACE_DISALLOW_COPY_AND_MOVE(ToggleButtonPaintProperty);
77 };
78 } // namespace OHOS::Ace::NG
79 
80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_BUTTON_TOGGLE_BUTTON_PAINT_PROPERTY_H
81