Мне нужно создать редактор полей в LiveCode DataGrid, который растет по мере того, как пользователь вводит данные, чтобы соответствовать форматированной высоте поля. Остальная часть основного элемента управления строкой также должна быть изменена вместе со сдвигом всех последующих элементов управления строкой вниз.
Как создать расширяющийся редактор полей в LiveCode DataGrid?
Ответы (2)
Отвечая на мой собственный вопрос, поскольку это может быть полезно для других.
Скопируйте кнопку поведения редактора поля из стека revDataGridLibrary на карточку с шаблоном строки.
Отредактируйте скрипт редактируемого поля следующим образом (обратите внимание, что вам нужно будет исправить ссылку на кнопку поведения, чтобы она была длинным идентификатором вашего нового поведения редактора поля):
on preOpenFieldEditor pEditor
set the behavior of pEditor to the long id of button id 1023 of card id 1010 of stack "Data Grid Templates 1362091650635"
set the uRowControl of pEditor to the long id of the owner of me
end preOpenFieldEditor
Отредактируйте сценарий поведения редактора полей, добавив следующее:
local sHeight,sRowControl
setProp uRowControl pRowControl
put pRowControl into sRowControl
end uRowControl
on openField
put the formattedHeight of me into sHeight
pass openField
end openField
on textChanged
local tHeight,tRect
lock screen
put the formattedHeight of me into tHeight
if sHeight <> tHeight then
put the rect of me into tRect
put item 2 of tRect+ tHeight into item 4 of tRect
set the rect of me to tRect
put tHeight into sHeight
dispatch "UpdateRow" to sRowControl with the long id of me
end if
unlock screen
pass textChanged
end textChanged
Теперь отредактируйте поведение шаблона строки, добавив следующий обработчик (обратите внимание, что в этом случае редактируемое поле называется «примечание», поэтому вы захотите изменить его для своего варианта использования):
on UpdateRow pFieldEditor
set the rect of graphic "Background" of me to the rect of pFieldEditor
set the rect of fld "note" of me to the rect of pFieldEditor
set the rect of me to the formattedRect of me
put the uScriptLocal["sTableObjectsA"] of me into tTableObjectsA
repeat for each line tControl in tTableObjectsA["all row controls"]
delete word -2 to -1 of tControl -- of me
put tControl into tControlA[the dgIndex of tControl]
end repeat
put the bottomLeft of me into tTopLeft
repeat for each item tIndex in tTableObjectsA["current"]["indexes"]
if tIndex > the dgIndex of me then
set the topLeft of tControlA[tIndex] to tTopLeft
put the bottomLeft of tControlA[tIndex] into tTopLeft
end if
end repeat
end UpdateRow
Выглядит полезно, Монте. Вопрос: зачем обработчик preOpenField? Разве эта информация не может быть установлена один раз во время разработки? Создает ли DataGrid новый элемент управления полем при каждом вызове редактора?