mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-12-04 05:29:08 +00:00
commit
d97f587f46
@ -454,6 +454,30 @@ panda::Local<panda::JSValueRef> Px2Lpx(panda::EcmaVM* vm, panda::Local<panda::JS
|
||||
return panda::NumberRef::New(vm, lpxValue);
|
||||
}
|
||||
|
||||
panda::Local<panda::JSValueRef> SetAppBackgroundColor(panda::EcmaVM* vm, panda::Local<panda::JSValueRef> value,
|
||||
const panda::Local<panda::JSValueRef> args[], int32_t argc, void* data)
|
||||
{
|
||||
if (argc != 1) {
|
||||
LOGE("The arg is wrong, must have one argument");
|
||||
return panda::JSValueRef::Exception(vm);
|
||||
}
|
||||
if (!args[0]->IsString()) {
|
||||
LOGE("The arg is wrong, value must be number");
|
||||
return panda::JSValueRef::Exception(vm);
|
||||
}
|
||||
std::string backgroundColorStr = args[0]->ToString(vm)->ToString();
|
||||
auto container = Container::Current();
|
||||
if (!container) {
|
||||
LOGW("container is null");
|
||||
return panda::JSValueRef::Exception(vm);
|
||||
}
|
||||
auto pipelineContext = container->GetPipelineContext();
|
||||
if (pipelineContext) {
|
||||
pipelineContext->SetRootBgColor(Color::FromString(backgroundColorStr));
|
||||
}
|
||||
return panda::JSValueRef::Undefined(vm);
|
||||
}
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(BindingTarget)>> bindFuncs = {
|
||||
{ "Flex", JSFlexImpl::JSBind },
|
||||
{ "Text", JSText::JSBind },
|
||||
@ -604,6 +628,8 @@ void JsRegisterViews(BindingTarget globalObj)
|
||||
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Lpx2Px, nullptr));
|
||||
globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "px2lpx"),
|
||||
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Px2Lpx, nullptr));
|
||||
globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "setAppBgColor"),
|
||||
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), SetAppBackgroundColor, nullptr));
|
||||
|
||||
JSViewAbstract::JSBind();
|
||||
JSContainerBase::JSBind();
|
||||
|
@ -426,6 +426,31 @@ JSValue Px2Lpx(JSContext* ctx, JSValueConst new_target, int argc, JSValueConst*
|
||||
return lpxQJSValue;
|
||||
}
|
||||
|
||||
JSValue SetAppBackgroundColor(JSContext* ctx, JSValueConst new_target, int argc, JSValueConst* argv)
|
||||
{
|
||||
if (argc != 1) {
|
||||
LOGE("The arg is wrong, must have one argument");
|
||||
return JS_ThrowSyntaxError(ctx, "input value must be number");
|
||||
}
|
||||
QJSContext::Scope scp(ctx);
|
||||
if (!JS_IsString(argv[0])) {
|
||||
LOGE("The arg is wrong, value must be string");
|
||||
return JS_ThrowSyntaxError(ctx, "input value must be string");
|
||||
}
|
||||
ScopedString valueString(ctx, argv[0]);
|
||||
std::string backgroundColorStr = valueString.get();
|
||||
auto container = Container::Current();
|
||||
if (!container) {
|
||||
LOGW("container is null");
|
||||
return JS_ThrowSyntaxError(ctx, "container is null");
|
||||
}
|
||||
auto pipelineContext = container->GetPipelineContext();
|
||||
if (pipelineContext) {
|
||||
pipelineContext->SetRootBgColor(Color::FromString(backgroundColorStr));
|
||||
}
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
void JsRegisterViews(BindingTarget globalObj)
|
||||
{
|
||||
JSContext* ctx = QJSContext::Current();
|
||||
@ -440,6 +465,7 @@ void JsRegisterViews(BindingTarget globalObj)
|
||||
QJSUtils::DefineGlobalFunction(ctx, Px2Fp, "px2fp", 1);
|
||||
QJSUtils::DefineGlobalFunction(ctx, Lpx2Px, "lpx2px", 1);
|
||||
QJSUtils::DefineGlobalFunction(ctx, Px2Lpx, "px2lpx", 1);
|
||||
QJSUtils::DefineGlobalFunction(ctx, SetAppBackgroundColor, "setAppBgColor", 1);
|
||||
|
||||
JSViewAbstract::JSBind();
|
||||
JSContainerBase::JSBind();
|
||||
|
@ -501,6 +501,33 @@ void Px2Lpx(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
args.GetReturnValue().Set(lpxV8Value);
|
||||
}
|
||||
|
||||
void SetAppBackgroundColor(const v8::FunctionCallbackInfo<v8::Value>& args)
|
||||
{
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
ACE_DCHECK(isolate);
|
||||
v8::Isolate::Scope isolateScope(isolate);
|
||||
v8::HandleScope handleScope(isolate);
|
||||
auto context = isolate->GetCurrentContext();
|
||||
if (args.Length() < 1 || !args[0]->IsString()) {
|
||||
LOGE("The arg is wrong, must have one argument");
|
||||
return;
|
||||
}
|
||||
v8::String::Utf8Value backgroundColorUtf8Str(isolate, args[0]);
|
||||
if (!(*backgroundColorUtf8Str)) {
|
||||
return;
|
||||
}
|
||||
std::string backgroundColorStr(*backgroundColorUtf8Str);
|
||||
auto container = Container::Current();
|
||||
if (!container) {
|
||||
LOGW("container is null");
|
||||
return;
|
||||
}
|
||||
auto pipelineContext = container->GetPipelineContext();
|
||||
if (pipelineContext) {
|
||||
pipelineContext->SetRootBgColor(Color::FromString(backgroundColorStr));
|
||||
}
|
||||
}
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(BindingTarget)>> bindFuncs = {
|
||||
{"Flex", JSFlexImpl::JSBind},
|
||||
{"Text", JSText::JSBind},
|
||||
@ -657,6 +684,8 @@ void JsRegisterViews(BindingTarget globalObj)
|
||||
v8::FunctionTemplate::New(isolate, Lpx2Px));
|
||||
globalObj->Set(v8::String::NewFromUtf8(isolate, "px2lpx").ToLocalChecked(),
|
||||
v8::FunctionTemplate::New(isolate, Px2Lpx));
|
||||
globalObj->Set(v8::String::NewFromUtf8(isolate, "setAppBgColor").ToLocalChecked(),
|
||||
v8::FunctionTemplate::New(isolate, SetAppBackgroundColor));
|
||||
|
||||
JSViewAbstract::JSBind();
|
||||
JSContainerBase::JSBind();
|
||||
|
@ -47,6 +47,11 @@ public:
|
||||
return backgroundColor_;
|
||||
}
|
||||
|
||||
void SetBackgroundColor(const Color& color)
|
||||
{
|
||||
backgroundColor_ = color;
|
||||
}
|
||||
|
||||
protected:
|
||||
AppTheme() = default;
|
||||
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "core/components/scroll/scrollable.h"
|
||||
#include "core/components/semi_modal/semi_modal_component.h"
|
||||
#include "core/components/semi_modal/semi_modal_element.h"
|
||||
#include "core/components/theme/app_theme.h"
|
||||
#include "core/components/stage/stage_component.h"
|
||||
#include "core/components/stage/stage_element.h"
|
||||
#include "core/image/image_provider.h"
|
||||
@ -1702,6 +1703,19 @@ void PipelineContext::SetRootRect(double width, double height) const
|
||||
}
|
||||
}
|
||||
|
||||
void PipelineContext::SetRootBgColor(const Color& color)
|
||||
{
|
||||
rootBgColor_ = color;
|
||||
auto appTheme = themeManager_->GetTheme<AppTheme>();
|
||||
appTheme->SetBackgroundColor(color);
|
||||
if (rootElement_) {
|
||||
auto renderRoot = DynamicCast<RenderRoot>(rootElement_->GetRenderNode());
|
||||
if (renderRoot) {
|
||||
renderRoot->SetBgColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PipelineContext::Finish(bool autoFinish) const
|
||||
{
|
||||
CHECK_RUN_ON(UI);
|
||||
|
@ -722,10 +722,7 @@ public:
|
||||
forbidePlatformQuit_ = forbidePlatformQuit;
|
||||
}
|
||||
|
||||
void SetRootBgColor(const Color& color)
|
||||
{
|
||||
rootBgColor_ = color;
|
||||
}
|
||||
void SetRootBgColor(const Color& color);
|
||||
|
||||
const Color& GetRootBgColor() const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user