Page 1 of 1

Changing gui background colors?

Posted: Thu Aug 14, 2025 5:25 am
by scruffyvoltherder
How do i change the background colors of GUI elements like buttons or flows and panes? It doesn't look like that exists as part of luastyle.

Re: Changing gui background colors?

Posted: Thu Aug 14, 2025 8:00 pm
by Osmo
This needs to be done by defining gui styles at data stage https://lua-api.factorio.com/latest/pro ... Style.html

Re: Changing gui background colors?

Posted: Sat Aug 16, 2025 2:03 am
by scruffyvoltherder
Since the style prototype is limited to one total instance, how do i extend that?

Unless I'm just blind, also appears that most of the data-stage style specifications don't have background colors either.

Re: Changing gui background colors?

Posted: Sat Aug 16, 2025 2:13 am
by Rseding91
It’s not a specific color code in the style, but part of the image set used by the style - in the PNG.

Re: Changing gui background colors?

Posted: Sat Aug 16, 2025 5:07 am
by scruffyvoltherder
That's using ElementImageSetLayer?

I'll probably be able to understand that once i'm sober.

How do i add my new styles to the existing GUI style instance?

Re: Changing gui background colors?

Posted: Sat Aug 16, 2025 12:25 pm
by Pi-C
scruffyvoltherder wrote: Sat Aug 16, 2025 5:07 am How do i add my new styles to the existing GUI style instance?
With other prototypes, you'd use something like

Code: Select all

local new_proto = table.deepcopy(data.raw[old_type][old_name])
new_proto.name = new_name
...
data:extend({new_proto})


With GUI-styles, this doesn't work. The only style that will be used is data.raw['gui-style'].default. However, you can add new styles to that! You don't even have to create everything from scratch, just pass on a 'parent' and all properties you don't set directly will be inherited. This is how I've defined styles in Autodrive:

Code: Select all

local styles = {}

-- Define button styles
styles.autodrive_button_off = {
  type = "button_style",
  parent = "shortcut_bar_button",
  padding = 4,
}

styles.autodrive_button_on = {
  type = "button_style",
  parent = "shortcut_bar_button_green",
  padding = 4,
}

-- Define textfield styles
styles.AD_highlighted_value_textfield = {
  type                  = "textbox_style",
  parent                = "highlighted_value_textfield",
  font                  = "default",
  font_color            = {},
}

styles.AD_stretchable_textfield = {
  type                  = "textbox_style",
  parent                = "stretchable_textfield",
  disabled_font         = "default-bold",
  disabled_font_color   = {1, 1, 1, 1},
}


styles.AD_inner_frame = {
    type = "frame_style",
    parent = "inside_shallow_frame_with_padding",
    vertically_stretchable = "on",
    horizontal_align = "center",
    vertical_align = "center",
}

-- Create styles
for s_name, s_data in pairs(styles) do
  data.raw['gui-style'].default[s_name] = s_data
end
Hope that helps! :-)