<commit_before>#include "halley/ui/widgets/ui_spin_control.h"
#include "halley/ui/widgets/ui_button.h"
#include "halley/ui/ui_validator.h"
using namespace Halley;

UISpinControl::UISpinControl(std::shared_ptr<InputKeyboard> keyboard, String id, UIStyle style, int value)
	: UIWidget(id, {}, UISizer())
	, value(value)
{
	textInput = std::make_shared<UITextInput>(keyboard, id + "_textinput", style.getSubStyle("input"), toString(value));
	textInput->setValidator(std::make_shared<UINumericValidator>(true));

	const auto leftButton = std::make_shared<UIButton>(id + "_left", style.getSubStyle("leftButton"));
	const auto rightButton = std::make_shared<UIButton>(id + "_right", style.getSubStyle("rightButton"));
	UIWidget::add(leftButton);
	UIWidget::add(textInput, 1);
	UIWidget::add(rightButton);

	setHandle(UIEventType::ButtonClicked, id + "_left", [=] (const UIEvent& event)
	{
		setValue(getValue() - 1);
	});
	setHandle(UIEventType::ButtonClicked, id + "_right", [=] (const UIEvent& event)
	{
		setValue(getValue() + 1);
	});
}

void UISpinControl::setValue(int v)
{
	int finalValue = v;
	if (minValue) {
		finalValue = std::max(finalValue, int(*minValue));
	}
	if (maxValue) {
		finalValue = std::max(finalValue, int(*maxValue));<commit_msg>Fix text input on spin control.<commit_after>#include "halley/ui/widgets/ui_spin_control.h"
#include "halley/ui/widgets/ui_button.h"
#include "halley/ui/ui_validator.h"
using namespace Halley;

UISpinControl::UISpinControl(std::shared_ptr<InputKeyboard> keyboard, String id, UIStyle style, int value)
	: UIWidget(id, {}, UISizer())
	, value(value)
{
	textInput = std::make_shared<UITextInput>(keyboard, id + "_textinput", style.getSubStyle("input"), toString(value));
	textInput->setValidator(std::make_shared<UINumericValidator>(true));

	const auto leftButton = std::make_shared<UIButton>(id + "_left", style.getSubStyle("leftButton"));
	const auto rightButton = std::make_shared<UIButton>(id + "_right", style.getSubStyle("rightButton"));
	UIWidget::add(leftButton, 0, Vector4f(), UISizerAlignFlags::Centre);
	UIWidget::add(textInput, 1);
	UIWidget::add(rightButton, 0, Vector4f(), UISizerAlignFlags::Centre);

	setHandle(UIEventType::ButtonClicked, id + "_left", [=] (const UIEvent& event)
	{
		setValue(getValue() - 1);
	});
	setHandle(UIEventType::ButtonClicked, id + "_right", [=] (const UIEvent& event)
	{
		setValue(getValue() + 1);
	});
	setHandle(UIEventType::TextChanged, id + "_textinput", [=] (const UIEvent& event)
	{
		setValue(event.getData().toInteger());
	});
}

void UISpinControl::setValue(int v)
{
	int finalValue = v;
	if (minValue) {
		finalValue = std::max(finalValue, int(*minValue));
	}
	if (maxValue) {
		finalValue = std::max(finalValue, int(*maxValue));
{'fraction_non_alphanumeric': 0.17130307467057102, 'fraction_numerical': 0.0036603221083455345, 'mean_word_length': 7.306990881458966, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6264446', 'n_tokens_mistral': 972, 'n_tokens_neox': 962, 'n_words': 167}