-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
widgets: add support for specifing size and position options via perc…
…entages of output dimensions (#541) * config: introduce a custom value type for layout related options * widgets: use CLayoutValueData for size and position options * widgets: catch bad_any_cast and out_of_range when contructing widgets other than label * config: rename and restrict CLayoutValueData::fromAny to fromAnyPv This is only for casting `any` variables that represent a void * to a CLayoutValueData*, not just any any. * misc: remove debug prints
- Loading branch information
1 parent
1cd3231
commit 4fc133c
Showing
7 changed files
with
202 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
#include "../helpers/Log.hpp" | ||
#include <hyprutils/math/Vector2D.hpp> | ||
#include <any> | ||
#include <string> | ||
|
||
enum eConfigValueDataTypes { | ||
CVD_TYPE_INVALID = -1, | ||
CVD_TYPE_LAYOUT = 0, | ||
}; | ||
|
||
class ICustomConfigValueData { | ||
public: | ||
virtual ~ICustomConfigValueData() = 0; | ||
|
||
virtual eConfigValueDataTypes getDataType() = 0; | ||
|
||
virtual std::string toString() = 0; | ||
}; | ||
|
||
class CLayoutValueData : public ICustomConfigValueData { | ||
public: | ||
CLayoutValueData() {}; | ||
virtual ~CLayoutValueData() {}; | ||
|
||
virtual eConfigValueDataTypes getDataType() { | ||
return CVD_TYPE_LAYOUT; | ||
} | ||
|
||
virtual std::string toString() { | ||
return std::format("{}{},{}{}", m_vValues.x, (m_sIsRelative.x) ? "%" : "px", m_vValues.y, (m_sIsRelative.y) ? "%" : "px"); | ||
} | ||
|
||
static CLayoutValueData* fromAnyPv(const std::any& v) { | ||
RASSERT(v.type() == typeid(void*), "Invalid config value type"); | ||
const auto P = (CLayoutValueData*)std::any_cast<void*>(v); | ||
RASSERT(P, "Empty config value"); | ||
return P; | ||
} | ||
|
||
Hyprutils::Math::Vector2D getAbsolute(const Hyprutils::Math::Vector2D& viewport) { | ||
return { | ||
(m_sIsRelative.x ? (m_vValues.x / 100) * viewport.x : m_vValues.x), | ||
(m_sIsRelative.y ? (m_vValues.y / 100) * viewport.y : m_vValues.y), | ||
}; | ||
} | ||
|
||
Hyprutils::Math::Vector2D m_vValues; | ||
struct { | ||
bool x = false; | ||
bool y = false; | ||
} m_sIsRelative; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.