gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.3k stars 245 forks source link

[FEATURE] Add focus support for TextView #560

Open aome510 opened 3 years ago

aome510 commented 3 years ago

Are there any ways to focus a TextView element? My use case is that I want to create a select list using LinearLayout (vertical) and TextView. This results in an error because TextView uses the default implementation of take_focus from View. Using SelectView is an alternative, but it restricts the label to be within one single row. I wonder why focus is not supported for TextView. Are there any difficulties involved supporting this feature that I may miss?

smallB007 commented 3 years ago

Hi, I belive that cursive TextView is an eqivalent of let's say Qt's label. TBH, I don't think having focus on such element is required. You should redesign, in order to use correct "widgets" for the job.

aome510 commented 3 years ago

Hi, thanks for the reply. I'm new to UI library so don't really have much information about what "widgets" I need to use for my case.

I want to have a view element that can be able to wrap words and add highlight upon being focused but there doesn't seem to be any view structs in Cursive::views support it. My current work-around is to implement a basic version of Cursive::views::TextView but with focus enabled: text_view.rs. This seems to work well at least for now.

I just wonder why there are some with focus enabled by default but not TextView.

smallB007 commented 3 years ago

It is I believe done because labels, never? need focus? The thing here is that I believe that the name TextView is misleading. In other gui frameworks it is called label.