tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

StoryInterface and UIBar #265

Open HenryLoenwind opened 1 year ago

HenryLoenwind commented 1 year ago

Is your feature request related to a problem? I need to use StoryInterface to put some divs around the story to style it nicely but I still want the features the UIBar offers without having to replicate them myself from scratch.

Describe alternatives you've considered. At the moment, I call UIBar.init(); in my Story Javascript and then jQuery("#ui-bar-history").detach().appendTo('#newhistory'); jQuery("#title").detach().appendTo('#newtitle'); jQuery("#menu").detach().appendTo('#newmenu'); jQuery("#ui-bar").detach(); move its parts where I want them. This works (even better with 2.37 now the StoryMenu bug is fixed), but it feels like I'm relying on undocumented implementation details.

Describe the solution you'd like. I thought about a couple of solutions that might work, but this one feels the most straightforward and uncomplicated:

  1. When encountering StoryInterface in engineInit(), destroy the old UIBar as it is currently, but after adding the html to the page, try to reconnect as follows:
  2. If there's no #ui-bar, do nothing.
  3. Try to find #ui-bar-tray, if it is there, add the ui-bar-toggle button to it
  4. Try to find #ui-bar-history, if it is there, add the 3 history buttons to it
  5. Try to find story-banner, story-title, story-subtitle, story-title-separator, story-author, and story-caption. Reconnect their updates if found
  6. Same for menu-story and menu-core (the latter also with button creation)
  7. Document that with a note that the author also is responsible for providing all the needed CSS that would have been in #style-ui-bar (I feel like still removing that would be the right choice as the CSS in there wouldn't fit any different structure anyway.)

This would ideally allow the author to use the functionality of all UIBar components just by including matching IDs in their html and styling them as wanted. And while my old solution isn't hard to do---it's literally 5 lines of code---, this would be a cleaner and update-safer way.

Additional context. "Add any other context or screenshots about the feature request here." Ok, here's a screenshot of what I made using StoryInterface and then re-adding the UIBar elements:

image

Not that related, but I spent way too much time making this look good and getting it to work on any screen size as long as it's landscape. Who'd have thought specifying font sizes and image widths in vh would ever make sense? ;) (Ignore the whiteness of the page (turn) number, the text colour is bleeding over from the debug style there.) And yes, this does resize so the text always stays on the pages, the book always is the full browser height and stays slightly left of centre and the sides of the book can slide off-screen but not the text area---with just CSS. (I'm getting off-topic, showing off my creation here, sorry!!!)