godot icon indicating copy to clipboard operation
godot copied to clipboard

Add support for multiline cells to `Tree`

Open dalexeev opened this issue 3 years ago • 2 comments

Confirming a change to a multiline cell is done with Ctrl+Enter instead of Enter.

My tree CSV editor

Test project: gd4-tree-multiline-items.zip

Closes godotengine/godot-proposals#3632.

dalexeev avatar Jun 05 '22 11:06 dalexeev

Confirming a change to a multiline cell is done with Ctrl+Enter instead of Enter.

Should be the opposite.

KoBeWi avatar Jun 05 '22 11:06 KoBeWi

@KoBeWi this is up to you to decide what to do

reduz avatar Aug 06 '22 21:08 reduz

Confirming a change to a multiline cell is done with Ctrl+Enter instead of Enter.

Should be the opposite.

Fixed.

@KoBeWi this is up to you to decide what to do

@KoBeWi If you are going to rewrite Tree in the near future, then this PR can probably be closed. Just don't forget about multiline cells, please.

dalexeev avatar Aug 14 '22 14:08 dalexeev

Needs rebase. Also the text changes should likely be reviewed by @bruvzg

KoBeWi avatar Sep 08 '22 14:09 KoBeWi

I tested this and:

  • ~~newline should be Shift+Enter not Ctrl+Enter (it's common in different apps, mainly chat)~~ EDIT: Ah it uses an existing action. I'd change it, but technically it's unrelated, so should be done in another PR.
  • multiline cells are unusable with default settings: image The size is too small. Maybe scroll_fit_content_height property is enough to fix that. Or at least docs should mention how to make the cell higher.

KoBeWi avatar Sep 09 '22 21:09 KoBeWi

  • multiline cells are unusable with default settings

The height of the editor is equal to the height of the line. If all cells are empty, Tree draws a line with a very small height. Perhaps this is a Tree problem? Maybe we need Tree to draw empty lines one line high?

  • Maybe scroll_fit_content_height property is enough to fix that.

In this case, the editor can overflow through the line without stretching it in height. I don't think this is what we need.

dalexeev avatar Sep 10 '22 13:09 dalexeev

The height of the editor is equal to the height of the line. If all cells are empty, Tree draws a line with a very small height. Perhaps this is a Tree problem? Maybe we need Tree to draw empty lines one line high?

Well, if the cell is editable, it's not very useful when it's tiny. Maaybe having cell edit without other cells isn't very common, but for multiline edits the height should definitely match the edited text.

In this case, the editor can overflow through the line without stretching it in height.

You could try using minimum_size_changed signal to update the cell height.

KoBeWi avatar Sep 10 '22 13:09 KoBeWi

You could try using minimum_size_changed signal to update the cell height.

The problem is that until the change is applied, the text is only in the TextEdit, not in the Tree cell. So, the line height remains small. Changing the contents of a cell before the change is applied is wrong.

dalexeev avatar Sep 10 '22 13:09 dalexeev

Then not sure what to do about the cell. IMO it's not fine if you have scrollable TextEdit, but then the text properly expands when you accept it. You could maybe change the cell text, but revert if it the user cancels editing text.

KoBeWi avatar Sep 10 '22 13:09 KoBeWi

I made the minimum height the same size as the height of one empty line:

You could maybe change the cell text, but revert if it the user cancels editing text.

I don't think this is a good solution since editing is a lengthy process and user code can get errors if it reads the text of the cells (the value can be new before the signal, and roll back if the user undoes the changes).

Ideally, Tree should be able to draw currently edited (not yet applied) values, distinguish between visual and logical content. But now it is difficult to implement.

dalexeev avatar Sep 10 '22 16:09 dalexeev

  • newline should be Shift+Enter not Ctrl+Enter (it's common in different apps, mainly chat)

In some applications this is Shift+Enter, in others Ctrl+Enter (for example, LibreOffice Calc).

dalexeev avatar Sep 10 '22 17:09 dalexeev

Needs a rebase, then I think it should be mergeable?

akien-mga avatar Apr 25 '23 14:04 akien-mga

Rebased.

dalexeev avatar Apr 25 '23 15:04 dalexeev

Thanks!

akien-mga avatar Apr 25 '23 17:04 akien-mga

I believe this breaks set_column_clip_content, at least when using text. I'm using this method in order to display ellipsis when text overflows the column width. Is there a way to get around this that I'm not seeing?

bvigario avatar May 12 '23 14:05 bvigario

See https://github.com/godotengine/godot/pull/76532#discussion_r1180062076. I added this to my TODO list and will try to fix it.

dalexeev avatar May 12 '23 14:05 dalexeev