Skip to content

Commit

Permalink
input_field: add font_color, font_size, font_family
Browse files Browse the repository at this point in the history
  • Loading branch information
fufexan committed Feb 20, 2024
1 parent 843695b commit 1cbc2b9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
6 changes: 5 additions & 1 deletion src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void CConfigManager::init() {
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", "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", "valign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("input-field", "position", Hyprlang::VEC2{0, -20});
Expand Down Expand Up @@ -96,6 +98,8 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
{"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())},
{"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())},
{"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())},
{"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())},
Expand Down Expand Up @@ -125,4 +129,4 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
}

return result;
}
}
18 changes: 10 additions & 8 deletions src/renderer/widgets/PasswordInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::un
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
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 = posFromHVAlign(viewport, size, pos, std::any_cast<Hyprlang::STRING>(props.at("halign")), std::any_cast<Hyprlang::STRING>(props.at("valign")));
Expand All @@ -21,9 +23,9 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::un
request.id = placeholder.resourceID;
request.asset = placeholderText;
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
request.props["font_family"] = std::string{"Sans"};
request.props["color"] = CColor{1.0 - font.r, 1.0 - font.g, 1.0 - font.b, 0.5};
request.props["font_size"] = (int)size.y / 4;
request.props["font_family"] = font_family;
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"] = font_size;
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
}
}
Expand Down Expand Up @@ -103,7 +105,7 @@ bool CPasswordInputField::draw(const SRenderData& data) {
outer.a = fade.a * data.opacity;
CColor innerCol = inner;
innerCol.a = fade.a * data.opacity;
CColor fontCol = font;
CColor fontCol = font_color;
fontCol.a *= fade.a * data.opacity * passAlpha;

g_pRenderer->renderRect(outerBox, outerCol, outerBox.h / 2.0);
Expand Down Expand Up @@ -179,9 +181,9 @@ void CPasswordInputField::updateFailTex() {
placeholder.failID = request.id;
request.asset = "<span style=\"italic\">" + FAIL.value() + "</span>";
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
request.props["font_family"] = std::string{"Sans"};
request.props["color"] = CColor{1.0 - font.r, 1.0 - font.g, 1.0 - font.b, 0.5};
request.props["font_size"] = (int)size.y / 4;
request.props["font_family"] = font_family;
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"] = font_size;
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);

placeholder.canGetNewFail = false;
Expand Down
18 changes: 10 additions & 8 deletions src/renderer/widgets/PasswordInputField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ class CPasswordInputField : public IWidget {
virtual bool draw(const SRenderData& data);

private:
void updateDots();
void updateFade();
void updateFailTex();
void updateDots();
void updateFade();
void updateFailTex();

Vector2D size;
Vector2D pos;
Vector2D size;
Vector2D pos;

int out_thick;
int out_thick, font_size;

CColor inner, outer, font;
CColor inner, outer, font_color;

std::string font_family;

struct {
float currentAmount = 0;
Expand All @@ -51,4 +53,4 @@ class CPasswordInputField : public IWidget {
} placeholder;

bool fadeOnEmpty;
};
};

0 comments on commit 1cbc2b9

Please sign in to comment.