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
20float ResolveDungeonWorkbenchNearbyHeight(float width, float height,
21 float requested_height,
22 float item_spacing) {
23 const float spare = height - width - std::max(item_spacing, 0.0f);
24 const float preview_height = std::min(requested_height, spare);
25 return width > 0.0f && preview_height >= 80.0f ? preview_height : 0.0f;
26}
27
28bool DrawDungeonWorkbenchVerticalSplitter(const char* id, float height,
29 float* pane_width, float min_width,
30 float max_width,
31 bool resize_from_left_edge,
32 float collapse_threshold) {
33 if (!pane_width) {
34 return false;
35 }
36
37 bool collapse_requested = false;
38 const float splitter_width = gui::UIConfig::kSplitterWidth;
39 const ImVec2 splitter_pos = ImGui::GetCursorScreenPos();
40 ImGui::InvisibleButton(id, ImVec2(splitter_width, std::max(height, 1.0f)));
41 const bool hovered = ImGui::IsItemHovered();
42 const bool active = ImGui::IsItemActive();
43 if (hovered || active) {
44 ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
45 }
46 if (hovered && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
47 *pane_width = ClampWorkbenchPaneWidth(*pane_width, min_width, max_width);
48 }
49 if (active) {
50 const float delta = ImGui::GetIO().MouseDelta.x;
51 const float proposed =
52 resize_from_left_edge ? (*pane_width - delta) : (*pane_width + delta);
53 if (proposed < collapse_threshold) {
54 collapse_requested = true;
55 *pane_width = min_width;
56 ImGui::SetTooltip(tr("Collapse pane"));
57 } else {
58 *pane_width = ClampWorkbenchPaneWidth(proposed, min_width, max_width);
59 ImGui::SetTooltip(tr("Width: %.0f px"), *pane_width);
60 }
61 }
62
63 ImVec4 splitter_color = gui::GetOutlineVec4();
64 splitter_color.w = active ? 0.95f : (hovered ? 0.72f : 0.35f);
65 ImGui::GetWindowDrawList()->AddLine(
66 ImVec2(splitter_pos.x + splitter_width * 0.5f, splitter_pos.y),
67 ImVec2(splitter_pos.x + splitter_width * 0.5f, splitter_pos.y + height),
68 ImGui::GetColorU32(splitter_color), active ? 2.0f : 1.0f);
69 return collapse_requested;
70}
71
72} // namespace yaze::editor
Editors are the view controllers for the application.
float ResolveDungeonWorkbenchNearbyHeight(float width, float height, float requested_height, float item_spacing)
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