feat(uidesigner): show view info on hierarchy text click

This commit is contained in:
Akash Yadav
2022-12-20 11:53:56 +05:30
parent 8e58f71f8d
commit f7dfe3515b
4 changed files with 29 additions and 6 deletions
Binary file not shown.
@@ -183,7 +183,9 @@ class UIDesignerActivity : BaseIDEActivity() {
}
fun setupHierarchy(view: IView) {
binding?.hierarchy?.setupWithView(view)
binding?.hierarchy?.setupWithView(view) {
workspace()?.showViewInfo(it)
}
}
fun openHierarchyView() {
@@ -150,8 +150,7 @@ class DesignerWorkspaceFragment : BaseFragment() {
view.registerAttributeChangeListener(attrHandler)
view.view.setOnTouchListener(
WidgetTouchListener(view, requireContext()) {
viewModel.view = it
findNavController().navigate(R.id.viewInfoSheet)
showViewInfo(it)
true
}
)
@@ -171,7 +170,12 @@ class DesignerWorkspaceFragment : BaseFragment() {
view.needSetup = false
}
}
internal fun showViewInfo(view: IView) {
viewModel.view = view
findNavController().navigate(R.id.viewInfoSheet)
}
private fun setupViewGroup(viewGroup: UiViewGroup) {
viewGroup.view.setOnDragListener(WidgetDragListener(viewGroup, placeholder, touchSlop))
viewGroup.addOnHierarchyChangeListener(hierarchyHandler)
@@ -25,6 +25,7 @@ import android.text.TextUtils.TruncateAt.MIDDLE
import android.util.AttributeSet
import android.util.TypedValue
import android.view.Gravity
import android.view.View.OnClickListener
import android.widget.LinearLayout
import androidx.core.view.updateMarginsRelative
import androidx.core.view.updatePaddingRelative
@@ -49,6 +50,13 @@ constructor(
defStyleRes: Int = 0
) : LinearLayout(context, attrs, defStyleAttr, defStyleRes) {
private val textToIView = mutableMapOf<HierarchyText, IView>()
private var onClick: ((IView) -> Unit)? = null
private val clickListener = OnClickListener { view ->
onClick?.let { click -> textToIView[view]?.let(click) }
}
private val paint = Paint()
private val pointRadius = SizeUtils.dp2px(3f).toFloat()
private val dp8 = SizeUtils.dp2px(8f)
@@ -62,19 +70,28 @@ constructor(
paint.isAntiAlias = true
}
fun setupWithView(view: IView) {
fun setupWithView(view: IView, onClick: ((IView) -> Unit)? = null) {
removeAllViews()
textToIView.clear()
this.onClick = onClick
addViews(view, 1)
}
private fun addViews(view: IView, depth: Int) {
val text = HierarchyText(context, depth, dp16).apply { this.text = view.tag }
val text =
HierarchyText(context, depth, dp16).apply {
this.text = view.tag
setOnClickListener(clickListener)
}
addView(text)
if (view is IViewGroup) {
text.childCount = computeChildCount(view)
view.forEach { addViews(it, depth + 1) }
}
textToIView[text] = view
}
private fun computeChildCount(view: IViewGroup): Int {