yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tile_selector_widget.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_WIDGETS_TILE_SELECTOR_WIDGET_H
2#define YAZE_APP_GUI_WIDGETS_TILE_SELECTOR_WIDGET_H
3
4#include <string>
5#include <string_view>
6
10#include "imgui/imgui.h"
11
12namespace yaze::gui {
13
20 public:
21 struct Config {
22 int tile_size = 16;
23 float display_scale = 2.0f;
25 int total_tiles = 512;
26 ImVec2 draw_offset = {2.0f, 0.0f};
27 bool show_tile_ids = false;
28 bool enable_drag = false;
29 bool show_hover_tooltip = false;
31 ImVec4 highlight_color = {1.0f, 0.85f, 0.35f, 1.0f};
32 };
33
34 struct RenderResult {
35 bool tile_clicked = false;
36 bool tile_double_clicked = false;
37 bool tile_right_clicked = false;
38 bool selection_changed = false;
39 bool tile_dragging = false;
40 int selected_tile = -1;
41 };
42
43 enum class JumpToTileResult {
44 kSuccess = 0,
47 };
48
49 explicit TileSelectorWidget(std::string widget_id);
50 TileSelectorWidget(std::string widget_id, Config config);
51
52 void AttachCanvas(Canvas* canvas);
53 void SetTileCount(int total_tiles);
54 void SetSelectedTile(int tile_id);
55 int GetSelectedTileID() const { return selected_tile_id_; }
56 int GetMaxTileId() const { return total_tiles_ > 0 ? total_tiles_ - 1 : 0; }
57 ImVec2 GetGridContentSize() const;
58 float GetPreferredViewportWidth() const;
59
60 RenderResult Render(gfx::Bitmap& atlas, bool atlas_ready);
61
64 bool DrawFilterBar();
65
71 JumpToTileResult JumpToTileFromInput(std::string_view input);
72
73 void ScrollToTile(int tile_id, bool use_imgui_scroll = true);
74 ImVec2 TileOrigin(int tile_id) const;
75
76 // Range filter accessors (for tests and automation)
78 int filter_range_min() const { return filter_range_min_; }
79 int filter_range_max() const { return filter_range_max_; }
80 void SetRangeFilter(int min_id, int max_id);
81 void ClearRangeFilter();
82
83 private:
84 RenderResult HandleInteraction(int tile_display_size);
85 int ResolveTileAtCursor(int tile_display_size) const;
86 void DrawHighlight(int tile_display_size) const;
87 void DrawTileIdLabels(int tile_display_size) const;
88 bool IsValidTileId(int tile_id) const;
89 bool IsInFilterRange(int tile_id) const;
90
91 Canvas* canvas_ = nullptr;
94 int total_tiles_ = 0;
95 std::string widget_id_;
96
97 // Deferred scroll state (for when ScrollToTile is called outside render
98 // context)
99 mutable int pending_scroll_tile_id_ = -1;
100 mutable bool pending_scroll_use_imgui_ = true;
101
102 // Filter bar state
103 char filter_buf_[8] = {};
104
105 // Range filter state
109 char filter_min_buf_[8] = {};
110 char filter_max_buf_[8] = {};
111 // Set when the last range input was invalid (min > max).
113 // Set when both parsed values exceed total_tiles_ so SetRangeFilter returned
114 // without activating (empty interval after clamping).
116 // Status from the most recent jump-to-ID entry attempt.
118};
119
120} // namespace yaze::gui
121
122#endif // YAZE_APP_GUI_WIDGETS_TILE_SELECTOR_WIDGET_H
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:64
Reusable tile selector built on top of Canvas.
JumpToTileResult JumpToTileFromInput(std::string_view input)
int ResolveTileAtCursor(int tile_display_size) const
RenderResult Render(gfx::Bitmap &atlas, bool atlas_ready)
bool IsValidTileId(int tile_id) const
void SetRangeFilter(int min_id, int max_id)
ImVec2 TileOrigin(int tile_id) const
RenderResult HandleInteraction(int tile_display_size)
void ScrollToTile(int tile_id, bool use_imgui_scroll=true)
void DrawTileIdLabels(int tile_display_size) const
void DrawHighlight(int tile_display_size) const
bool IsInFilterRange(int tile_id) const
TileSelectorWidget(std::string widget_id)
Graphical User Interface (GUI) components for the application.