数値入力UI
https://scrapbox.io/files/6443a8a0795e2f001cacf159.png
使い方
InputNumber(int32 数値,Vec2 中心の座標,double ボタンの大きさ:省略可,int32 最大桁数:省略可)
用途
ゲーム内の暗号入力などの演出など
コード
code:数値入力.cpp
# include <Siv3D.hpp>
void InputNumber(int32& num, const Vec2& center, double size = 100, int32 maxDigits = 9)
{
const int32 digits = log10(num) + 1;
for (Size p : step({ 3,4 }))
{
const RoundRect rect{ Arg::center(p * size + center - Vec2(size,size * 1.5)),size * 0.8,size * 0.8,size * 0.1 };
int32 n = p.y * 3 + p.x + 1;
String str;
ColorF color;
if (n == 10)
{
color = Palette::Red;
str = U"C";
if (rect.leftClicked())
{
num = 0;
}
}
else if (n == 12)
{
color = Palette::Green;
str = U"<";
if (rect.leftClicked())
{
num /= 10;
}
}
else
{
color = Palette::Black;
if (n == 11)
{
n = 0;
}
str = Format(n);
if (rect.leftClicked() && digits < maxDigits)
{
num = num * 10 + n;
}
}
if (rect.mouseOver())
{
Cursor::RequestStyle(CursorStyle::Hand);
}
rect.draw(rect.leftPressed() ? Palette::Skyblue : Palette::White).drawFrame(size * 0.05, Palette::Gray);
SimpleGUI::GetFont()(str).drawAt(size * 0.5, rect.center(), color);
}
}
void Main()
{
const Font font(60);
int32 num = 0;
while (System::Update())
{
InputNumber(num, Scene::Center());
font(num).draw(Arg::rightCenter(550, 60));
}
}