-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add StyleBoxMulti that draws other style boxes #79046
Conversation
The crash report failure is confusing. Any ideas? |
} | ||
|
||
void StyleBoxMulti::set_style_boxes(const TypedArray<StyleBox> &p_styleboxes) { | ||
style_boxes = p_styleboxes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setter probably should have a cyclic reference check to make sure one of the items is not this
or another StyleBoxMulti
with this
as a child style, or it can get stuck it the infinite draw
loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a check for that in debug mode https://github.com/aaronfranke/godot/blob/style-box-multi/scene/resources/style_box.cpp#L159-L185
GitHub isn't showing the change on the PR for some reason. I could push again to see if that works but I will need to push again anyway for the docs after the version bump to 4.2 so I'll just wait.
^ Smaller SVG |
de2af37
to
cae7ee4
Compare
From the technical POV, one thing that is not resolved here is sizing resolution. The way it behaves currently basically means that the StyleBoxMulti itself needs to have margins configured, and that the default minimum size resolution is used. Internal styleboxes do not contribute to it in any way and their possibly custom ways to resolve the minimum size are ignored. I'm not sure that would be the expected behavior. |
cae7ee4
to
5027fca
Compare
@aaronfranke did you ever finish a StyleBoxMulti addon? I'd love to use it. |
@rainlizard Here you go: @tool
@icon("style_box_multi.svg")
## Style box that can draw multiple style boxes.
## It can be used to combine multiple style boxes into one.
class_name StyleBoxMulti
extends StyleBox
@export var style_boxes: Array[StyleBox] = []
func _draw(canvas_item: RID, rect: Rect2) -> void:
for style_box in style_boxes:
style_box.draw(canvas_item, rect)
|
@aaronfranke it works but there's a big problem in the editor, when you adjust one of the array's stylebox's values it's not updating instantly in the editor. You have to switch scenes then switch back in order for it to update it. For example you set the border color to green, then nothing will change in the editor, so you switch to a blank scene then switch back and now the border color will be green. v4.3.dev3.official [36e943b] |
Here you go @tool
@icon("style_box_multi.svg")
## Style box that can draw multiple style boxes.
## It can be used to combine multiple style boxes into one.
class_name StyleBoxMulti
extends StyleBox
@export var style_boxes: Array[StyleBox] = []:
set(mod_value):
if style_boxes == mod_value:
return
for style_box in style_boxes:
if style_box == null or mod_value.has(style_box):
continue
if style_box.changed.is_connected(emit_changed):
style_box.changed.disconnect(emit_changed)
style_boxes = mod_value
for style_box in style_boxes:
if style_box == null:
continue
if not style_box.changed.is_connected(emit_changed):
style_box.changed.connect(emit_changed)
emit_changed()
func _draw(canvas_item: RID, rect: Rect2) -> void:
for style_box in style_boxes:
if style_box == null:
continue
style_box.draw(canvas_item, rect) |
Works perfectly, thanks theraot. This |
Implements and closes godotengine/godot-proposals#7203
EDIT: Actually, does not need to be in the engine, I made a mistake when concluding it can't be done in an add-on.