23#include "../ktech.hpp"
49 std::function<
void()> OnPress,
50 const std::string& key = KTech::Keys::return_,
52 const std::string& text =
"Button",
53 bool withFrame =
false,
56 KTech::RGBA down = KTech::RGBAColors::Widgets::buttonDownBlue)
59 m_unselectedRGBA(unselected),
60 m_selectedRGBA(selected),
62 m_downInvocation(
engine, [this]() -> bool { return RemovePressColor(); })
65 SetText(text, withFrame);
67 m_callbackGroup.RegisterCallback(key, [
this]() ->
bool {
return InsideOnPress(); });
76 void SetText(
const std::string& text,
bool withFrame)
79 if (m_downInvocation.m_active)
81 tempColor = m_downRGBA;
85 tempColor = m_selectedRGBA;
89 tempColor = m_unselectedRGBA;
94 m_textures.resize(TEXTURES_SIZE_FRAMED);
106 m_textures.resize(TEXTURES_SIZE_FRAMELESS);
109 m_textures[ti_text].Write({text}, tempColor, KTech::RGBAColors::transparent,
KTech::Point(1, 1));
113 enum TextureIndex :
size_t
116 TEXTURES_SIZE_FRAMELESS,
117 ti_topLeftCorner = TEXTURES_SIZE_FRAMELESS,
120 ti_bottomRightCorner,
128 KTech::RGBA m_unselectedRGBA, m_selectedRGBA, m_downRGBA;
129 static constexpr size_t pressLength = 100;
132 void OnSelect()
override
137 void OnDeselect()
override
142 void RenderSelected()
146 texture.Transform([&](
KTech::CellA& cell){ cell.
f = m_selectedRGBA; });
150 void RenderUnselected()
154 texture.Transform([&](
KTech::CellA& cell){ cell.
f = m_unselectedRGBA; });
158 auto RemovePressColor() ->
bool
164 texture.Transform([&](
KTech::CellA& cell){ cell.
f = m_selectedRGBA; });
171 texture.Transform([&](
KTech::CellA& cell){ cell.
f = m_unselectedRGBA; });
177 auto InsideOnPress() ->
bool
181 texture.Transform([&](
KTech::CellA& cell){ cell.
f = m_downRGBA; });
183 m_downInvocation.
Invoke(pressLength, KTech::Time::Measurement::milliseconds);
Complete engine containing all engine components.
Definition engine.hpp:41
Like Cell, but with RGBA foreground and background colors, instead of RGB.
Definition cella.hpp:32
RGBA f
Foreground (character) color.
Definition cella.hpp:33
Serializable world structure identifier.
Definition id.hpp:38
2D vector, mostly used to store positions and directions.
Definition point.hpp:30
Like RGB, but also has an alpha channel representing transparency.
Definition rgba.hpp:30
A CellA-based sprite.
Definition texture.hpp:48
Calls a function after a given time.
Definition invocation.hpp:68
void Invoke(long time, Measurement measurement)
Invoke your callback function.
Definition invocation.cpp:82
Unsigned 2D vector, mostly used to store sizes and 2D indexes.
Definition upoint.hpp:29