Page 1 of 1

Changing hyperlink style

Posted: Mon Jan 13, 2014 10:47 pm
by Milkymalk
I tried fiddling around with styles a bit and tried to change the style in which hyperlinks appear. The code below works (mostly copied from the hyperlink example), but the hyperlink does not gain focus nor does clicking it do anything anymore. If I comment out the marked line (i.e., don't apply the new style), everything works fine but I changed nothing (of course).

My guess is that I am completely off-track and misunderstood something so badly that I just can't figure out the right way...

Code: Select all

init python:
    style.lexikon = Style(style.hyperlink_text)
    style.lexikon.bold = True
    style.lexikon.color = "#aaaaff"
    style.lexikon.underline = False
    lexikon = Character(None, window_yfill=True, window_xmargin=20, 
                           window_ymargin=20, window_background=Solid((0, 0, 0, 192)))

    def hyperlink_styler(target):
         return style.lexikon

    config.hyperlink_styler = hyperlink_styler           # <----------- crucial line
    
label define_quine:

    lexikon "Quine:\n\nA program that prints itself to its output."

    return
    
# The game starts here.
label start:

    "A game that instructs on how to make a game? Isn't that a sort of {a=define_quine}Quine{/a}?"

    # ...

    return

Re: Changing hyperlink style

Posted: Sat Jan 18, 2014 12:45 am
by PyTom
You probably want to use the hyperlink_functions style property, rather than config.hyperlink_styler.

Code: Select all

init python:
    def hyperlink_styler(target):
        return style.lexicon

    def hyperlink_callback(target):
        # handle click.
        return     

    style.default.hyperlink_functions = (hyperlink_styler, hyperlink_callback, None)
You very likely also want to set your lexicon style to something that changes on mouseover.

Code: Select all

    style.lexikon = Style(style.hyperlink_text)
    style.lexikon.bold = True
    style.lexikon.color = "#aaaaff"
    style.lexikon.underline = False
    style.lexikon.hover_underline = True

Re: Changing hyperlink style

Posted: Wed Jan 22, 2014 12:15 pm
by Milkymalk
To be honest I was fishing in the dark, copying snippets of code that were given for similar questions elsewhere and trying to get them to work like I want.

I found another solution now. But nevertheless thank you, this helped me understand how hyperlink_functions actually works!

This is what I found to work:

Code: Select all

init python:
    style.lexikon = Style(style.say_dialogue)    # base style to work with
    style.lexikon.bold = True
    style.lexikon.color = "#aaaaff"
    style.lexikon.hover_color = "#ffffff"
    style.lexikon.underline = False
    
    style.hyperlink_text = style.lexikon