Cannot load theme file

Started by pinkwar123, 14 July 2023, 06:47:49

pinkwar123

I'm a newbie to this library. I'm trying to build a small dictionary project using some widgets from the library. I'm trying to load themes into my widgets. The theme file is one of the .txt files that I copy from this forum.

First I met the exception at memory location when loading theme from the file. Then when I came across a topic about the exactly the same problem, I got that there are 2 ways that I can do that: putting the theme file in the same folder as .exe file / using the absolute path. Although I tried both ways, I still met the same error: "Unhandled exception at 0x00007FFA9E844B2C in Project1.exe: Microsoft C++ exception: tgui::Exception at memory location 0x00000023777DB708."

The absolute path is : "C:\Users\84903\OneDrive\Desktop\theme.txt"

Could you help me to solve this? Thank you so much!

texus

The "Unhandled exception" means that a tgui::Exception is being thrown that you aren't catching. The exception might have a bit more information about what is going wrong.

You can change your code to something like this:
Code (cpp) Select
int main()
{
    try
    {
        // Existing code here
        return 0;
    }
    catch (const tgui::Exception& e)
    {
        std::cerr << "TGUI exception: " << e.what() << std::endl;
        return 1;
    }
}

Then it would print the information about the exception to the console and exit the program instead of exiting the program with the unhandled exception error.

Hopefully the exception will tell you what the issue is. It's probably either going to be in opening the file or with parsing its contents.
- If the file can't be opened, make sure the path is correct. If a relative path doesn't work, try with an absolute path (but make sure to escape your "\" characters in the string or to use "/" instead). If an absolute path does work, then maybe your working directory isn't where you think it is.
- If the issue is with parsing the contents, then double check that you are using a theme file from the same TGUI version than you are using.

pinkwar123

#2
Thank you so much for your quick response. After modifying the code as what you've suggested, this is what I got:
"TGUI exception: Error while parsing input at line 2. Found '{' while trying to read a value."

So is this simply because the theme file came from a different version?. This is the theme file:

Button {
Texture         = ${blue_button00:10};
TextureHover    = ${blue_button01:10};
TextureDown     = ${blue_button03:10};
TextureFocused  = ${blue_button01:10};
TextureDisabled = ${grey_button05:10};
TextColor       = rgb(250, 250, 250);
TextColorDisabled = rgb(100, 100, 100);
}

ChatBox {
TextureBackground = ${blue_button05:10};
Scrollbar         = &Scrollbar;
Padding           = (3, 3, 3, 3);
}

Checkbox {
TextureUnchecked        = ${grey_box};
TextureChecked          = ${blue_boxCheckmark};
TextColor               = rgb(100, 100, 100);
TextColorHover          = Black;
}

ChildWindow {
TextureTitlebar        = ${blue_button05:10o-10};
TitleColor             = White;
TextureBackground      = ${grey_panel:10o+10};
BorderColor            = Black;
DistanceToSide         = 5;
PaddingBetweenButtons  = 2;
ShowTextOnTitleButtons = false;
CloseButton = {
Texture       = ${red_cross};
};
}

ComboBox {
TextureBackground     = ${blue_button00:10};
TextureArrow          = ${grey_arrowDownGrey};
TextureArrowHover     = ${grey_arrowDownWhite};
TextColor             = rgb(190, 190, 190);
Padding               = (3, 3, 3, 3);
ListBox               = &ListBox;
}

EditBox {
Texture        = ${grey_button06:10};
TextureHover   = ${grey_button05:10};
TextureFocused = ${grey_button05:10};

TextColor                   = rgb(100, 100, 100);
SelectedTextColor           = White;
SelectedTextBackgroundColor = rgb( 10, 110, 255);
DefaultTextColor            = rgb(120, 120, 120);
CaretColor                  = rgb(110, 110, 255);
Padding                     = (6, 4, 6, 4);
}

Label {
TextColor = rgb(190, 190, 190);
Scrollbar = &Scrollbar;
}

ListBox {
TextureBackground = ${grey_panel:10};

TextColor                    = rgb(100, 100, 100);
TextColorHover               = rgb(250, 250, 250);
BackgroundColorHover         = rgb(17, 70, 92);
SelectedBackgroundColor      = rgb(35, 140, 184);
SelectedTextColor            = White;
Padding                      = (3, 3, 3, 3);
Scrollbar                    = &Scrollbar;
}

ListView {
TextColor                    = rgb(190, 190, 190);
TextColorHover               = rgb(250, 250, 250);
BackgroundColor              = rgb( 80,  80,  80);
BackgroundColorHover         = rgb(100, 100, 100);
SelectedBackgroundColor      = rgb( 10, 110, 255);
SelectedBackgroundColorHover = rgb(30, 150, 255);
SelectedTextColor            = White;
Padding                      = (3, 3, 3, 3);
Scrollbar                    = &Scrollbar;
}

MenuBar {
TextureBackground             = ${blue_button00:10};
TextureItemBackground         = ${blue_button00:10};
TextureSelectedItemBackground = ${blue_button00:10};
TextColor                     = rgb(190, 190, 190);
SelectedTextColor             = White;
DistanceToSide                = 5;
}

MessageBox {
TextColor       = rgb(190, 190, 190);
Button          = &Button;

TextureTitlebar = ${blue_button05:10};
TitleColor      = rgb(190, 190, 190);
BackgroundColor = rgb( 80,  80,  80);
BorderColor     = Black;
Borders         = (1, 1, 1, 1);
DistanceToSide  = 5;
CloseButton     = {
Texture = ${red_cross};
};
}

Panel {
TextureBackground = ${grey_panel:10};
}

ProgressBar {
TextureBackground = ${grey_button05:5};
TextureFill       = ${blue_button01:5};
TextColor         = rgb(190, 190, 190);
TextColorFilled   = rgb(250, 250, 250);
}

RadioButton {
TextureUnchecked        = ${grey_circle};
TextureChecked          = ${blue_boxTick};
TextureUncheckedHover   = ${grey_circle};
TextureCheckedHover     = ${blue_boxTick};
TextureUncheckedFocused = ${grey_circle};
TextureCheckedFocused   = ${blue_boxTick};
TextColor               = rgb(190, 190, 190);
TextColorHover          = rgb(250, 250, 250);
}

Scrollbar {
TextureTrack          = ${grey_sliderVertical};
TextureTrackHover     = ${grey_sliderVertical};
TextureThumb          = ${blue_button07:10};
TextureThumbHover     = ${blue_button08:10};
TextureArrowUp        = ${blue_sliderUp};
TextureArrowUpHover   = ${blue_sliderUp};
TextureArrowDown      = ${blue_sliderDown};
TextureArrowDownHover = ${blue_sliderDown};
}

Slider {
TextureTrack      = ${grey_sliderHorizontal};
TextureTrackHover = ${grey_sliderHorizontal};
TextureThumb      = ${grey_sliderUp};
}

SpinButton {
TextureArrowUp        = ${grey_arrowUpGrey};
TextureArrowUpHover   = ${grey_arrowUpWhite};
TextureArrowDown      = ${grey_arrowDownGrey};
TextureArrowDownHover = ${grey_arrowDownWhite};
BorderBetweenArrows    = 0;
}

Tabs {
TextureTab         = ${grey_button13};
TextureSelectedTab = ${blue_button08};
TextColor          = rgb(190, 190, 190);
SelectedTextColor  = White;
DistanceToSide     = 8;
}

TextBox {
TextureBackground           = ${grey_button06:10};
TextColor                   = rgb(190, 190, 190);
SelectedTextColor           = White;
SelectedTextBackgroundColor = rgb( 10, 110, 255);
CaretColor                  = rgb(110, 110, 255);
Padding                     = (3, 3, 3, 3);
Scrollbar                   = &Scrollbar;
}

ToolTip {
TextColor       = rgb(190, 190, 190);
BackgroundColor = rgb( 80,  80,  80);
BorderColor     = Black;
Borders         = (1, 1, 1, 1);
Padding         = (2, 2, 2, 2);
}

ItemSlot {
BackgroundColor = rgba(255, 255, 255, 0);
BackgroundColorHover = rgba(255, 255, 255, 50);
}

texus

That is not a valid theme file in any TGUI version.
Wherever you found that file probably also has a small tool to convert it into a valid TGUI theme.

You can find the official theme files from TGUI in the "themes" folder of the TGUI files that you downloaded.

pinkwar123

Thank you so much for your instructions. I've managed to load the file in the right way. It turned out that the file is in wrong format. Following your instructions, I used the file from the folder downloaded officially, and it works so me. Thanks for your dedication!!