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 16import { Style } from '@ohos/common'; 17import { initMoon, initSun } from '../../feature/SunCanvasFeature'; 18 19@Preview 20@Component 21export default struct SunCanvas { 22 private sunImg: ImageBitmap = new ImageBitmap('/common/images/sun.png'); 23 private moonImg: ImageBitmap = new ImageBitmap('/common/images/moon.png'); 24 private iconMoon: ImageBitmap = new ImageBitmap('/common/images/icon_moon.svg'); 25 private settings: RenderingContextSettings = new RenderingContextSettings(true); 26 private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); 27 28 build() { 29 Row() { 30 Canvas(this.context) 31 .height('95%') 32 .aspectRatio(1.8) 33 .onReady(() => { 34 this.context.clearRect(0, 0, this.context.width, this.context.height); 35 initSun(this.context, this.sunImg); 36 initMoon(this.context, this.moonImg, this.iconMoon); 37 }) 38 } 39 .width('100%') 40 .height(Style.CARD_HEIGHT) 41 .justifyContent(FlexAlign.Center) 42 .backgroundColor(Style.CARD_BACKGROUND_COLOR) 43 .borderRadius(Style.NORMAL_RADIUS) 44 } 45}