[SOLVED] Changing fonts for a custom window

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
theyeeguy
Newbie
Posts: 12
Joined: Mon Sep 20, 2021 7:11 am
Contact:

[SOLVED] Changing fonts for a custom window

#1 Post by theyeeguy »

Been tinkering around with Ren'Py lately, and I decided to make both gui.rpy and screens.rpy from scratch in order to better understand the engine. I kind of get how some things work now, but currently I'm stuck on how to change the font for the text in a custom window I named (following the default say screen format). Usually I just modify it using define gui.name_text_font = "DejaVuSans.ttf" but due to my window being renamed I can't do that anymore.

Here's the code (so far) for my new screens.rpy:

Code: Select all

screen say(who,what):

    window:
        id "sayBox"
        style "sayBox_style"

        ##### if who has value, also display window id nameBox #####
        if who is not None:

            window:
                id "nameBox"
                style "nameBox_style"

                text who id "who_s"

        text what id "what"

style sayBox_style:
    #anchor
    xanchor 0
    yanchor 0
    #position
    xpos 0
    ypos 500
    #size
    xsize 500
    ysize 200

style nameBox_style:

    properties gui.text_properties("nameBox_style")
    #anchor
    xanchor 0
    yanchor 0
    #position
    xpos 0
    yoffset -50
    #size
    xsize 500
    ysize None

    background "#000000"
while here's the (currently non working) code for my gui.rpy

Code: Select all

init python:
    gui.init(1280, 720)

define gui.nameBox_style_text_font = "RobotoCondensed-Bold.ttf"
I'm specifically asking on how to change the text in the window with id nameBox. Since text cannot be modified through style, I tried using the code in my gui.rpy but it doesn't seem to work. I looked through previous posts in the forum but none of them don't seem to be similar to my case (or are outdated)

Secondary question: How do I make it so that I can "define" a custom made text/window/frame through gui.rpy? Is properties gui.text_properties("nameBox_style") not the correct way to do it?

I really want to learn the engine thoroughly and not just modify variables since I'm eager to make a amazing things with it. Any help would be greatly appreciated.
Last edited by theyeeguy on Tue Sep 21, 2021 7:45 am, edited 1 time in total.

jeffster
Veteran
Posts: 361
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Changing fonts for a custom window

#2 Post by jeffster »

You can point a screen element with a mouse and press shift-i to view the structure of the displayables and the styles applied.

Style names apply automatically according to a simple algorithm. See:

https://www.renpy.org/doc/html/style.html
https://www.renpy.org/doc/html/style_pr ... fix-search

Look in the original screens.rpy how various elements get styled.

Maybe instead of

Code: Select all

define gui.nameBox_style_text_font = "RobotoCondensed-Bold.ttf"
do just

Code: Select all

style nameBox_style:
    font "RobotoCondensed-Bold.ttf"

theyeeguy
Newbie
Posts: 12
Joined: Mon Sep 20, 2021 7:11 am
Contact:

Re: Changing fonts for a custom window

#3 Post by theyeeguy »

jeffster wrote: Mon Sep 20, 2021 2:07 pm You can point a screen element with a mouse and press shift-i to view the structure of the displayables and the styles applied.

Style names apply automatically according to a simple algorithm. See:

https://www.renpy.org/doc/html/style.html
https://www.renpy.org/doc/html/style_pr ... fix-search

Look in the original screens.rpy how various elements get styled.

Maybe instead of

Code: Select all

define gui.nameBox_style_text_font = "RobotoCondensed-Bold.ttf"
do just

Code: Select all

style nameBox_style:
    font "RobotoCondensed-Bold.ttf"
That was actually the first method I thought of when I troubleshooted the problem. Unfortunately I wasn't able to influence the text in any way. I even tried putting in a size 48 just in case it was a problem with locating the font but alas the text still stayed the same. I have tried replicating the solution just now but as expected it did not change at all.

jeffster
Veteran
Posts: 361
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Changing fonts for a custom window

#4 Post by jeffster »

OK. you got me curious, and I actually looked at your code and checked it with inspector (shift-i). I think you should use "style_prefix" rather than "style". Otherwise you assign the style to "window" but not to the text. Alternatively, you could assign the style to the text:

Code: Select all

        if who is not None:

            window:
                id "nameBox"
                style "nameBox_style"

                text who id "who_s" style "nameBox_style"

        text what id "what"

theyeeguy
Newbie
Posts: 12
Joined: Mon Sep 20, 2021 7:11 am
Contact:

Re: Changing fonts for a custom window

#5 Post by theyeeguy »

Thank you very much! Code presented above did the trick. I even managed to modify it through gui.rpy.

Although I did have trouble understanding what you meant by using style_prefix. Reading the documentation I couldn't find examples of using it. Would you mind explaining what it does if it's not too much trouble?

jeffster
Veteran
Posts: 361
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: [SOLVED] Changing fonts for a custom window

#6 Post by jeffster »

Eventually, I think it should be like this:

1. In unique cases (like setting the game title font in the Main menu, or making a specific screen not like any other screens), we can just put properties to the displayables:

Code: Select all

    text title align (0.5, 0.5) size 72 font "images/fonts/Nouveau.ttf"
# or in a block:
    text config.version:
        align (0.5, 0.5) 
        yoffset 100
        font "images/fonts/FiraCode.ttf"
2. When using some styles repeatedly, write them directly in screens.rpy:

Code: Select all

style slot_button_text is gui_button_text
style slot_button_text:
    outlines[(absolute(1), "#000", 0, 0)]
    idle_color "#DDD"
    selected_idle_color "#FFF"
    selected_hover_color "#A3E066"
3. When we reuse the same settings in more than one style we can define them in gui.rpy. Maybe we can also make several "themes" (like: day, night, azure, olive, high_contrast) and keep them as settings in gui.rpy, easy to switch.
style_prefix
See "Using styles and style inheritance":
https://www.renpy.org/doc/html/style.ht ... nheritance

It might be not quite intuitive because it's a bit different from css/html, but I think I will make some effort now and re-read that part.

Usually, docs for Ren'Py are relatively easy to find using search field on https://www.renpy.org/

Good luck in making interesting programs, bro (to all of us)!

theyeeguy
Newbie
Posts: 12
Joined: Mon Sep 20, 2021 7:11 am
Contact:

Re: [SOLVED] Changing fonts for a custom window

#7 Post by theyeeguy »

I kind of understand now. I'll try reading up more on it in the future. Thanks once again!

Good luck to all of us indeed o/

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], downover