From f75435eb6c84a1ce9176c90137e6d1b26d96631d Mon Sep 17 00:00:00 2001 From: anoshenko Date: Wed, 3 May 2023 15:16:03 +0300 Subject: [PATCH] Bug fixing --- app_scripts.js | 109 ++++++++++++++++++++++++++++++++++--------------- listView.go | 6 +++ popupUtils.go | 6 ++- 3 files changed, 87 insertions(+), 34 deletions(-) diff --git a/app_scripts.js b/app_scripts.js index 8e40df5..20de4af 100644 --- a/app_scripts.js +++ b/app_scripts.js @@ -590,6 +590,10 @@ function selectDropDownListItem(elementId, number) { function listItemClickEvent(element, event) { event.stopPropagation(); + if(element.getAttribute("data-disabled") == "1") { + return + } + var selected = false; if (element.classList) { const focusStyle = getListFocusedItemStyle(element); @@ -707,6 +711,9 @@ function findRightListItem(list, x, y) { var count = list.childNodes.length; for (var i = 0; i < count; i++) { var item = list.childNodes[i]; + if (item.getAttribute("data-disabled") == "1") { + continue; + } if (item.offsetLeft >= x) { if (result) { var result_dy = Math.abs(result.offsetTop - y); @@ -728,6 +735,9 @@ function findLeftListItem(list, x, y) { var count = list.childNodes.length; for (var i = 0; i < count; i++) { var item = list.childNodes[i]; + if (item.getAttribute("data-disabled") == "1") { + continue; + } if (item.offsetLeft < x) { if (result) { var result_dy = Math.abs(result.offsetTop - y); @@ -749,6 +759,9 @@ function findTopListItem(list, x, y) { var count = list.childNodes.length; for (var i = 0; i < count; i++) { var item = list.childNodes[i]; + if (item.getAttribute("data-disabled") == "1") { + continue; + } if (item.offsetTop < y) { if (result) { var result_dx = Math.abs(result.offsetLeft - x); @@ -770,6 +783,9 @@ function findBottomListItem(list, x, y) { var count = list.childNodes.length; for (var i = 0; i < count; i++) { var item = list.childNodes[i]; + if (item.getAttribute("data-disabled") == "1") { + continue; + } if (item.offsetTop >= y) { if (result) { var result_dx = Math.abs(result.offsetLeft - x); @@ -818,50 +834,77 @@ function listViewKeyDownEvent(element, event) { if (current) { var item switch (key) { - case " ": - case "Enter": - var message = "itemClick{session=" + sessionID + ",id=" + element.id + "}"; - sendMessage(message); - break; + case " ": + case "Enter": + var message = "itemClick{session=" + sessionID + ",id=" + element.id + "}"; + sendMessage(message); + break; - case "ArrowLeft": - item = findLeftListItem(element, current.offsetLeft, current.offsetTop); - break; - - case "ArrowRight": - item = findRightListItem(element, current.offsetLeft + current.offsetWidth, current.offsetTop); - break; - - case "ArrowDown": - item = findBottomListItem(element, current.offsetLeft, current.offsetTop + current.offsetHeight); - break; + case "ArrowLeft": + item = findLeftListItem(element, current.offsetLeft, current.offsetTop); + break; + + case "ArrowRight": + item = findRightListItem(element, current.offsetLeft + current.offsetWidth, current.offsetTop); + break; + + case "ArrowDown": + item = findBottomListItem(element, current.offsetLeft, current.offsetTop + current.offsetHeight); + break; - case "ArrowUp": - item = findTopListItem(element, current.offsetLeft, current.offsetTop); - break; + case "ArrowUp": + item = findTopListItem(element, current.offsetLeft, current.offsetTop); + break; - case "Home": - item = element.childNodes[0]; - break; + case "Home": + item = element.childNodes[0]; + break; - case "End": - item = element.childNodes[element.childNodes.length - 1]; - break; + case "End": + item = element.childNodes[element.childNodes.length - 1]; + break; - case "PageUp": - // TODO - break; + case "PageUp": + // TODO + break; - case "PageDown": - // TODO - break; + case "PageDown": + // TODO + break; - default: - return; + default: + return; } if (item && item !== current) { 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; + } } } diff --git a/listView.go b/listView.go index 7dadbf7..5d07388 100644 --- a/listView.go +++ b/listView.go @@ -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;`) listView.itemSize(self, buffer) + if !listView.adapter.IsListItemEnabled(i) { + buffer.WriteString(`" data-disabled="1`) + } buffer.WriteString(`">`) buffer.WriteString(itemDiv) @@ -796,6 +799,9 @@ func (listView *listViewData) noneCheckboxSubviews(self View, buffer *strings.Bu } buffer.WriteString(`" `) buffer.WriteString(itemStyle) + if !listView.adapter.IsListItemEnabled(i) { + buffer.WriteString(` data-disabled="1"`) + } buffer.WriteString(`>`) if view := listView.getItemView(i); view != nil { diff --git a/popupUtils.go b/popupUtils.go index 9275a2b..b1b1ac1 100644 --- a/popupUtils.go +++ b/popupUtils.go @@ -127,10 +127,14 @@ func (popup *popupMenuData) ListSize() int { } func (popup *popupMenuData) ListItem(index int, session Session) View { - return NewTextView(popup.session, Params{ + view := NewTextView(popup.session, Params{ Text: popup.items[index], Style: "ruiPopupMenuItem", }) + if !popup.IsListItemEnabled(index) { + view.Set(TextColor, "@ruiDisabledTextColor") + } + return view } func (popup *popupMenuData) IsListItemEnabled(index int) bool {