yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_workbench_layout.cc
Go to the documentation of this file.
2#include "util/i18n/tr.h"
3
4#include <algorithm>
5
8
9namespace yaze::editor {
10
11namespace {
12
13float ClampWorkbenchPaneWidth(float desired_width, float min_width,
14 float max_width) {
15 return std::clamp(desired_width, min_width, std::max(min_width, max_width));
16}
17
18} // namespace
19
20bool DrawDungeonWorkbenchVerticalSplitter(const char* id, float height,
21 float* pane_width, float min_width,
22 float max_width,
23 bool resize_from_left_edge,
24 float collapse_threshold) {
25 if (!pane_width) {
26 return false;
27 }
28
29 bool collapse_requested = false;
30 const float splitter_width = gui::UIConfig::kSplitterWidth;
31 const ImVec2 splitter_pos = ImGui::GetCursorScreenPos();
32 ImGui::InvisibleButton(id, ImVec2(splitter_width, std::max(height, 1.0f)));
33 const bool hovered = ImGui::IsItemHovered();
34 const bool active = ImGui::IsItemActive();
35 if (hovered || active) {
36 ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
37 }
38 if (hovered && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
39 *pane_width = ClampWorkbenchPaneWidth(*pane_width, min_width, max_width);
40 }
41 if (active) {
42 const float delta = ImGui::GetIO().MouseDelta.x;
43 const float proposed =
44 resize_from_left_edge ? (*pane_width - delta) : (*pane_width + delta);
45 if (proposed < collapse_threshold) {
46 collapse_requested = true;
47 *pane_width = min_width;
48 ImGui::SetTooltip(tr("Collapse pane"));
49 } else {
50 *pane_width = ClampWorkbenchPaneWidth(proposed, min_width, max_width);
51 ImGui::SetTooltip(tr("Width: %.0f px"), *pane_width);
52 }
53 }
54
55 ImVec4 splitter_color = gui::GetOutlineVec4();
56 splitter_color.w = active ? 0.95f : (hovered ? 0.72f : 0.35f);
57 ImGui::GetWindowDrawList()->AddLine(
58 ImVec2(splitter_pos.x + splitter_width * 0.5f, splitter_pos.y),
59 ImVec2(splitter_pos.x + splitter_width * 0.5f, splitter_pos.y + height),
60 ImGui::GetColorU32(splitter_color), active ? 2.0f : 1.0f);
61 return collapse_requested;
62}
63
64} // namespace yaze::editor
Editors are the view controllers for the application.
bool DrawDungeonWorkbenchVerticalSplitter(const char *id, float height, float *pane_width, float min_width, float max_width, bool resize_from_left_edge, float collapse_threshold)
ImVec4 GetOutlineVec4()
static constexpr float kSplitterWidth
Definition ui_config.h:76