Help center align "image" via "style_prefix"

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
span4ev
Regular
Posts: 77
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc
Contact:

Help center align "image" via "style_prefix"

#1 Post by span4ev » Thu Aug 04, 2022 10:49 am

1. I can't center "image" via "style_prefix"
2. I just don’t understand how I can center all the elements so as not to write a bunch of the same lines

Code: Select all

vbox:
    style_prefix 'ShopItemMainWin_inner'
    image Transform('bla/bla/bla/bla/bla.jpg', size=(bla,bla)) 

    text 'BlaBla'

    hbox:
        text  "Bla" 
        text  "Bla"
        
# this is not working at all
style ShopItemMainWin_inner_image:
    xalign .5

# but it works for: "text", "frame", "hbox", "button" ...
style ShopItemMainWin_inner_text:
    xalign .5
style ShopItemMainWin_inner_hbox:
    xalign .5
 
But for "image" it doesn't work. But if I do this, then everything will work out

Code: Select all

image Transform('bla/bla/bla/bla/bla.jpg', size=(bla,bla)) xalign .5
1. What and how to write?
2. How would you specify "xalign .5" once for "vbox" so as not to write it a bunch of times?

If I specify this for the parent, it doesn't work.

Code: Select all

style ShopItemMainWin_inner:
    xalign .5

User avatar
m_from_space
Veteran
Posts: 302
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Help center align "image" via "style_prefix"

#2 Post by m_from_space » Sun Aug 07, 2022 3:58 pm

I believe you cannot apply style_prefixes to this keyword (maybe I'm wrong). You can apply a style to each image, but for only one property that of course makes no sense.

Creating an image with a default position can be done via:

Code: Select all

image myimage = Image("myimage.jpg", xalign=0.5)
In this case it will always center itself inside the parent when using the screen keyword add.

Code: Select all

screen myscreen:
    vbox:
        add "myimage"
Another workaround would be to give all your images the same width and center them around a transparent background inside your favorite software.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]