palladium/include/pd/ui7/container/checkbox.hpp
tobid7 35272687f6 # Changes 0.3.1
- Add Layout API and let Menu use it
- Add DragData (for float, double, int, etc)
- Add IO Delta calculation to not require a users delta value
- Add Config Var for SLider drag min size
- Remove Hid::Ref input of Containers as IO DragApi is used
- Containers that accept input will require an ID to function
2025-03-14 15:14:45 +01:00

72 lines
2.4 KiB
C++

#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Checkbox Object
* @note The Updated input is available after
* Context::Update while the visual update is done
* during the Update
*/
class Checkbox : public Container {
public:
/**
* Constructor for Checkbox Object
* @param label Label of the Checkbox
* @param usr_ref Reference to the bool value to update
* @param io IO Reference
*/
Checkbox(const std::string& label, bool& usr_ref, UI7::IO::Ref io)
: usr_ref(usr_ref) {
this->label = label;
this->tdim = io->Ren->GetTextDimensions(label);
}
~Checkbox() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Update Size if framepadding changed */
void Update() override;
private:
vec2 tdim; ///< Text Size
vec2 cbs = vec2(18); ///< Checkbox size
UI7Color color = UI7Color_FrameBackground; ///< Checkbox background Color
std::string label; ///< Checkbox Label
bool& usr_ref; ///< User bool reference
};
} // namespace UI7
} // namespace PD