Skip to content

Commit

Permalink
Fix up SquooshLayout and TreeBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyfroehlich committed Dec 26, 2024
1 parent f976c76 commit 3cb16e1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ internal object VariableManager {
varMap = varMap.copy {
// Remove old entries for docId
val oldVarMap = docVarMap[docId.id]
oldVarMap?.collectionsMap?.forEach { collections.remove(it.key) }
oldVarMap?.collectionNameMapMap?.forEach { collectionNameMap.remove(it.key) }
oldVarMap?.variablesMap?.forEach { variables.remove(it.key) }
oldVarMap?.variableNameMapMap?.forEach { variableNameMap.remove(it.key) }
oldVarMap?.collectionsMap?.forEach { this.collections.remove(it.key) }
oldVarMap?.collectionNameMapMap?.forEach { this.collectionNameMap.remove(it.key) }
oldVarMap?.variablesMap?.forEach { this.variables.remove(it.key) }
oldVarMap?.variableNameMapMap?.forEach { this.variableNameMap.remove(it.key) }

// Add new entries for docId
docVarMap[docId.id] = map
collections.putAll(map.collectionsMap)
collectionNameMap.putAll(map.collectionNameMapMap)
variables.putAll(map.variablesMap)
variableNameMap.putAll(map.variableNameMapMap)
this.collections.putAll(map.collectionsMap)
this.collectionNameMap.putAll(map.collectionNameMapMap)
this.variables.putAll(map.variablesMap)
this.variableNameMap.putAll(map.variableNameMapMap)
}
currentDocId = docId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ private fun updateLayoutTree(

layoutNodes.add(
layoutNode {
layoutId
parentLayoutId
-1 // not childIdx!
resolvedNode.style.layoutStyle
resolvedNode.view.name
useMeasureFunc
null
null
this.layoutId = layoutId
this.parentLayoutId = parentLayoutId
this.childIndex = -1 // not childIdx!
this.style = resolvedNode.style.layoutStyle
this.name = resolvedNode.view.name
this.useMeasureFunc = useMeasureFunc
clearFixedWidth()
clearFixedHeight()
}
)
layoutCache[layoutId] = layoutCacheKey
Expand Down Expand Up @@ -296,8 +296,8 @@ internal fun layoutTree(
val layoutParentChildren = arrayListOf<LayoutParentChildren>()
updateLayoutTree(manager, root, layoutCache, layoutNodes, layoutParentChildren)
val layoutNodeList = layoutNodeList {
layoutNodes
layoutParentChildren
this.layoutNodes.addAll(layoutNodes)
this.parentChildren.addAll(layoutParentChildren)
}

// Now we can give the new layoutNodeList to the Rust JNI layout implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.android.designcompose.definition.view.View
import com.android.designcompose.definition.view.ViewDataKt.container
import com.android.designcompose.definition.view.ViewStyle
import com.android.designcompose.definition.view.containerOrNull
import com.android.designcompose.definition.view.copy
import com.android.designcompose.definition.view.frameExtrasOrNull
import com.android.designcompose.definition.view.overridesOrNull
import com.android.designcompose.definition.view.styleOrNull
Expand Down Expand Up @@ -566,59 +567,61 @@ private fun generateOverlayNode(
}
}

val nodeStyleBuilder = node.style.nodeStyle.toBuilder()
nodeStyleBuilder.overflow = Overflow.OVERFLOW_VISIBLE
nodeStyleBuilder.backgroundsList.clear()

overlay.overlayBackgroundOrNull?.colorOrNull?.let {
val bgColor =
com.android.designcompose.definition.element.color {
r = (it.r * 255.0).toInt()
g = (it.g * 255.0).toInt()
b = (it.b * 255.0).toInt()
a = (it.a * 255.0).toInt()
}
nodeStyleBuilder.backgroundsList.add(background { solid = colorOrVar { color = bgColor } })
val newNodeStyle = node.style.nodeStyle.copy {
this.overflow = Overflow.OVERFLOW_VISIBLE
this.backgrounds.clear()

overlay.overlayBackgroundOrNull?.colorOrNull?.let {
val bgColor =
com.android.designcompose.definition.element.color {
r = (it.r * 255.0).toInt()
g = (it.g * 255.0).toInt()
b = (it.b * 255.0).toInt()
a = (it.a * 255.0).toInt()
}
this.backgrounds.add(background { solid = colorOrVar { color = bgColor } })
}
}


val overlayStyle = viewStyle {
layoutStyle = layoutStyleBuilder.build()
nodeStyle = nodeStyleBuilder.build()
this.layoutStyle = layoutStyleBuilder.build()
this.nodeStyle = newNodeStyle
}

// Now synthesize a view.
val overlayViewData = container {
shape = viewShape { rect = box { isMask = false } }
children.add(node.view)
this.shape = viewShape { rect = box { isMask = false } }
this.children.add(node.view)
}

val overlayScrollInfo = scrollInfo {
pagedScrolling = false
overflow = OverflowDirection.OVERFLOW_DIRECTION_NONE
this.pagedScrolling = false
this.overflow = OverflowDirection.OVERFLOW_DIRECTION_NONE
}

if (node.view.uniqueId !in 0..0xFFFF) {
throw RuntimeException("View's unique ID must be in the range 0..0xFFFF")
}
val overlayView = view {
uniqueId = (node.view.uniqueId + 0x2000)
id = "overlay-${node.view.id}"
name = "Overlay ${node.view.name}"
this.uniqueId = (node.view.uniqueId + 0x2000)
this.id = "overlay-${node.view.id}"
this.name = "Overlay ${node.view.name}"
if (
overlay.overlayBackgroundInteraction ==
OverlayBackgroundInteraction.OVERLAY_BACKGROUND_INTERACTION_CLOSE_ON_CLICK_OUTSIDE
) {
reactions.add(
this.reactions.add(
reaction {
trigger = trigger { click = empty {} }
action = action { close = empty {} }
}
)
}
scrollInfo = overlayScrollInfo
style = overlayStyle
data = viewData { container = overlayViewData }
renderMethod = View.RenderMethod.RENDER_METHOD_NONE
this.scrollInfo = overlayScrollInfo
this.style = overlayStyle
this.data = viewData { container = overlayViewData }
this.renderMethod = View.RenderMethod.RENDER_METHOD_NONE
}
val overlayLayoutId = layoutIdAllocator.listLayoutId(node.layoutId)
val layoutId =
Expand Down

0 comments on commit 3cb16e1

Please sign in to comment.