• 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 
24 namespace OHOS::Ace::NG {
25 
26 class ToggleButtonPaintProperty : public PaintProperty {
27     DECLARE_ACE_TYPE(ToggleButtonPaintProperty, PaintProperty)
28 
29 public:
30     ToggleButtonPaintProperty() = default;
31     ~ToggleButtonPaintProperty() override = default;
Clone()32     RefPtr<PaintProperty> Clone() const override
33     {
34         auto value = MakeRefPtr<ToggleButtonPaintProperty>();
35         value->PaintProperty::UpdatePaintProperty(DynamicCast<PaintProperty>(this));
36         value->propIsOn_ = CloneIsOn();
37         value->propSelectedColor_ = CloneSelectedColor();
38         value->propBackgroundColor_ = CloneBackgroundColor();
39         return value;
40     }
41 
Reset()42     void Reset() override
43     {
44         PaintProperty::Reset();
45         ResetIsOn();
46         ResetSelectedColor();
47         ResetBackgroundColor();
48     }
49 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)50     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
51     {
52         /* no fixed attr below, just return */
53         if (filter.IsFastFilter()) {
54             return;
55         }
56         json->PutExtAttr("type", "ToggleType.Button", filter);
57         json->PutExtAttr("isOn", propIsOn_.value_or(false) ? "true" : "false", filter);
58         json->PutExtAttr("selectedColor", propSelectedColor_.value_or(Color()).ColorToString().c_str(), filter);
59     }
60 
61     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsOn, bool, PROPERTY_UPDATE_RENDER);
62     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedColor, Color, PROPERTY_UPDATE_RENDER);
63     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BackgroundColor, Color, PROPERTY_UPDATE_RENDER);
64     ACE_DISALLOW_COPY_AND_MOVE(ToggleButtonPaintProperty);
65 };
66 } // namespace OHOS::Ace::NG
67 
68 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_BUTTON_TOGGLE_BUTTON_PAINT_PROPERTY_H
69