1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.internal.widget.remotecompose.core.operations.layout.measure; 17 18 import android.annotation.NonNull; 19 20 import com.android.internal.widget.remotecompose.core.operations.layout.Component; 21 22 /** Encapsulate the result of a measure pass for a component */ 23 public class ComponentMeasure { 24 int mId = -1; 25 float mX; 26 float mY; 27 float mW; 28 float mH; 29 int mVisibility = Component.Visibility.VISIBLE; 30 setX(float value)31 public void setX(float value) { 32 mX = value; 33 } 34 setY(float value)35 public void setY(float value) { 36 mY = value; 37 } 38 setW(float value)39 public void setW(float value) { 40 mW = value; 41 } 42 setH(float value)43 public void setH(float value) { 44 mH = value; 45 } 46 getX()47 public float getX() { 48 return mX; 49 } 50 getY()51 public float getY() { 52 return mY; 53 } 54 getW()55 public float getW() { 56 return mW; 57 } 58 getH()59 public float getH() { 60 return mH; 61 } 62 getVisibility()63 public int getVisibility() { 64 return mVisibility; 65 } 66 setVisibility(int visibility)67 public void setVisibility(int visibility) { 68 mVisibility = visibility; 69 } 70 ComponentMeasure(int id, float x, float y, float w, float h, int visibility)71 public ComponentMeasure(int id, float x, float y, float w, float h, int visibility) { 72 this.mId = id; 73 this.mX = x; 74 this.mY = y; 75 this.mW = w; 76 this.mH = h; 77 this.mVisibility = visibility; 78 } 79 ComponentMeasure(int id, float x, float y, float w, float h)80 public ComponentMeasure(int id, float x, float y, float w, float h) { 81 this(id, x, y, w, h, Component.Visibility.VISIBLE); 82 } 83 ComponentMeasure(@onNull Component component)84 public ComponentMeasure(@NonNull Component component) { 85 this( 86 component.getComponentId(), 87 component.getX(), 88 component.getY(), 89 component.getWidth(), 90 component.getHeight(), 91 component.mVisibility); 92 } 93 94 /** 95 * Initialize this ComponentMeasure from another ComponentMeasure instance. 96 * 97 * @param m the ComponentMeasure to copy from 98 */ copyFrom(@onNull ComponentMeasure m)99 public void copyFrom(@NonNull ComponentMeasure m) { 100 mX = m.mX; 101 mY = m.mY; 102 mW = m.mW; 103 mH = m.mH; 104 mVisibility = m.mVisibility; 105 } 106 107 /** 108 * Returns true if the ComponentMeasure passed is identical to us 109 * 110 * @param m the ComponentMeasure to check 111 * @return true if the passed ComponentMeasure is identical to ourself 112 */ same(@onNull ComponentMeasure m)113 public boolean same(@NonNull ComponentMeasure m) { 114 return mX == m.mX && mY == m.mY && mW == m.mW && mH == m.mH && mVisibility == m.mVisibility; 115 } 116 117 /** 118 * Returns true if the component will be gone 119 * 120 * @return true if gone 121 */ isGone()122 public boolean isGone() { 123 return Component.Visibility.isGone(mVisibility); 124 } 125 126 /** 127 * Returns true if the component will be visible 128 * 129 * @return true if visible 130 */ isVisible()131 public boolean isVisible() { 132 return Component.Visibility.isVisible(mVisibility); 133 } 134 135 /** 136 * Returns true if the component will be invisible 137 * 138 * @return true if invisible 139 */ isInvisible()140 public boolean isInvisible() { 141 return Component.Visibility.isInvisible(mVisibility); 142 } 143 144 /** Clear any override on the visibility */ clearVisibilityOverride()145 public void clearVisibilityOverride() { 146 mVisibility = Component.Visibility.clearOverride(mVisibility); 147 } 148 149 /** Add a visibility override */ addVisibilityOverride(int value)150 public void addVisibilityOverride(int value) { 151 mVisibility = Component.Visibility.clearOverride(mVisibility); 152 mVisibility = Component.Visibility.add(mVisibility, value); 153 } 154 } 155