-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79c8c74
commit d9c2053
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#pragma once | ||
|
||
#include "tactile/base/prelude.hpp" | ||
#include "tactile/core/ui/common/icons.hpp" | ||
|
||
namespace tactile::ui { | ||
|
||
/// \addtogroup UI | ||
/// \{ | ||
|
||
/** | ||
* Adds a button to the widget stack. | ||
* | ||
* \param label The text label to use. | ||
* \param tooltip An optional tooltip. | ||
* \param enabled Controls whether the button is pressable. | ||
* \param width The width of the button. Pass \c 0 to use automatic width. | ||
* \param height The height of the button. Pass \c 0 to use automatic height. | ||
* | ||
* \return | ||
* True if the button was pressed; false otherwise. | ||
*/ | ||
[[nodiscard]] | ||
auto push_button(const char* label, | ||
const char* tooltip = nullptr, | ||
bool enabled = true, | ||
float width = 0.0f, | ||
float height = 0.0f) -> bool; | ||
|
||
/** | ||
* Adds an icon button to the widget stack. | ||
* | ||
* \param icon The icon to use. | ||
* \param tooltip An optional tooltip. | ||
* \param enabled Controls whether the button is pressable. | ||
* | ||
* \return | ||
* True if the button was pressed; false otherwise. | ||
*/ | ||
[[nodiscard]] | ||
auto push_icon_button(Icon icon, | ||
const char* tooltip = nullptr, | ||
bool enabled = true) -> bool; | ||
|
||
/// \} | ||
|
||
} // namespace tactile::ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#include "tactile/core/ui/common/buttons.hpp" | ||
|
||
#include <imgui.h> | ||
|
||
#include "tactile/core/ui/common/widgets.hpp" | ||
|
||
namespace tactile::ui { | ||
|
||
auto push_button(const char* label, | ||
const char* tooltip, | ||
const bool enabled, | ||
const float width, | ||
const float height) -> bool | ||
{ | ||
const DisabledScope disable {!enabled}; | ||
|
||
const auto was_pressed = ImGui::Button(label, ImVec2 {width, height}); | ||
|
||
if (ImGui::IsItemHovered()) { | ||
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); | ||
|
||
if (tooltip != nullptr) { | ||
ImGui::SetTooltip("%s", tooltip); | ||
} | ||
} | ||
|
||
return was_pressed; | ||
} | ||
|
||
auto push_icon_button(const Icon icon, | ||
const char* tooltip, | ||
const bool enabled) -> bool | ||
{ | ||
const auto* icon_string = to_string(icon); | ||
|
||
const auto& style = ImGui::GetStyle(); | ||
const auto side_length = ImGui::GetFontSize() + style.ItemSpacing.y * 2.0f; | ||
|
||
return push_button(icon_string, tooltip, enabled, side_length, side_length); | ||
} | ||
|
||
} // namespace tactile::ui |