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 selection_changed = false;
38 bool tile_dragging = false;
39 int selected_tile = -1;
40 };
41
42 enum class JumpToTileResult {
43 kSuccess = 0,
46 };
47
48 explicit TileSelectorWidget(std::string widget_id);
49 TileSelectorWidget(std::string widget_id, Config config);
50
51 void AttachCanvas(Canvas* canvas);
52 void SetTileCount(int total_tiles);
53 void SetSelectedTile(int tile_id);
54 int GetSelectedTileID() const { return selected_tile_id_; }
55 int GetMaxTileId() const { return total_tiles_ > 0 ? total_tiles_ - 1 : 0; }
56
57 RenderResult Render(gfx::Bitmap& atlas, bool atlas_ready);
58
61 bool DrawFilterBar();
62
68 JumpToTileResult JumpToTileFromInput(std::string_view input);
69
70 void ScrollToTile(int tile_id, bool use_imgui_scroll = true);
71 ImVec2 TileOrigin(int tile_id) const;
72
73 // Range filter accessors (for tests and automation)
75 int filter_range_min() const { return filter_range_min_; }
76 int filter_range_max() const { return filter_range_max_; }
77 void SetRangeFilter(int min_id, int max_id);
78 void ClearRangeFilter();
79
80 private:
81 RenderResult HandleInteraction(int tile_display_size);
82 int ResolveTileAtCursor(int tile_display_size) const;
83 void DrawHighlight(int tile_display_size) const;
84 void DrawTileIdLabels(int tile_display_size) const;
85 bool IsValidTileId(int tile_id) const;
86 bool IsInFilterRange(int tile_id) const;
87
88 Canvas* canvas_ = nullptr;
91 int total_tiles_ = 0;
92 std::string widget_id_;
93
94 // Deferred scroll state (for when ScrollToTile is called outside render
95 // context)
96 mutable int pending_scroll_tile_id_ = -1;
97 mutable bool pending_scroll_use_imgui_ = true;
98
99 // Filter bar state
100 char filter_buf_[8] = {};
101
102 // Range filter state
106 char filter_min_buf_[8] = {};
107 char filter_max_buf_[8] = {};
108 // Set when the last range input was invalid (min > max).
110 // Set when both parsed values exceed total_tiles_ so SetRangeFilter returned
111 // without activating (empty interval after clamping).
113 // Status from the most recent jump-to-ID entry attempt.
115};
116
117} // namespace yaze::gui
118
119#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:150
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.