Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgets/text area #4995

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

wiktor-obrebski
Copy link
Contributor

@wiktor-obrebski wiktor-obrebski commented Oct 8, 2024

This MR introduce TextArea widget.
This widgets is already in use in gui/journal and coming gui/notes tools.
Its provide much better support for text manipultation than TextField do.

Scripts journal has been migrated here:
DFHack/scripts#1327


self:addviews{
TextAreaContent{
view_id='text_area',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think other widgets leave out the view_id so that the caller can specify their own and then access their elements internally like self.subviews[element_index]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improved

function TextArea:getText()
return self.subviews.text_area.text
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we expose a setText method as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@robob27 robob27 Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make it so that if you call setText(text) and then press CTRL-Z, it will revert to the text before the setText call? (If it's already working like that for you, let me know, I might just need to re-pull)

Edit: I repulled just to make sure so I didn't waste your time and confirmed that it's not working this way on the latest update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings about it, can you present a usecase where it would be useful?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The situation where this came up for me is with this UI in a script I've been working on:

image

I'm using this to be able to quickly add notes to individual units. Once I no longer need the note for the unit, I'll clear it out with ALT+C. I know I could CTRL+A/backspace to clear all but I also wanted to provide a shortcut to clear the notes with a single hotkey press (I had this before while using an EditField here and still find it handy).

If a user ever did ALT+C by accident here, ideally they could CTRL+Z it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I would additionally expose clearHistory function for cases where it would be a required behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

TextArea = defclass(TextArea, Panel)

TextArea.ATTRS{
init_text = '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to switch this to text instead of init_text? It feels like text might align more closely with the API of other widgets like EditField, Label

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid it will consfuse users and they will treat it as writeable property - where it is not. they need to to use :setText(...)

@robob27
Copy link
Contributor

robob27 commented Oct 9, 2024

I really appreciate your work on all of this stuff! You really went all out with this widget and the result is fantastic. Journal is sooo good and it's awesome that every other script will have such a great textarea to work with. I have been looking forward to this PR 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants