make a SameLineOrWrap helper and fix wrapping bug introduced by switching to the docking branch of imgui

This commit is contained in:
Sven Balzer 2025-03-27 12:45:45 +01:00
parent e19a13c354
commit e5d90533dd

View File

@ -1356,6 +1356,13 @@ void change_map_tile(V2 pos, TileKind kind) {
update_buffer(current_map.gpu_buffer, 0, current_map.width * current_map.height * sizeof(Uint32), current_map.tiles);
}
static void SameLineOrWrap(const ImVec2& size) {
ImGuiWindow *window = ImGui::GetCurrentWindow();
ImVec2 pos = ImVec2(window->DC.CursorPosPrevLine.x + ImGui::GetStyle().ItemSpacing.x, window->DC.CursorPosPrevLine.y);
if (window->WorkRect.Contains(ImRect(pos, pos + size)))
ImGui::SameLine();
}
int main(int argc, char **argv) {
setup_memory_functions();
@ -1672,9 +1679,8 @@ int main(int argc, char **argv) {
ImVec2 uv0 = ImVec2(0, 0);
ImVec2 uv1 = ImVec2(1, 1);
float available = ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x;
if (available >= 32)
ImGui::SameLine();
if (i != 0)
SameLineOrWrap(ImVec2(32, 32));
if (SelectableTile("##tile", selected_tile == i, &tile_atlas_texture_binding, i, ImVec2(32, 32), uv0, uv1, SDL_max(selected_rotation, 0))) {
selected_tile_kind = -1;
@ -1693,21 +1699,16 @@ int main(int argc, char **argv) {
if (SelectableTile("##None", selected_rotation == 0, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 0))
selected_rotation = 0;
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
ImGui::SameLine();
SameLineOrWrap(ImVec2(32, 32));
if (SelectableTile("##90", selected_rotation == 1, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 1))
selected_rotation = 1;
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
ImGui::SameLine();
SameLineOrWrap(ImVec2(32, 32));
if (SelectableTile("##180", selected_rotation == 2, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 2))
selected_rotation = 2;
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
ImGui::SameLine();
SameLineOrWrap(ImVec2(32, 32));
if (SelectableTile("##270", selected_rotation == 3, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 3))
selected_rotation = 3;