Skip to content

Commit

Permalink
do not set currentIndex to null position when focusedChild changes
Browse files Browse the repository at this point in the history
implement accurate getItemPosition
  • Loading branch information
whoozle committed May 14, 2024
1 parent ba67f47 commit c1345ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
7 changes: 6 additions & 1 deletion core/BaseView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ BaseLayout {
}

onFocusedChildChanged: {
var idx = this._items.indexOf(this.focusedChild)
if (value === null)
return

var idx = this._items.indexOf(value)
if (idx >= 0)
this.currentIndex = idx
}
Expand Down Expand Up @@ -141,6 +144,8 @@ BaseLayout {
}

onCurrentIndexChanged: {
if (this.trace)
log("onCurrentIndexChanged", value)
this.focusCurrent()
}

Expand Down
33 changes: 23 additions & 10 deletions core/ListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,35 @@ BaseView {
function getItemPosition(idx) {
var items = this._items
var item = items[idx]
var sizes = this._sizes
var horizontal = this.orientation === this.Horizontal
var spacing = this.spacing

if (!item) {
var refSize
var x = 0, y = 0, w = 0, h = 0
for(var i = idx; i >= 0; --i) {
if (items[i]) {
for(var i = 0; i < idx; ++i)
{
if (!item)
item = items[i]
x = item.viewX + item.x
y = item.viewY + item.y

if (item) {
w = item.width
h = item.height
break
}
}
var missing = idx - i
if (missing > 0) {
x += missing * (w + this.spacing)
y += missing * (h + this.spacing)
var s = sizes[i]
if (refSize === undefined || s > 0)
refSize = s
if (s === undefined)
s = refSize
if (s === undefined)
s = 0

if (horizontal) {
x += s + spacing
} else {
y += s + spacing
}
}
return [x, y, w, h]
}
Expand Down

0 comments on commit c1345ef

Please sign in to comment.