Added direct theme support and will slowly move more things into this struct for configuring the look.

This commit is contained in:
Zed A. Shaw 2025-05-09 11:20:22 -04:00
parent b9deb3a0de
commit a18d60dcb0
9 changed files with 48 additions and 67 deletions

View file

@ -35,4 +35,21 @@ namespace sfml {
return false;
}
}
guecs::Theme Backend::theme() {
guecs::Theme theme;
theme.PADDING = 3;
theme.BORDER_PX = 1;
theme.TEXT_SIZE = 30;
theme.LABEL_SIZE = 20;
theme.FILL_COLOR = theme.DARK_MID;
theme.TEXT_COLOR = theme.LIGHT_LIGHT;
theme.BG_COLOR = theme.MID;
theme.BORDER_COLOR = theme.LIGHT_DARK;
theme.BG_COLOR_DARK = theme.BLACK;
theme.FONT_FILE_NAME = "assets/text.otf";
return theme;
}
}

View file

@ -2,14 +2,8 @@
#include "guecs/sfml/backend.hpp"
namespace guecs {
static Backend* BACKEND = nullptr;
using std::make_shared;
void init(Backend* backend) {
BACKEND = backend;
}
void Textual::init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText");
if(font == nullptr) font = font_ptr;

11
src/guecs/theme.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "guecs/theme.hpp"
namespace guecs {
Backend* BACKEND = nullptr;
Theme THEME;
void init(Backend* backend) {
BACKEND = backend;
THEME = BACKEND->theme();
}
}

View file

@ -5,7 +5,7 @@ namespace guecs {
using std::make_shared;
UI::UI() {
$font = make_shared<sf::Font>(FONT_FILE_NAME);
$font = make_shared<sf::Font>(THEME.FONT_FILE_NAME);
}
void UI::position(int x, int y, int width, int height) {
@ -180,7 +180,7 @@ namespace guecs {
tc->text->setString(content);
} else {
auto &cell = cell_for(ent);
Textual to_set{content, TEXT_SIZE};
Textual to_set{content, THEME.TEXT_SIZE};
to_set.init(cell, $font);
set<Textual>(ent, to_set);
}
@ -214,9 +214,9 @@ namespace guecs {
tc->text->setString(content);
} else {
auto &cell = cell_for(ent);
Label to_set{content, LABEL_SIZE};
Label to_set{content, THEME.LABEL_SIZE};
to_set.init(cell, $font);
to_set.text->setFillColor(TEXT_COLOR);
to_set.text->setFillColor(THEME.TEXT_COLOR);
set<Label>(ent, to_set);
}
}