input_field: add font_color, font_size, font_family

This commit is contained in:
Mihai Fufezan 2024-02-20 16:28:02 +02:00
parent 843695b0b0
commit 1cbc2b9c22
No known key found for this signature in database
3 changed files with 25 additions and 17 deletions

View file

@ -35,6 +35,8 @@ void CConfigManager::init() {
m_config.addSpecialConfigValue("input-field", "outline_thickness", Hyprlang::INT{4}); m_config.addSpecialConfigValue("input-field", "outline_thickness", Hyprlang::INT{4});
m_config.addSpecialConfigValue("input-field", "fade_on_empty", Hyprlang::INT{1}); m_config.addSpecialConfigValue("input-field", "fade_on_empty", Hyprlang::INT{1});
m_config.addSpecialConfigValue("input-field", "font_color", Hyprlang::INT{0xFF000000}); m_config.addSpecialConfigValue("input-field", "font_color", Hyprlang::INT{0xFF000000});
m_config.addSpecialConfigValue("input-field", "font_family", Hyprlang::STRING{"Sans"});
m_config.addSpecialConfigValue("input-field", "font_size", Hyprlang::INT{12});
m_config.addSpecialConfigValue("input-field", "halign", Hyprlang::STRING{"center"}); m_config.addSpecialConfigValue("input-field", "halign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("input-field", "valign", Hyprlang::STRING{"center"}); m_config.addSpecialConfigValue("input-field", "valign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("input-field", "position", Hyprlang::VEC2{0, -20}); m_config.addSpecialConfigValue("input-field", "position", Hyprlang::VEC2{0, -20});
@ -96,6 +98,8 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
{"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", k.c_str())}, {"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", k.c_str())},
{"fade_on_empty", m_config.getSpecialConfigValue("input-field", "fade_on_empty", k.c_str())}, {"fade_on_empty", m_config.getSpecialConfigValue("input-field", "fade_on_empty", k.c_str())},
{"font_color", m_config.getSpecialConfigValue("input-field", "font_color", k.c_str())}, {"font_color", m_config.getSpecialConfigValue("input-field", "font_color", k.c_str())},
{"font_family", m_config.getSpecialConfigValue("input-field", "font_family", k.c_str())},
{"font_size", m_config.getSpecialConfigValue("input-field", "font_size", k.c_str())},
{"halign", m_config.getSpecialConfigValue("input-field", "halign", k.c_str())}, {"halign", m_config.getSpecialConfigValue("input-field", "halign", k.c_str())},
{"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())}, {"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())},
{"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())}, {"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())},
@ -125,4 +129,4 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
} }
return result; return result;
} }

View file

@ -9,7 +9,9 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::un
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color")); outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness")); out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty")); fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
font = std::any_cast<Hyprlang::INT>(props.at("font_color")); font_color = std::any_cast<Hyprlang::INT>(props.at("font_color"));
font_family = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
font_size = std::any_cast<Hyprlang::INT>(props.at("font_size"));
pos = std::any_cast<Hyprlang::VEC2>(props.at("position")); pos = std::any_cast<Hyprlang::VEC2>(props.at("position"));
pos = posFromHVAlign(viewport, size, pos, std::any_cast<Hyprlang::STRING>(props.at("halign")), std::any_cast<Hyprlang::STRING>(props.at("valign"))); pos = posFromHVAlign(viewport, size, pos, std::any_cast<Hyprlang::STRING>(props.at("halign")), std::any_cast<Hyprlang::STRING>(props.at("valign")));
@ -21,9 +23,9 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::un
request.id = placeholder.resourceID; request.id = placeholder.resourceID;
request.asset = placeholderText; request.asset = placeholderText;
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT; request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
request.props["font_family"] = std::string{"Sans"}; request.props["font_family"] = font_family;
request.props["color"] = CColor{1.0 - font.r, 1.0 - font.g, 1.0 - font.b, 0.5}; request.props["color"] = CColor{1.0 - font_color.r, 1.0 - font_color.g, 1.0 - font_color.b, 0.5};
request.props["font_size"] = (int)size.y / 4; request.props["font_size"] = font_size;
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
} }
} }
@ -103,7 +105,7 @@ bool CPasswordInputField::draw(const SRenderData& data) {
outer.a = fade.a * data.opacity; outer.a = fade.a * data.opacity;
CColor innerCol = inner; CColor innerCol = inner;
innerCol.a = fade.a * data.opacity; innerCol.a = fade.a * data.opacity;
CColor fontCol = font; CColor fontCol = font_color;
fontCol.a *= fade.a * data.opacity * passAlpha; fontCol.a *= fade.a * data.opacity * passAlpha;
g_pRenderer->renderRect(outerBox, outerCol, outerBox.h / 2.0); g_pRenderer->renderRect(outerBox, outerCol, outerBox.h / 2.0);
@ -179,9 +181,9 @@ void CPasswordInputField::updateFailTex() {
placeholder.failID = request.id; placeholder.failID = request.id;
request.asset = "<span style=\"italic\">" + FAIL.value() + "</span>"; request.asset = "<span style=\"italic\">" + FAIL.value() + "</span>";
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT; request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
request.props["font_family"] = std::string{"Sans"}; request.props["font_family"] = font_family;
request.props["color"] = CColor{1.0 - font.r, 1.0 - font.g, 1.0 - font.b, 0.5}; request.props["color"] = CColor{1.0 - font_color.r, 1.0 - font_color.g, 1.0 - font_color.b, 0.5};
request.props["font_size"] = (int)size.y / 4; request.props["font_size"] = font_size;
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
placeholder.canGetNewFail = false; placeholder.canGetNewFail = false;

View file

@ -17,16 +17,18 @@ class CPasswordInputField : public IWidget {
virtual bool draw(const SRenderData& data); virtual bool draw(const SRenderData& data);
private: private:
void updateDots(); void updateDots();
void updateFade(); void updateFade();
void updateFailTex(); void updateFailTex();
Vector2D size; Vector2D size;
Vector2D pos; Vector2D pos;
int out_thick; int out_thick, font_size;
CColor inner, outer, font; CColor inner, outer, font_color;
std::string font_family;
struct { struct {
float currentAmount = 0; float currentAmount = 0;
@ -51,4 +53,4 @@ class CPasswordInputField : public IWidget {
} placeholder; } placeholder;
bool fadeOnEmpty; bool fadeOnEmpty;
}; };