From 4f8b912ff8df01472faff6b98dcf8a5e0247a270 Mon Sep 17 00:00:00 2001 From: wangyihui Date: Wed, 22 Mar 2023 05:30:58 +0000 Subject: [PATCH] add new component Signed-off-by: wangyihui Change-Id: Ib128d0a80b153f7aa284247a04d93e5b2545ba2b --- .../bridge/declarative_frontend/BUILD.gn | 1 + .../engine/jsi/jsi_view_register_impl.cpp | 3 + .../jsview/js_mycircle.cpp | 104 ++++++++++++++++++ .../declarative_frontend/jsview/js_mycircle.h | 33 ++++++ .../core/components_ng/pattern/BUILD.gn | 4 + .../mycircle/mycircle_layout_algorithm.cpp | 38 +++++++ .../mycircle/mycircle_layout_algorithm.h | 38 +++++++ .../mycircle/mycircle_layout_property.h | 55 +++++++++ .../pattern/mycircle/mycircle_model.h | 39 +++++++ .../pattern/mycircle/mycircle_model_ng.cpp | 48 ++++++++ .../pattern/mycircle/mycircle_model_ng.h | 33 ++++++ .../mycircle/mycircle_paint_method.cpp | 44 ++++++++ .../pattern/mycircle/mycircle_paint_method.h | 39 +++++++ .../mycircle/mycircle_paint_property.h | 48 ++++++++ .../pattern/mycircle/mycircle_pattern.cpp | 31 ++++++ .../pattern/mycircle/mycircle_pattern.h | 63 +++++++++++ .../inspector_composed_component.cpp | 1 + .../inspector/inspector_constants.cpp | 4 + .../inspector/inspector_constants.h | 4 + 19 files changed, 630 insertions(+) create mode 100644 frameworks/bridge/declarative_frontend/jsview/js_mycircle.cpp create mode 100644 frameworks/bridge/declarative_frontend/jsview/js_mycircle.h create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_layout_algorithm.cpp create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_layout_algorithm.h create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_layout_property.h create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_model.h create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_model_ng.cpp create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_model_ng.h create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_paint_method.cpp create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_paint_method.h create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_paint_property.h create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_pattern.cpp create mode 100644 frameworks/core/components_ng/pattern/mycircle/mycircle_pattern.h diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index f59e86597ef..9df1f829840 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -196,6 +196,7 @@ template("declarative_js_engine") { "jsview/js_menu.cpp", "jsview/js_menu_item.cpp", "jsview/js_menu_item_group.cpp", + "jsview/js_mycircle.cpp", "jsview/js_navdestination.cpp", "jsview/js_navigation.cpp", "jsview/js_navigator.cpp", diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register_impl.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register_impl.cpp index b4232bbe7ef..0f2dcf22f8a 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register_impl.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register_impl.cpp @@ -93,6 +93,7 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_menu.h" #include "frameworks/bridge/declarative_frontend/jsview/js_menu_item.h" #include "frameworks/bridge/declarative_frontend/jsview/js_menu_item_group.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_mycircle.h" #include "frameworks/bridge/declarative_frontend/jsview/js_navdestination.h" #include "frameworks/bridge/declarative_frontend/jsview/js_navigation.h" #include "frameworks/bridge/declarative_frontend/jsview/js_navigator.h" @@ -246,6 +247,7 @@ void UpdateRootComponent(const panda::Local& obj) view->FireOnShow(); } }); + view->RegisterRenderDoneCallback([pagePattern]() { pagePattern->MarkRenderDone();}); pagePattern->SetOnPageHide([weak = Referenced::WeakClaim(view)]() { auto view = weak.Upgrade(); if (view) { @@ -404,6 +406,7 @@ static const std::unordered_map> { "ActionSheet", JSActionSheet::JSBind }, { "AlertDialog", JSAlertDialog::JSBind }, { "ContextMenu", JSContextMenu::JSBind }, + { "MyCircle", JSMyCircle::JSBind }, #ifdef ABILITY_COMPONENT_SUPPORTED { "AbilityComponent", JSAbilityComponent::JSBind }, #endif diff --git a/frameworks/bridge/declarative_frontend/jsview/js_mycircle.cpp b/frameworks/bridge/declarative_frontend/jsview/js_mycircle.cpp new file mode 100644 index 00000000000..1ae292ee8df --- /dev/null +++ b/frameworks/bridge/declarative_frontend/jsview/js_mycircle.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/jsview/js_mycircle.h" + +#include "base/log/ace_scoring_log.h" +#include "core/common/container.h" +#include "core/components_ng/pattern/mycircle/mycircle_model.h" +#include "core/components_ng/pattern/mycircle/mycircle_model_ng.h" + +namespace OHOS::Ace { + +std::unique_ptr MyCircleModel::instance_ = nullptr; + +MyCircleModel* MyCircleModel::GetInstance() +{ + if (!instance_) { +#ifdef NG_BUILD + instance_.reset(new NG::MyCircleModelNG()); +#else + if (Container::IsCurrentUseNewPipeline()) { + instance_.reset(new NG::MyCircleModelNG()); + } else { + instance_.reset(new NG::MyCircleModelNG()); + // instance_.reset(new Framework::MyCircleModelImpl()); + } +#endif + } + return instance_.get(); +} + +} // namespace OHOS::Ace + +namespace OHOS::Ace::Framework { +void JSMyCircle::SetRadius(const JSCallbackInfo& info) +{ + if (info.Length() < 1) { + LOGE("The arg is wrong, it is supposed to have at least 1 arguments"); + return; + } + Dimension value; + if (!ParseJsDimensionVp(info[0], value)) { + return; + } + MyCircleModel::GetInstance()->SetRadius(value); +} + +void JSMyCircle::SetEdgeColor(const JSCallbackInfo& info) +{ + if (info.Length() < 1) { + LOGE("The arg is wrong, it is supposed to have atleast 1 arguments"); + return; + } + + Color color; + if (!ParseJsColor(info[0], color)) { + return; + } + MyCircleModel::GetInstance()->SetEdgeColor(color); +} + +void JSMyCircle::SetEdgeWidth(const JSCallbackInfo& info) +{ + if (info.Length() < 1) { + LOGE("The arg is wrong, it is supposed to have at least 1 arguments"); + return; + } + Dimension value; + if (!ParseJsDimensionVp(info[0], value)) { + return; + } + MyCircleModel::GetInstance()->SetEdgeWidth(value); +} + +void JSMyCircle::Create() +{ + MyCircleModel::GetInstance()->Create(); +} + +void JSMyCircle::JSBind(BindingTarget globalObj) +{ + JSClass::Declare("MyCircle"); + MethodOptions opt = MethodOptions::NONE; + JSClass::StaticMethod("create", &JSMyCircle::Create, opt); + JSClass::StaticMethod("circleRadius", &JSMyCircle::SetRadius); + JSClass::StaticMethod("circleEdgeColor", &JSMyCircle::SetEdgeColor); + JSClass::StaticMethod("circleEdgeWidth", &JSMyCircle::SetEdgeWidth); + JSClass::StaticMethod("onCircleClick", &JSInteractableView::JsOnClick); + JSClass::Inherit(); + JSClass::Bind<>(globalObj); +} +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_mycircle.h b/frameworks/bridge/declarative_frontend/jsview/js_mycircle.h new file mode 100644 index 00000000000..1d2e850b922 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/jsview/js_mycircle.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_MYCIRCLE_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_MYCIRCLE_H + +#include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" + +namespace OHOS::Ace::Framework { +class JSMyCircle : public JSViewAbstract, public JSInteractableView { +public: + static void SetRadius(const JSCallbackInfo& info); + static void SetEdgeColor(const JSCallbackInfo& info); + static void SetEdgeWidth(const JSCallbackInfo& info); + + static void JSBind(BindingTarget globalObj); + static void Create(); +}; +} // namespace OHOS::Ace::Framework +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_MYCIRCLE_H diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index 3db06ab7587..911d0473f55 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -45,6 +45,10 @@ build_component_ng("pattern_ng") { "checkbox/checkbox_paint_method.cpp", "checkbox/checkbox_paint_property.cpp", "checkbox/checkbox_pattern.cpp", + "mycircle/mycircle_layout_algorithm.cpp", + "mycircle/mycircle_model_ng.cpp", + "mycircle/mycircle_paint_method.cpp", + "mycircle/mycircle_pattern.cpp", "checkboxgroup/checkboxgroup_layout_algorithm.cpp", "checkboxgroup/checkboxgroup_model_ng.cpp", "checkboxgroup/checkboxgroup_paint_method.cpp", diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_algorithm.cpp new file mode 100644 index 00000000000..270350ef458 --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_algorithm.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/components_ng/pattern/mycircle/mycircle_layout_algorithm.h" + +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/pattern/mycircle/mycircle_layout_property.h" + +namespace OHOS::Ace::NG { + +std::optional MyCircleLayoutAlgorithm::MeasureContent( + const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) +{ + if (contentConstraint.selfIdealSize.IsValid()) { + return contentConstraint.selfIdealSize.ConvertToSizeT(); + } + auto mycircleLayoutProperty = DynamicCast(layoutWrapper->GetLayoutProperty()); + CHECK_NULL_RETURN(mycircleLayoutProperty, std::nullopt); + auto radius = mycircleLayoutProperty->GetRadius().value_or(30.0_vp).ConvertToPx(); + auto edgeWidth = mycircleLayoutProperty->GetEdgeWidth().value_or(1.0_vp).ConvertToPx(); + CHECK_NULL_RETURN(mycircleLayoutProperty, std::nullopt); + SizeF componentSize((2 * radius + edgeWidth), (2 * radius + edgeWidth)); + return contentConstraint.Constrain(componentSize); +} + +} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_algorithm.h b/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_algorithm.h new file mode 100644 index 00000000000..8b8adcbd165 --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_algorithm.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_LAYOUT_ALGORITHM_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_LAYOUT_ALGORITHM_H + +#include "core/components_ng/layout/box_layout_algorithm.h" + +namespace OHOS::Ace::NG { +class ACE_EXPORT MyCircleLayoutAlgorithm : public BoxLayoutAlgorithm { + DECLARE_ACE_TYPE(MyCircleLayoutAlgorithm, BoxLayoutAlgorithm); + +public: + MyCircleLayoutAlgorithm() = default; + ~MyCircleLayoutAlgorithm() override = default; + + std::optional MeasureContent( + const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override; + +private: + // float constrainStrokeWidth_ = 0; + // float dividerLength_ = 0; + // bool vertical_ = false; + ACE_DISALLOW_COPY_AND_MOVE(MyCircleLayoutAlgorithm); +}; +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_LAYOUT_ALGORITHM_H \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_property.h b/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_property.h new file mode 100644 index 00000000000..1018ea99c9c --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_layout_property.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_LAYOUT_PROPERTY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_LAYOUT_PROPERTY_H + +#include "base/geometry/dimension.h" +#include "core/components_ng/layout/layout_property.h" +#include "core/components_ng/property/property.h" + +namespace OHOS::Ace::NG { +class ACE_EXPORT MyCircleLayoutProperty : public LayoutProperty { + DECLARE_ACE_TYPE(MyCircleLayoutProperty, LayoutProperty); + +public: + MyCircleLayoutProperty() = default; + + ~MyCircleLayoutProperty() override = default; + + RefPtr Clone() const override + { + auto value = MakeRefPtr(); + value->LayoutProperty::UpdateLayoutProperty(DynamicCast(this)); + value->propRadius_ = CloneRadius(); + value->propEdgeWidth_ = CloneEdgeWidth(); + return value; + } + + void Reset() override + { + LayoutProperty::Reset(); + ResetRadius(); + ResetEdgeWidth(); + } + + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Radius, Dimension, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EdgeWidth, Dimension, PROPERTY_UPDATE_MEASURE); + + ACE_DISALLOW_COPY_AND_MOVE(MyCircleLayoutProperty); +}; +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_LAYOUT_PROPERTY_H diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_model.h b/frameworks/core/components_ng/pattern/mycircle/mycircle_model.h new file mode 100644 index 00000000000..74ef179ac0b --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_model.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_MODEL_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_MODEL_H + +#include "core/components_ng/base/frame_node.h" + +namespace OHOS::Ace { + +class ACE_EXPORT MyCircleModel { +public: + static MyCircleModel* GetInstance(); + virtual ~MyCircleModel() = default; + + virtual void Create() = 0; + virtual void SetRadius(const Dimension& value) = 0; + virtual void SetEdgeColor(const Color& value) = 0; + virtual void SetEdgeWidth(const Dimension& value) = 0; + +private: + static std::unique_ptr instance_; +}; + +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_MODEL_H \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_model_ng.cpp b/frameworks/core/components_ng/pattern/mycircle/mycircle_model_ng.cpp new file mode 100644 index 00000000000..1d76dd2a887 --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_model_ng.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/components_ng/pattern/mycircle/mycircle_model_ng.h" + +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/base/view_stack_processor.h" +#include "core/components_ng/pattern/mycircle/mycircle_pattern.h" +#include "core/components_v2/inspector/inspector_constants.h" +#include "core/pipeline_ng/pipeline_context.h" + +namespace OHOS::Ace::NG { +void MyCircleModelNG::Create() +{ + auto* stack = ViewStackProcessor::GetInstance(); + auto nodeId = stack->ClaimNodeId(); + auto frameNode = FrameNode::GetOrCreateFrameNode( + V2::MYCIRCLE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); + stack->Push(frameNode); +} + +void MyCircleModelNG::SetRadius(const Dimension& value) +{ + ACE_UPDATE_LAYOUT_PROPERTY(MyCircleLayoutProperty, Radius, value); +} + +void MyCircleModelNG::SetEdgeColor(const Color& value) +{ + ACE_UPDATE_PAINT_PROPERTY(MyCirclePaintProperty, EdgeColor, value); +} + +void MyCircleModelNG::SetEdgeWidth(const Dimension& value) +{ + ACE_UPDATE_LAYOUT_PROPERTY(MyCircleLayoutProperty, EdgeWidth, value); +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_model_ng.h b/frameworks/core/components_ng/pattern/mycircle/mycircle_model_ng.h new file mode 100644 index 00000000000..f0108051dd5 --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_model_ng.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_MODEL_NG_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_MODEL_NG_H + +#include "core/components_ng/pattern/mycircle/mycircle_model.h" + +namespace OHOS::Ace::NG { + +class ACE_EXPORT MyCircleModelNG : public MyCircleModel { +public: + void Create() override; + void SetRadius(const Dimension& value) override; + void SetEdgeColor(const Color& value) override; + void SetEdgeWidth(const Dimension& value) override; +}; + +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_MODEL_NG_H \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_method.cpp b/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_method.cpp new file mode 100644 index 00000000000..57cac6fe0e3 --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_method.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/components_ng/pattern/mycircle/mycircle_paint_method.h" + +#include "base/geometry/dimension.h" +#include "core/components_ng/render/drawing.h" +#include "core/components_ng/render/drawing_prop_convertor.h" + +namespace OHOS::Ace::NG { + +CanvasDrawFunction MyCirclePaintMethod::GetContentDrawFunction(PaintWrapper* paintWrapper) +{ + auto offset = paintWrapper->GetContentOffset(); + auto mycirclePaintProperty = DynamicCast(paintWrapper->GetPaintProperty()); + CHECK_NULL_RETURN(mycirclePaintProperty, nullptr); + Color edgeColor = mycirclePaintProperty->GetEdgeColor().value_or(Color::BLACK); + + return [radius = radius_, edgeColor, edgeWidth = edgeWidth_, offset](RSCanvas& canvas) { + canvas.Save(); + RSPen pen; + pen.SetAntiAlias(true); + pen.SetColor(ToRSColor(edgeColor)); + pen.SetWidth(edgeWidth); + canvas.AttachPen(pen); + auto centerPt = RSPoint(offset.GetX() + radius, offset.GetY() + radius); + canvas.DrawCircle(centerPt, radius); + canvas.DetachPen(); + canvas.Restore(); + }; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_method.h b/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_method.h new file mode 100644 index 00000000000..6e26dc18d9a --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_method.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_PAINT_METHOD_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_PAINT_METHOD_H + +#include "core/components_ng/pattern/mycircle/mycircle_paint_property.h" +#include "core/components_ng/render/node_paint_method.h" + +namespace OHOS::Ace::NG { +class ACE_EXPORT MyCirclePaintMethod : public NodePaintMethod { + DECLARE_ACE_TYPE(MyCirclePaintMethod, NodePaintMethod) +public: + explicit MyCirclePaintMethod(float radius, float edgeWidth) : radius_(radius), edgeWidth_(edgeWidth) {} + ~MyCirclePaintMethod() override = default; + + CanvasDrawFunction GetContentDrawFunction(PaintWrapper* paintWrapper) override; + +private: + float radius_ = 30.0f; + float edgeWidth_ = 1.0f; + ACE_DISALLOW_COPY_AND_MOVE(MyCirclePaintMethod); +}; + +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_PAINT_METHOD_H diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_property.h b/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_property.h new file mode 100644 index 00000000000..4cdd16f867a --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_paint_property.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_PAINT_PROPERTY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_PAINT_PROPERTY_H + +#include "core/components/common/layout/constants.h" +#include "core/components/common/properties/color.h" +#include "core/components_ng/render/paint_property.h" + +namespace OHOS::Ace::NG { +// PaintProperty are used to set render properties. +class MyCirclePaintProperty : public PaintProperty { + DECLARE_ACE_TYPE(MyCirclePaintProperty, PaintProperty) +public: + MyCirclePaintProperty() = default; + ~MyCirclePaintProperty() override = default; + RefPtr Clone() const override + { + auto value = MakeRefPtr(); + value->PaintProperty::UpdatePaintProperty(DynamicCast(this)); + value->propEdgeColor_ = CloneEdgeColor(); + return value; + } + + void Reset() override + { + PaintProperty::Reset(); + ResetEdgeColor(); + } + + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EdgeColor, Color, PROPERTY_UPDATE_RENDER); + ACE_DISALLOW_COPY_AND_MOVE(MyCirclePaintProperty); +}; +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_MYCIRCLE_PAINT_PROPERTY_H diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_pattern.cpp b/frameworks/core/components_ng/pattern/mycircle/mycircle_pattern.cpp new file mode 100644 index 00000000000..68ede524573 --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_pattern.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/components_ng/pattern/mycircle/mycircle_pattern.h" + +namespace OHOS::Ace::NG { +bool MyCirclePattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) +{ + return !(config.skipMeasure || dirty->SkipMeasureContent()); +} + +void MyCirclePattern::OnModifyDone() +{ + auto mycircleLayoutProperty = GetLayoutProperty(); + CHECK_NULL_VOID(mycircleLayoutProperty); + radiusLength_ = mycircleLayoutProperty->GetRadius().value_or(30.0_vp).ConvertToPx(); + edgeWidth_ = mycircleLayoutProperty->GetEdgeWidth().value_or(1.0_vp).ConvertToPx(); +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/mycircle/mycircle_pattern.h b/frameworks/core/components_ng/pattern/mycircle/mycircle_pattern.h new file mode 100644 index 00000000000..f0f301aa017 --- /dev/null +++ b/frameworks/core/components_ng/pattern/mycircle/mycircle_pattern.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MYCIRCLE_MYCIRCLE_PATTERN_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MYCIRCLE_MYCIRCLE_PATTERN_H + +#include "core/components_ng/pattern/mycircle/mycircle_layout_algorithm.h" +#include "core/components_ng/pattern/mycircle/mycircle_layout_property.h" +#include "core/components_ng/pattern/mycircle/mycircle_paint_method.h" +#include "core/components_ng/pattern/mycircle/mycircle_paint_property.h" +#include "core/components_ng/pattern/pattern.h" + +namespace OHOS::Ace::NG { +class MyCirclePattern : public Pattern { + DECLARE_ACE_TYPE(MyCirclePattern, Pattern); + +public: + MyCirclePattern() {}; + ~MyCirclePattern() override = default; + + RefPtr CreateNodePaintMethod() override + { + return MakeRefPtr(radiusLength_, edgeWidth_); + } + + RefPtr CreateLayoutProperty() override + { + return MakeRefPtr(); + } + + RefPtr CreateLayoutAlgorithm() override + { + return MakeRefPtr(); + } + + RefPtr CreatePaintProperty() override + { + return MakeRefPtr(); + } + +private: + bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; + void OnModifyDone() override; + + float radiusLength_ = 30.0f; + float edgeWidth_ = .0f; + ACE_DISALLOW_COPY_AND_MOVE(MyCirclePattern); +}; +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MYCIRCLE_MYCIRCLE_PATTERN_H diff --git a/frameworks/core/components_v2/inspector/inspector_composed_component.cpp b/frameworks/core/components_v2/inspector/inspector_composed_component.cpp index 44911a40443..a2f584117a6 100644 --- a/frameworks/core/components_v2/inspector/inspector_composed_component.cpp +++ b/frameworks/core/components_v2/inspector/inspector_composed_component.cpp @@ -281,6 +281,7 @@ const std::unordered_map COMPONENT_TAG_TO_ETS_TAG_MAP { SHAPE_COMPONENT_TAG, SHAPE_ETS_TAG }, { IMAGE_COMPONENT_TAG, IMAGE_ETS_TAG }, { QRCODE_COMPONENT_TAG, QRCODE_ETS_TAG }, + { MYCIRCLE_COMPONENT_TAG, MYCIRCLE_ETS_TAG }, { SPAN_COMPONENT_TAG, SPAN_ETS_TAG }, { BOX_COMPONENT_TAG, BLANK_ETS_TAG }, { BUTTON_COMPONENT_TAG, BUTTON_ETS_TAG }, diff --git a/frameworks/core/components_v2/inspector/inspector_constants.cpp b/frameworks/core/components_v2/inspector/inspector_constants.cpp index 593e05420f9..31d3a66caaf 100644 --- a/frameworks/core/components_v2/inspector/inspector_constants.cpp +++ b/frameworks/core/components_v2/inspector/inspector_constants.cpp @@ -479,4 +479,8 @@ const char REMOTE_WINDOW_ETS_TAG[] = "RemoteWindow"; ACE_EXPORT extern const char MODEL_COMPONENT_TAG[] = "ModelComponent"; ACE_EXPORT extern const char MODEL_ETS_TAG[] = "Model"; +// mycircle +const char MYCIRCLE_COMPONENT_TAG[] = "MyCircleComponent"; +const char MYCIRCLE_ETS_TAG[] = "MyCircle"; + } // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/inspector/inspector_constants.h b/frameworks/core/components_v2/inspector/inspector_constants.h index 18e5c7a3820..2c8bcf5e171 100644 --- a/frameworks/core/components_v2/inspector/inspector_constants.h +++ b/frameworks/core/components_v2/inspector/inspector_constants.h @@ -490,6 +490,10 @@ ACE_EXPORT extern const char REMOTE_WINDOW_ETS_TAG[]; ACE_EXPORT extern const char MODEL_COMPONENT_TAG[]; ACE_EXPORT extern const char MODEL_ETS_TAG[]; +// mycircle +ACE_EXPORT extern const char MYCIRCLE_COMPONENT_TAG[]; +ACE_EXPORT extern const char MYCIRCLE_ETS_TAG[]; + } // namespace OHOS::Ace::V2 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INSPECTOR_INSPECTOR_CONSTANTS_H -- Gitee