1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

StyleBox preview adjusted to fit all drawn content

This change allows StyleBox preview to take shadows and content margins into account to display how a whole panel would be rendered.

The preview control clips contents so that in any case it doesn't bleed on controls around.

Fixes #33801
This commit is contained in:
PouleyKetchoupp
2019-11-24 16:26:30 +01:00
parent 636bc5c32f
commit 1120de862d
3 changed files with 33 additions and 1 deletions

View File

@@ -68,7 +68,14 @@ void StyleBoxPreview::_sb_changed() {
void StyleBoxPreview::_redraw() {
if (stylebox.is_valid()) {
preview->draw_style_box(stylebox, preview->get_rect());
Rect2 preview_rect = preview->get_rect();
// Re-adjust preview panel to fit all drawn content
Rect2 draw_rect = stylebox->get_draw_rect(preview_rect);
preview_rect.size -= draw_rect.size - preview_rect.size;
preview_rect.position -= draw_rect.position - preview_rect.position;
preview->draw_style_box(stylebox, preview_rect);
}
}
@@ -81,6 +88,7 @@ void StyleBoxPreview::_bind_methods() {
StyleBoxPreview::StyleBoxPreview() {
preview = memnew(Control);
preview->set_custom_minimum_size(Size2(0, 150 * EDSCALE));
preview->set_clip_contents(true);
preview->connect("draw", this, "_redraw");
add_margin_child(TTR("Preview:"), preview);
}