Currently Online

Latest Posts

Topic: Themes; get font_color

kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2397
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-22, 13:02

Is there a possibility to get the font color currently set by a theme?

Background:
I want to switch between an own color and the font color of the currently used theme, e.g.

local font_clr1 = 202020
local font_clr2 = get_theme_font_color()         -- How to get this color?
local font_clr = 
for i, v in ipairs(table) then
   if math.fmod(i,2) == 0 then                   -- switch color on every loop
      font_clr = font_clr1
   else
      font_clr = font_clr2
   end
   p_font("color="..font_clr, "on every loop this text has a different color") 
end

I have tried to find something in the documentation but it looks like there is no possibility to get any information about the currently used theme.

Edited: 2023-12-22, 13:04

Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
tothxa
Avatar
Joined: 2021-03-24, 12:44
Posts: 425
OS: antix / Debian
Version: some new PR I'm testing
Ranking
Tribe Member
Posted at: 2023-12-22, 15:10

As you're using a predefined alternate colour, I think you could just set the font style, and inside the font tag override the colour, or in your example:

for i, v in ipairs(table) do
   local text = "on every loop this text has a different color"
   if math.fmod(i,2) == 0 then  -- switch color on every loop
      out = out .. p_font("color="..font_clr1, text)
   else
      out = out .. p(text)
   end
end

However, if you really want to adapt to themes, you should derive the alternate colour from the theme's text colour, so it would still be desirable to be able to get it. IIRC from the time I did the paragraph style PR, it's not possible currently.


Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2397
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-22, 18:08

Yes with a single line of text this is possible without much coding. But if the text consists of more text lines this becomes tedious:

for i, v in ipairs(table) do
    local text1 = "on every loop this text has a different color"
    local text2 = "on every loop this text has a different color"
    local text3 = "on every loop this text has a different color"
    [...]
    if math.fmod(i,2) == 0 then  -- switch color on every loop
       out = out .. p_font("color="..font_clr1, text1)
       out = out .. p_font("color="..font_clr1, text2)
       out = out .. p_font("color="..font_clr1, text3) 
       [...]
    else
       out = out .. p(text1)
       out = out .. p(text2)
       out = out .. p(text3)
       [...]
    end
end

Anyway, thanks for your answer! So i am glad that i didn't overlooked something in the big documentation and have to live with that face-smile.png


Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote