Starfinder Playlist
  1. #1

    Execute code on next frame?

    Hello! I find myself needing to get the new size of a stringcontrol after setting the text, but this is impossible to do on the same frame that the text is set because the control doesn't automatically resize until the next frame. Is it possible to somehow execute code a frame later? Or is there already some sort of update function I'm not aware of? Thanks!


    here is an example of the issue (spell_text control has no set size or bottom anchor, so it is dynamically sized based on its value):
    Code:
    window.spell_text.setValue("long description here");
    new_size_x, new_size_y = window.spell_text.getSize(); -- unexpected behaviour. Returns the size of the control before setting the text value. This needs to be deferred one frame to get the new size
    -- do something with the new size...
    Last edited by GEONE; October 7th, 2023 at 21:38.

  2. #2
    There is no mechanism to do this right now. Since I'm assuming that your anchoring is set up so that elements shift based on the size of the text string, which means that the whole window has to be re-laid out before the new size is known.

    You're best off describing what you want to do, and then others or myself can make suggestions on how to do it like what you want.

    Regards,
    JPG

  3. #3
    Quote Originally Posted by Moon Wizard View Post
    There is no mechanism to do this right now. Since I'm assuming that your anchoring is set up so that elements shift based on the size of the text string, which means that the whole window has to be re-laid out before the new size is known.

    You're best off describing what you want to do, and then others or myself can make suggestions on how to do it like what you want.

    Regards,
    JPG

    I'm trying to get the window height to scale with the textcontrol's size, so if the text flows off the bottom of the window, then the window's height will scale up to accommodate it. I don't want to have to use a scrollbar.

  4. #4
    Hmm, not sure off the top of my head.

    For all the dialogs that I make, I set the height to about 3-5 lines, and have a scrollbar just in case the text goes longer (due to font substitution or other considerations).

    You could do it like the window title that uses a text widget. The main challenge is deciding how "wide" you want to allow before forcing wrapping in a window-based scenario.

    I think it's easier to just leave as a simple dialog for now with a scrollbar, like below

    Code:
    	<windowclass name="dialog_okcancel">
    		<frame>utilitybox</frame>
    		<placement>
    			<size width="300" height="300" />
    			<nosave />
    		</placement>
    		<script>
    			function processOK()
    				....
    				close();
    			end
    			function processCancel()
    				....
    				close();
    			end
    		</script>
    		<sheetdata>
    			<windowtitlebar name="title" />
    			<windowmenubar_utilitybox name="buttonbar" />
    
    			<anchor_content_utilitybox_top />
    			
    			<anchor_content_utilitybox_bottom />
    			<sub_content_bottom name="sub_buttons">
    				<class>dialog_buttons_okcancel</class>
    			</sub_content_bottom>
    
    			<stringc_content_framed_groupbox name="text" />
    			<scrollbar_content_text />
    		</sheetdata>
    	</windowclass>
    Regards,
    JPG

  5. #5
    If it's a one-time layout, you might be able to resize using the onFirstLayout event for the window to get the measure of the control, then use setSize to force another resize (not sure if that will work, but might be worth a try if it's a one-time resize).

    Regards,
    JPG

  6. #6
    Quote Originally Posted by Moon Wizard View Post
    If it's a one-time layout, you might be able to resize using the onFirstLayout event for the window to get the measure of the control, then use setSize to force another resize (not sure if that will work, but might be worth a try if it's a one-time resize).

    Regards,
    JPG
    I had tried using onFirstLayout before, but it was getting called before I was able to set the text.

    I was able to achieve what I wanted via some jank. Instead of setting the text when I needed it to change, I instead created two identical stringcontrols (one with the longer text and 0 alpha font, and one with the shorter text and #FF alpha font) and had the text for both of them set at the same time. Then whenever I needed a size for either of them after that, I could getSize the stringcontrol I needed since the text was already set beforehand. Essentially 'precomputing' the size of the larger stringcontrol and setting the window's size to that when I need it. And swapping them out to display the larger text was as easy as swapping the font's colors.

    It's not a general solution, and it only really works for the specific scenario I needed it for.
    Last edited by GEONE; October 8th, 2023 at 06:47.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in