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

Example of a custom composed widget #15

Open
patrickbkr opened this issue May 3, 2024 · 2 comments
Open

Example of a custom composed widget #15

patrickbkr opened this issue May 3, 2024 · 2 comments

Comments

@patrickbkr
Copy link

I'm trying to implement a custom widget (The source view widget of the debugger I'm working on. I'm calling it SourceWidget). That widget should be a composition of a SpanBuffer (the line numbers), a divider and another SpanBuffer (the source text). As that widget will be specific to my use-case, it won't make sense to add it to T::W.
I am missing an example of how to build a custom widget that's composed of others. Questions that have come to my mind trying to do so:

  • Do I need to implement a layout twin class for my custom Widget?
  • Where would I hook in such a custom layout twin?
  • How can I use my custom widget (in an initial-layout($builder, ...) method) without modifying T::W sources?
  • Which classes / roles do I need to inherit? Candidates: T::W::Widget, T::W::StandardWidgetBuilder, T::W::L::WidgetBuilding, T::W::Scrollable
  • Which methods do I then need to implement?
  • How can I prevent my child widgets from processing scrolling events automatically, but instead process scrolling events myself and then dictate my child widgets where to scroll?

I'm lacking in understanding of the overall T::W architecture. I think an example could help.

@japhb
Copy link
Owner

japhb commented May 23, 2024

In IRC you mentioned a few days ago that you were working on building your own widget, but it doesn't look composed (it looks like you went the bespoke route instead). I think this is a generally useful request, and would in fact probably make a great example, but is it still a priority request for you?

@patrickbkr
Copy link
Author

patrickbkr commented May 24, 2024

There are many open ends I'm chasing. I'm just picking the ones where I'm not blocked. My current plan is:

  • Create a generic RichText widget, to be part of T-W <-- I'm working on this at the moment
  • Create a generic TreeView widget, building on RichText, to be part of T-W
  • Create a SourceView widget, not part of T-W, based on RichText. It adds line numbers, highlights of breakpointed lines, markers of currently-executing line(s), ... <-- this is the custom composed widget
  • Create a LocalsView widget, not part of T-W, based on TreeView. Maybe I can get away without inheriting if I get the interface of TreeView just right.

As a temporary workaround for the "custom" part (i.e. How do I create a widget without modifying the T-W sources?), I can just add the widget to my local clone of T-W and move it out later.

As a temporary workaround for the "composed" part (i.e. How do I combine two SpanBuffers and a Divider into a new SourceView widget?), I can use a single SpanBuffer and output the line numbers at the start of each line and enforce line wrapping.

So in summary, it's not the highest priority at the moment, but at some point it will turn into a blocker.

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

No branches or pull requests

2 participants