Currently Online

Latest Posts

Topic: Themes; get font_color

kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 19:48
Posts: 2443
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-22, 12: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, 12:04

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

Top Quote
tothxa
Avatar
Joined: 2021-03-24, 11:44
Posts: 439
OS: antix / Debian
Version: some new PR I'm testing
Ranking
Tribe Member
Posted at: 2023-12-22, 14: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, 19:48
Posts: 2443
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-22, 17: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