/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include REGISTER_WIDGET(GUI, SpinBox) namespace GUI { SpinBox::SpinBox() { set_min_size({ 40, 22 }); set_preferred_size({ SpecialDimension::OpportunisticGrow, 22 }); m_editor = add(); m_editor->set_text("0"sv); m_editor->on_change = [this, weak_this = make_weak_ptr()] { if (!weak_this) return; auto value = m_editor->text().to_uint(); if (value.has_value()) set_value(value.value()); else m_editor->set_text(String::number(m_value)); }; m_editor->on_up_pressed = [this] { set_value(m_value + 1); }; m_editor->on_down_pressed = [this] { set_value(m_value - 1); }; m_editor->on_return_pressed = [this] { if (on_return_pressed) on_return_pressed(); }; m_increment_button = add