Repository: godotengine/godot
File: scene/gui/texture_rect.cpp (C++)

Code before:

					region.position = ((scaled_tex_size - size) / scale).abs() / 2.0f;
					region.size = size / scale;
				} break;
			}

			size.width *= hflip ? -1.0f : 1.0f;
			size.height *= vflip ? -1.0f : 1.0f;

			if (region.has_area()) {
				draw_texture_rect_region(texture, Rect2(offset, size), region);
			} else {
				// `draw_texture_rect` doesn't support tiling an AtlasTexture.
				// Workaround using nine patch. Doesn't work properly for non-zero margin, nesting AtlasTextures is fine otherwise.
				if (tile && Object::cast_to<AtlasTexture>(*texture)) {
					Rect2 src_rect(Vector2(), texture->get_size());
					Rect2 dst_rect(offset, size);
					bool has_margin = false;
					Ref<AtlasTexture> at = texture;
					while (at.is_valid()) {
						at->get_rect_region(dst_rect, src_rect, dst_rect, src_rect);
						has_margin = has_margin || (at->get_margin() != Rect2());
						at = at->get_atlas();
					}
					if (has_margin) {
						WARN_PRINT_ONCE(vformat("Tiling an AtlasTexture with non-zero margin is not supported (in: %s).", this));
					}
					RS::get_singleton()->canvas_item_add_nine_patch(get_canvas_item(), dst_rect, src_rect, texture->get_scaled_rid(), Vector2(), Vector2(), RS::NINE_PATCH_TILE, RS::NINE_PATCH_TILE, true);
				} else {
					draw_texture_rect(texture, Rect2(offset, size), tile);
				}
			}
		} break;
		case NOTIFICATION_RESIZED: {
			update_minimum_size();
		} break;
	}
}

Size2 TextureRect::get_minimum_size() const {
	if (texture.is_valid()) {
		switch (expand_mode) {
			case EXPAND_KEEP_SIZE: {
				return texture->get_size();
			} break;
			case EXPAND_IGNORE_SIZE: {
				return Size2();
			} break;
			case EXPAND_FIT_WIDTH: {
				return Size2(get_size().y, 0);
			} break;

Review comment (bug):
Actually, this is bad, it warns only once for the whole lifetime of the project/editor. Meaning after creating such wrong setup (`STRETCH_TILE` + `AtlasTexture` with non-zero `margin`) in the editor once, you won't be warned again if you'd again create similar wrong setup e.g. in different TextureRect (not until you'd restart the editor).

I could change it to `WARN_PRINT`, but then it could spam the warning for such wrong setup (seems to be doing so e.g. on dragging given TextureRect within the editor). But that's probably fine? 🤔 Such setup would not work correctly, hence should be fixed by the user (and doing so would get rid of the potential warning spam).

Alternative I guess would be to show this in the node configuration warning, but this would be only shown in the editor (so no warning for stuff created dynamically on runtime). +It would require connecting to `AtlasTexture.changed` signal for properly updating. Seems like unnecessary overhead for such a niche case to me. So I think `WARN_PRINT` is probably the way to go.

@KoBeWi What do you think?

Code after:

					region.position = ((scaled_tex_size - size) / scale).abs() / 2.0f;
					region.size = size / scale;
				} break;
			}

			size.width *= hflip ? -1.0f : 1.0f;
			size.height *= vflip ? -1.0f : 1.0f;

			if (region.has_area()) {
				draw_texture_rect_region(texture, Rect2(offset, size), region);
			} else {
				// `draw_texture_rect` doesn't support tiling an AtlasTexture.
				// Workaround using nine patch. Doesn't work properly for non-zero margin, nesting AtlasTextures is fine otherwise.
				if (tile && Object::cast_to<AtlasTexture>(*texture)) {
					Rect2 src_rect(Vector2(), texture->get_size());
					Rect2 dst_rect(offset, size);
					Ref<AtlasTexture> at = texture;
					bool anything_to_draw = true;
					while (anything_to_draw && at.is_valid()) {
						anything_to_draw = at->get_rect_region(dst_rect, src_rect, dst_rect, src_rect);
						at = at->get_atlas();
					}
					if (anything_to_draw) {
						RS::get_singleton()->canvas_item_add_nine_patch(get_canvas_item(), dst_rect, src_rect, texture->get_scaled_rid(), Vector2(), Vector2(), RS::NINE_PATCH_TILE, RS::NINE_PATCH_TILE, true);
					}
				} else {
					draw_texture_rect(texture, Rect2(offset, size), tile);
				}
			}
		} break;
		case NOTIFICATION_RESIZED: {
			update_minimum_size();
		} break;
	}
}

Size2 TextureRect::get_minimum_size() const {
	if (texture.is_valid()) {
		switch (expand_mode) {
			case EXPAND_KEEP_SIZE: {
				return texture->get_size();
			} break;
			case EXPAND_IGNORE_SIZE: {
				return Size2();
			} break;
			case EXPAND_FIT_WIDTH: {
				return Size2(get_size().y, 0);
			} break;
			case EXPAND_FIT_WIDTH_PROPORTIONAL: {
				real_t ratio = real_t(texture->get_width()) / texture->get_height();