fix label sizing in containers, radius for div, swap manual bg draw to Panel
This commit is contained in:
@@ -4,18 +4,45 @@ extends FlexContainer
|
||||
|
||||
signal flex_resized
|
||||
|
||||
var bgcolor: Color = Color(0,0,0,0)
|
||||
var content_size: Vector2 = Vector2.ZERO
|
||||
var background_panel: Panel = null
|
||||
|
||||
func set_background_color(color: Color) -> void:
|
||||
bgcolor = color
|
||||
queue_redraw()
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
super._notification(what)
|
||||
|
||||
if what == NOTIFICATION_DRAW and bgcolor.a > 0:
|
||||
draw_rect(Rect2(Vector2.ZERO, content_size), bgcolor)
|
||||
func update_background_panel():
|
||||
var needs_background = has_meta("custom_css_background_color") or has_meta("custom_css_border_radius")
|
||||
|
||||
if needs_background:
|
||||
if not background_panel:
|
||||
background_panel = Panel.new()
|
||||
background_panel.name = "BackgroundPanel"
|
||||
background_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(background_panel)
|
||||
move_child(background_panel, 0) # Ensure it's behind content
|
||||
|
||||
# Set panel size to match container
|
||||
background_panel.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
|
||||
# Create StyleBoxFlat for background and border radius
|
||||
var style_box = StyleBoxFlat.new()
|
||||
|
||||
if has_meta("custom_css_background_color"):
|
||||
style_box.bg_color = get_meta("custom_css_background_color")
|
||||
else:
|
||||
style_box.bg_color = Color.TRANSPARENT
|
||||
|
||||
if has_meta("custom_css_border_radius"):
|
||||
var radius_str = get_meta("custom_css_border_radius")
|
||||
var radius = StyleManager.parse_radius(radius_str)
|
||||
style_box.corner_radius_top_left = radius
|
||||
style_box.corner_radius_top_right = radius
|
||||
style_box.corner_radius_bottom_left = radius
|
||||
style_box.corner_radius_bottom_right = radius
|
||||
|
||||
background_panel.add_theme_stylebox_override("panel", style_box)
|
||||
|
||||
elif background_panel:
|
||||
# Remove background panel if no longer needed
|
||||
background_panel.queue_free()
|
||||
background_panel = null
|
||||
|
||||
# This is the overridden layout logic for the auto-sizing container
|
||||
func _resort() -> void:
|
||||
@@ -40,6 +67,10 @@ func _resort() -> void:
|
||||
var c = get_child(i)
|
||||
if not c is Control or c.is_set_as_top_level():
|
||||
continue
|
||||
|
||||
# Skip background panel from flex calculations
|
||||
if c.name == "BackgroundPanel":
|
||||
continue
|
||||
|
||||
var cid = c.get_instance_id()
|
||||
var target_index = _find_index_from_flex_list(_flex_list, cid)
|
||||
@@ -151,10 +182,9 @@ func _resort() -> void:
|
||||
_draw_debug_rect(Rect2(offset, rect_size), Color(1, 0, 0, 0.8))
|
||||
|
||||
|
||||
if has_meta("custom_css_background_color"):
|
||||
set_background_color(get_meta("custom_css_background_color"))
|
||||
|
||||
queue_redraw()
|
||||
# Update background panel if needed
|
||||
update_background_panel()
|
||||
|
||||
emit_signal("flex_resized")
|
||||
|
||||
func calculate_available_dimension(is_width: bool) -> float:
|
||||
|
||||
Reference in New Issue
Block a user