fruxo / turbobadger

Small footprint UI library for hardware accelerated games & applications
578 stars 84 forks source link

Reloading skin #90

Open codecat opened 8 years ago

codecat commented 8 years ago

What's the best way to reload a skin at runtime? Currently, I'm using this:

tb::g_tb_skin->UnloadBitmaps();
tb::g_tb_skin->Load("resources/default_skin/skin.tb.txt");
m_root.Invalidate();

This works for colors and such, but not for padding for some reason. Also, would this work on the new shape-based skin system?

codecat commented 8 years ago

I actually just realized it doesn't work for padding because the padding is handled at inflate-time. So that would also ultimately require a reload of all widgets.

fruxo commented 8 years ago

Yes, true. The simple layout that non-TBLayout widgets do, cannot reapply padding like it does when inflated. This is because it doesn't know the difference between widgets that should, and widgets that was given some custom rect programmatically that shouldn't be overwritten.

I think that in the long run, it would be better to always reapply padding & gravity in situations like that (it's also a problem when using strong override with different padding on non-TBLayout layouts). And have a special layout widget (or flag) for when widgets are given custom rects. That should be a rare special case anyway.

fruxo commented 8 years ago

I'll push a fix to shape-rasterizer-3, that makes TBSkin::Load callable multiple times btw. I'll use it to change theme. Same skin and paddings, but with different set of colors.

codecat commented 8 years ago

Thanks for the clarification!