-
Notifications
You must be signed in to change notification settings - Fork 242
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
Dynamically adding Scenes #320
Comments
Yeah. You're right. The assumption in the current The simplest approach for this is probably to create your own play loop. Asciimatics already provides the API to do this. You can see how to use the necessary calls here: asciimatics/asciimatics/screen.py Line 1599 in 9903ced
You could then change that to call |
Alternatively, if you're feeling more adventurous, I'd happily help you add a real tab layout to the widgets subsystem. |
Thank you for these ideas! Right now I'm thinking the easiest thing to do might be to clear widgets and rebuild on select.
I'd be interested in giving that a try! I'll probably finish my current project first, then give this a shot. I'll post a link to the project in a week when it's in a working state. What are you imagining the tab layout API might look like? |
Asciimatics already has the concept of a Layout, which is responsible for placing Widgets within a Frame. The current implementation just allows you to create a set of columns (to place the widgets in). We could create a TabbedLayout that allows you to create multiple tabs - each of which is one column. You then add widgets to each tab in much the same way as you would add one to a column for the current Layout. The display logic then needs to draw the tab header as well as the column for the active tab. Similarly input logic needs to find the active tab rather than the current column. Overall logic should be pretty similar to the existing Layout object. This will only allow simple forms inside the TabbedLayout, though. if you need something more complex than that, we'd have to start nesting Layouts within TabbedLayout. This would then effectively just be the logic to handle the tab header and route drawing/input to the correct embedded Layout... which probably means we should call it something else. i can flesh out design ideas as needed... |
Okay I finally put my progress on github. There's a lot of room for improvement, but I put a picture on the readme of the tab system I currently have going. My current implementation is to call this function whenever a tab button is pressed, which clears the central layout and replaces the central widget. However, this only works because I have two layouts one on top of the other, and the top one only ever holds a single widget. I'm going to switch to having vertical tabs on the side, rather than on the bottom, and I think that means whenever a button is selected I'll have to create all of the tab buttons, which is less ideal 🤔 |
You just got me thinking- does Asciimatics allow for nested layouts? That might let me work around some issues. |
Good question... Sadly not. |
Dynamically adding scenes may be what I was trying to do without realizing (which if it's not, I can open a new issue; just let me know and I'll do that) and I think you answered this for me with your response:
The what I'm trying to do and the why: I think what I'm trying to do is related to dynamic scenes, because even though I'm looking to create effect-scenes that are generically written, it's the active switching (i.e. calling play) to those scenes and then returning back (i.e. getting in the middle of Asciimatic's loop and telling it, return "here" or return "there" when the scene is done -- the dynamic part). I see references to callbacks and I feel like that's kind of what I'm looking for except, I'm not looking to add to the callstack to simulate a return as that would be a memory leak as the callstack would grow and grow as the program is used. Second question (related to the scene thing only beneath the surface more): A real shot in the dark attempt at achieving what I was looking to do (which if you couldn't tell, didn't work lol): |
Wow! Lots to unpack there...
|
Hi! Thank you for the wonderful library. I am building a TUI which uses tab navigation, and after reading through #271 and taking a close look at the tab demo, I realized that there may not be a way to do what I'm looking for.
Basically, I have a dynamic number of tabs. The user can create new tabs, and at the moment I'm strugling to figure out a way to add them to the list of scenes.
This seems to be a typical pattern through the samples:
However, short of throwing a custom exception, forcing in a newly instantiated scene, and then going back to
screen.play
I don't see a way to dynamically register a new scene to the list and then callraise NextScene("New scene name")
.The text was updated successfully, but these errors were encountered: