Nick
08/19/2022, 3:41 PMayodele
08/19/2022, 5:26 PMlabel
needs a behavior or theme for it to render. Can you shed more light?Nick
08/19/2022, 7:09 PMTheme
or a Behavior
directly. `Theme`s are easy to use though, so you don't really have to manually set `Behavior`s in most cases. Let me know if that answers your question.ayodele
08/19/2022, 9:23 PMcontainer
but still don't know it's difference from layout
Nick
08/20/2022, 1:45 AMayodele
08/20/2022, 9:48 AMconstraint
layout, but one of the view(which is the last) it holds is a top view too that uses constraint layout in itself.
But the inner top view does not render. Like it was ignored.
Is it due to constraint layout??Nick
08/20/2022, 3:19 PM// create children and specify their Layouts if they have children
tooLevelView = container {
this += … // add nested children
layout = constrain(…) { … } // setup topLevelView’s layout
}
display += topLevelView // show the view and all its children
The order of these operations can change of course. But the end result would be that Display holds ONLY the views at the top of your hierarchy, and those views hold children etc.
Display
- Child1
- GrandChild1
- …
- Child2
- …
Let me know if that's clear. If not, it would be easier to help if you shared a code sample of what you're trying to achieve.ayodele
08/20/2022, 4:24 PMclass TopView(textMetrics: TextMetrics): View(){
init {
val but = Button("Click", textMetrics)
val innerView = InnerView(textMetrics)
children += listOf(but, innerView)
layout = constrain(but,innerView){ b1, b2 ->
<http://b1.top|b1.top> = <http://parent.top|parent.top>
b1.left = parent.left
<http://b2.top|b2.top> = b1.bottom
b2.left = parent.left
}
}
}
This is my InnerView
class InnerView(textMetrics: TextMetrics): View(){
init {
val but = Button("ClickInner", textMetrics)
children += listOf(but, but)
layout = constrain(but,but){ b1, b2 ->
<http://b1.top|b1.top> = <http://parent.top|parent.top>
b1.left = parent.left
<http://b2.top|b2.top> = b1.bottom
b2.left = parent.left
}
}
}
Then my app:
val vi = TopView(textMetrics)
display += vi
display.layout = constrain(vi){view ->
view.width = parent.width
view.height = parent.height
}
But i get circular dependency
error. Can you tell me what I did wrongNick
08/20/2022, 4:35 PMconstrain(but, but)
. You are also adding that view to InnerView twice. Adding twice doesn't matter, but the current constraint impl can't deal with self references. This happens because b1 == b2 since you are constraining the same view. Surely this isn't what you wanted.ayodele
08/20/2022, 5:24 PMTopView
was shownNick
08/20/2022, 5:27 PMayodele
08/20/2022, 5:33 PMinit
block of the InnerView
it showed.
Why does the TopView
not need a size for the view to be rendered, but InnerView does?Nick
08/20/2022, 5:46 PMTopView
in the layout you assigned to the Display
. The `Display`’s layout will affect all its children.ayodele
08/20/2022, 6:29 PMmatchparent
in views or I'll have to pass around the display object?Nick
08/20/2022, 6:59 PMparent
. This is a View?
which will be null
if the view is top-level (or hasn't been added to any other view). Top-level views always have a null
parent
(Display
is not a View
).
Is your goal to get the Display
, or just a view’s parent? You'll have to pass the Display
around if other parts of your app want to use it.
View
actually always knows it's Display
(once it has been shown). But that value is internal for now. You'll also notice that a View’s parent is just a plain View
. This is intentional, and avoids leaking information about a View through its children.matchparent
by the way? Do you mean telling a view to fit the size of its parent? If so, you can use a layout on the parent that sizes the view to it. A constraint is a simple way (like you did before for the top view).ayodele
08/20/2022, 7:55 PMparent.height
and parent.width
?Nick
08/20/2022, 7:56 PMayodele
08/20/2022, 8:11 PMNick
08/20/2022, 9:45 PM