forked from mbk-lab/rui_orig
2
0
Fork 0

Bug fixing

This commit is contained in:
anoshenko 2023-05-03 15:16:03 +03:00
parent b7a0aa9a6d
commit f75435eb6c
3 changed files with 87 additions and 34 deletions

View File

@ -590,6 +590,10 @@ function selectDropDownListItem(elementId, number) {
function listItemClickEvent(element, event) { function listItemClickEvent(element, event) {
event.stopPropagation(); event.stopPropagation();
if(element.getAttribute("data-disabled") == "1") {
return
}
var selected = false; var selected = false;
if (element.classList) { if (element.classList) {
const focusStyle = getListFocusedItemStyle(element); const focusStyle = getListFocusedItemStyle(element);
@ -707,6 +711,9 @@ function findRightListItem(list, x, y) {
var count = list.childNodes.length; var count = list.childNodes.length;
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
var item = list.childNodes[i]; var item = list.childNodes[i];
if (item.getAttribute("data-disabled") == "1") {
continue;
}
if (item.offsetLeft >= x) { if (item.offsetLeft >= x) {
if (result) { if (result) {
var result_dy = Math.abs(result.offsetTop - y); var result_dy = Math.abs(result.offsetTop - y);
@ -728,6 +735,9 @@ function findLeftListItem(list, x, y) {
var count = list.childNodes.length; var count = list.childNodes.length;
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
var item = list.childNodes[i]; var item = list.childNodes[i];
if (item.getAttribute("data-disabled") == "1") {
continue;
}
if (item.offsetLeft < x) { if (item.offsetLeft < x) {
if (result) { if (result) {
var result_dy = Math.abs(result.offsetTop - y); var result_dy = Math.abs(result.offsetTop - y);
@ -749,6 +759,9 @@ function findTopListItem(list, x, y) {
var count = list.childNodes.length; var count = list.childNodes.length;
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
var item = list.childNodes[i]; var item = list.childNodes[i];
if (item.getAttribute("data-disabled") == "1") {
continue;
}
if (item.offsetTop < y) { if (item.offsetTop < y) {
if (result) { if (result) {
var result_dx = Math.abs(result.offsetLeft - x); var result_dx = Math.abs(result.offsetLeft - x);
@ -770,6 +783,9 @@ function findBottomListItem(list, x, y) {
var count = list.childNodes.length; var count = list.childNodes.length;
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
var item = list.childNodes[i]; var item = list.childNodes[i];
if (item.getAttribute("data-disabled") == "1") {
continue;
}
if (item.offsetTop >= y) { if (item.offsetTop >= y) {
if (result) { if (result) {
var result_dx = Math.abs(result.offsetLeft - x); var result_dx = Math.abs(result.offsetLeft - x);
@ -818,50 +834,77 @@ function listViewKeyDownEvent(element, event) {
if (current) { if (current) {
var item var item
switch (key) { switch (key) {
case " ": case " ":
case "Enter": case "Enter":
var message = "itemClick{session=" + sessionID + ",id=" + element.id + "}"; var message = "itemClick{session=" + sessionID + ",id=" + element.id + "}";
sendMessage(message); sendMessage(message);
break; break;
case "ArrowLeft": case "ArrowLeft":
item = findLeftListItem(element, current.offsetLeft, current.offsetTop); item = findLeftListItem(element, current.offsetLeft, current.offsetTop);
break; break;
case "ArrowRight": case "ArrowRight":
item = findRightListItem(element, current.offsetLeft + current.offsetWidth, current.offsetTop); item = findRightListItem(element, current.offsetLeft + current.offsetWidth, current.offsetTop);
break; break;
case "ArrowDown": case "ArrowDown":
item = findBottomListItem(element, current.offsetLeft, current.offsetTop + current.offsetHeight); item = findBottomListItem(element, current.offsetLeft, current.offsetTop + current.offsetHeight);
break; break;
case "ArrowUp": case "ArrowUp":
item = findTopListItem(element, current.offsetLeft, current.offsetTop); item = findTopListItem(element, current.offsetLeft, current.offsetTop);
break; break;
case "Home": case "Home":
item = element.childNodes[0]; item = element.childNodes[0];
break; break;
case "End": case "End":
item = element.childNodes[element.childNodes.length - 1]; item = element.childNodes[element.childNodes.length - 1];
break; break;
case "PageUp": case "PageUp":
// TODO // TODO
break; break;
case "PageDown": case "PageDown":
// TODO // TODO
break; break;
default: default:
return; return;
} }
if (item && item !== current) { if (item && item !== current) {
selectListItem(element, item, true); selectListItem(element, item, true);
} }
} else {
switch (key) {
case " ":
case "Enter":
case "ArrowLeft":
case "ArrowUp":
case "ArrowRight":
case "ArrowDown":
case "Home":
case "End":
case "PageUp":
case "PageDown":
var list = element.childNodes[0];
var count = list.childNodes.length;
for (var i = 0; i < count; i++) {
var item = list.childNodes[i];
if (item.getAttribute("data-disabled") == "1") {
continue;
}
selectListItem(element, item, true);
return;
}
break;
default:
return;
}
} }
} }

View File

@ -740,6 +740,9 @@ func (listView *listViewData) checkboxSubviews(self View, buffer *strings.Builde
} }
buffer.WriteString(`" onclick="listItemClickEvent(this, event)" data-left="0" data-top="0" data-width="0" data-height="0" style="display: grid; justify-items: stretch; align-items: stretch;`) buffer.WriteString(`" onclick="listItemClickEvent(this, event)" data-left="0" data-top="0" data-width="0" data-height="0" style="display: grid; justify-items: stretch; align-items: stretch;`)
listView.itemSize(self, buffer) listView.itemSize(self, buffer)
if !listView.adapter.IsListItemEnabled(i) {
buffer.WriteString(`" data-disabled="1`)
}
buffer.WriteString(`">`) buffer.WriteString(`">`)
buffer.WriteString(itemDiv) buffer.WriteString(itemDiv)
@ -796,6 +799,9 @@ func (listView *listViewData) noneCheckboxSubviews(self View, buffer *strings.Bu
} }
buffer.WriteString(`" `) buffer.WriteString(`" `)
buffer.WriteString(itemStyle) buffer.WriteString(itemStyle)
if !listView.adapter.IsListItemEnabled(i) {
buffer.WriteString(` data-disabled="1"`)
}
buffer.WriteString(`>`) buffer.WriteString(`>`)
if view := listView.getItemView(i); view != nil { if view := listView.getItemView(i); view != nil {

View File

@ -127,10 +127,14 @@ func (popup *popupMenuData) ListSize() int {
} }
func (popup *popupMenuData) ListItem(index int, session Session) View { func (popup *popupMenuData) ListItem(index int, session Session) View {
return NewTextView(popup.session, Params{ view := NewTextView(popup.session, Params{
Text: popup.items[index], Text: popup.items[index],
Style: "ruiPopupMenuItem", Style: "ruiPopupMenuItem",
}) })
if !popup.IsListItemEnabled(index) {
view.Set(TextColor, "@ruiDisabledTextColor")
}
return view
} }
func (popup *popupMenuData) IsListItemEnabled(index int) bool { func (popup *popupMenuData) IsListItemEnabled(index int) bool {