fix w-full h-full and span sizing inheritance
This commit is contained in:
@@ -4,12 +4,15 @@
|
|||||||
[ext_resource type="Theme" uid="uid://bn6rbmdy60lhr" path="res://Scenes/Styles/BrowserText.tres" id="2_theme"]
|
[ext_resource type="Theme" uid="uid://bn6rbmdy60lhr" path="res://Scenes/Styles/BrowserText.tres" id="2_theme"]
|
||||||
|
|
||||||
[node name="Button" type="Control"]
|
[node name="Button" type="Control"]
|
||||||
custom_minimum_size = Vector2(100, 30)
|
custom_minimum_size = Vector2(64, 30)
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 0
|
anchors_preset = 0
|
||||||
|
offset_right = 64.0
|
||||||
|
offset_bottom = 30.0
|
||||||
script = ExtResource("1_button")
|
script = ExtResource("1_button")
|
||||||
|
|
||||||
[node name="ButtonNode" type="Button" parent="."]
|
[node name="ButtonNode" type="Button" parent="."]
|
||||||
|
custom_minimum_size = Vector2(64, 0)
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ min_value = -99999.0
|
|||||||
max_value = 99999.0
|
max_value = 99999.0
|
||||||
|
|
||||||
[node name="FileContainer" type="HBoxContainer" parent="."]
|
[node name="FileContainer" type="HBoxContainer" parent="."]
|
||||||
visible = false
|
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
offset_right = 300.0
|
offset_right = 300.0
|
||||||
offset_bottom = 35.0
|
offset_bottom = 35.0
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ extends FlexContainer
|
|||||||
signal flex_resized
|
signal flex_resized
|
||||||
|
|
||||||
var bgcolor: Color = Color(0,0,0,0)
|
var bgcolor: Color = Color(0,0,0,0)
|
||||||
|
var content_size: Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
func set_background_color(color: Color) -> void:
|
func set_background_color(color: Color) -> void:
|
||||||
bgcolor = color
|
bgcolor = color
|
||||||
@@ -14,11 +15,21 @@ func _notification(what: int) -> void:
|
|||||||
super._notification(what)
|
super._notification(what)
|
||||||
|
|
||||||
if what == NOTIFICATION_DRAW and bgcolor.a > 0:
|
if what == NOTIFICATION_DRAW and bgcolor.a > 0:
|
||||||
draw_rect(Rect2(Vector2.ZERO, size), bgcolor)
|
draw_rect(Rect2(Vector2.ZERO, content_size), bgcolor)
|
||||||
|
|
||||||
# This is the overridden layout logic for the auto-sizing container
|
# This is the overridden layout logic for the auto-sizing container
|
||||||
func _resort() -> void:
|
func _resort() -> void:
|
||||||
#size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
# Check if we should fill horizontally (for w-full)
|
||||||
|
if has_meta("should_fill_horizontal"):
|
||||||
|
size_flags_horizontal = Control.SIZE_FILL
|
||||||
|
else:
|
||||||
|
size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||||
|
|
||||||
|
# Check if we should fill vertically (for h-full)
|
||||||
|
if has_meta("should_fill_vertical"):
|
||||||
|
size_flags_vertical = Control.SIZE_FILL
|
||||||
|
else:
|
||||||
|
size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||||
|
|
||||||
if debug_draw:
|
if debug_draw:
|
||||||
_draw_rects.clear()
|
_draw_rects.clear()
|
||||||
@@ -74,11 +85,38 @@ func _resort() -> void:
|
|||||||
_root.mark_dirty_and_propogate()
|
_root.mark_dirty_and_propogate()
|
||||||
|
|
||||||
|
|
||||||
var auto_size_width = not has_meta("custom_css_width")
|
var auto_size_width = not has_meta("custom_css_width") and not has_meta("should_fill_horizontal")
|
||||||
var auto_size_height = not has_meta("custom_css_height")
|
var auto_size_height = not has_meta("custom_css_height") and not has_meta("should_fill_vertical")
|
||||||
|
|
||||||
var available_width = NAN if auto_size_width else size.x
|
var available_width = NAN
|
||||||
var available_height = NAN if auto_size_height else size.y
|
var available_height = NAN
|
||||||
|
|
||||||
|
if not auto_size_width:
|
||||||
|
if has_meta("should_fill_horizontal"):
|
||||||
|
# For w-full, use the full parent size if available
|
||||||
|
var parent_container = get_parent()
|
||||||
|
if parent_container and parent_container.size.x > 0:
|
||||||
|
available_width = parent_container.size.x
|
||||||
|
elif size.x > 0:
|
||||||
|
available_width = size.x
|
||||||
|
else:
|
||||||
|
# Fallback: try to get from custom_minimum_size
|
||||||
|
available_width = custom_minimum_size.x if custom_minimum_size.x > 0 else NAN
|
||||||
|
else:
|
||||||
|
available_width = size.x
|
||||||
|
|
||||||
|
if not auto_size_height:
|
||||||
|
if has_meta("should_fill_vertical"):
|
||||||
|
# For h-full, use the full parent size if available
|
||||||
|
var parent_container = get_parent()
|
||||||
|
if parent_container and parent_container.size.y > 0:
|
||||||
|
available_height = parent_container.size.y
|
||||||
|
elif size.y > 0:
|
||||||
|
available_height = size.y
|
||||||
|
else:
|
||||||
|
available_height = custom_minimum_size.y if custom_minimum_size.y > 0 else NAN
|
||||||
|
else:
|
||||||
|
available_height = size.y
|
||||||
|
|
||||||
_root.calculate_layout(available_width, available_height, 1) # 1 = LTR direction
|
_root.calculate_layout(available_width, available_height, 1) # 1 = LTR direction
|
||||||
|
|
||||||
@@ -92,25 +130,58 @@ func _resort() -> void:
|
|||||||
var custom_w = 0.0
|
var custom_w = 0.0
|
||||||
if has_meta("custom_css_width"):
|
if has_meta("custom_css_width"):
|
||||||
custom_w = float(get_meta("custom_css_width"))
|
custom_w = float(get_meta("custom_css_width"))
|
||||||
|
elif has_meta("should_fill_horizontal"):
|
||||||
|
# Use the same logic as available_width calculation
|
||||||
|
var parent_container = get_parent()
|
||||||
|
if parent_container and parent_container.size.x > 0:
|
||||||
|
custom_w = parent_container.size.x
|
||||||
|
elif size.x > 0:
|
||||||
|
custom_w = size.x
|
||||||
|
else:
|
||||||
|
custom_w = custom_minimum_size.x if custom_minimum_size.x > 0 else 0.0
|
||||||
|
|
||||||
var custom_h = 0.0
|
var custom_h = 0.0
|
||||||
if has_meta("custom_css_height"):
|
if has_meta("custom_css_height"):
|
||||||
custom_h = float(get_meta("custom_css_height"))
|
custom_h = float(get_meta("custom_css_height"))
|
||||||
|
elif has_meta("should_fill_vertical"):
|
||||||
|
# Use the same logic as available_height calculation
|
||||||
|
var parent_container = get_parent()
|
||||||
|
if parent_container and parent_container.size.y > 0:
|
||||||
|
custom_h = parent_container.size.y
|
||||||
|
elif size.y > 0:
|
||||||
|
custom_h = size.y
|
||||||
|
else:
|
||||||
|
custom_h = custom_minimum_size.y if custom_minimum_size.y > 0 else 0.0
|
||||||
|
|
||||||
var needed_size = Vector2(
|
var needed_size = Vector2(
|
||||||
max(custom_w, computed_size.x),
|
max(custom_w, computed_size.x),
|
||||||
max(custom_h, computed_size.y)
|
max(custom_h, computed_size.y)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Store the actual content size for background drawing
|
||||||
|
content_size = needed_size
|
||||||
|
|
||||||
# Construct the new minimum size for this container
|
# Construct the new minimum size for this container
|
||||||
var new_min_size = custom_minimum_size
|
var new_min_size = custom_minimum_size
|
||||||
if auto_size_width:
|
if auto_size_width:
|
||||||
new_min_size.x = needed_size.x
|
new_min_size.x = needed_size.x
|
||||||
|
else:
|
||||||
|
# For w-full, ensure minimum size matches the needed size
|
||||||
|
new_min_size.x = needed_size.x
|
||||||
if auto_size_height:
|
if auto_size_height:
|
||||||
new_min_size.y = needed_size.y
|
new_min_size.y = needed_size.y
|
||||||
|
else:
|
||||||
|
# For h-full, ensure minimum size matches the needed size
|
||||||
|
new_min_size.y = needed_size.y
|
||||||
|
|
||||||
if not custom_minimum_size.is_equal_approx(new_min_size):
|
if not custom_minimum_size.is_equal_approx(new_min_size):
|
||||||
custom_minimum_size = new_min_size
|
custom_minimum_size = new_min_size
|
||||||
|
|
||||||
|
# For w-full/h-full, also force the actual size if SIZE_FILL isn't working
|
||||||
|
if has_meta("should_fill_horizontal") and size.x < new_min_size.x:
|
||||||
|
size.x = new_min_size.x
|
||||||
|
if has_meta("should_fill_vertical") and size.y < new_min_size.y:
|
||||||
|
size.y = new_min_size.y
|
||||||
|
|
||||||
# Apply the calculated layout to each child control
|
# Apply the calculated layout to each child control
|
||||||
for flex_data in _flex_list:
|
for flex_data in _flex_list:
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ var HTML_CONTENT = """<head>
|
|||||||
<p>Keep track of your to-do list</p>
|
<p>Keep track of your to-do list</p>
|
||||||
|
|
||||||
<!-- Task List -->
|
<!-- Task List -->
|
||||||
<div style="flex flex-col gap-2 w-64 bg-[#f8fafc] items-center justify-center">
|
<div style="flex flex-col gap-2 w-80 bg-[#f8fafc] items-center justify-center">
|
||||||
<span style="flex justify-between items-center bg-[#e2e8f0] w-full h-8">
|
<span style="flex justify-between items-center bg-[#e2e8f0] w-full h-8">
|
||||||
<span>✅ Finish homework</span>
|
<span>✅ Finish homework</span>
|
||||||
<button>Delete</button>
|
<button>Delete</button>
|
||||||
|
|||||||
@@ -172,9 +172,19 @@ static func apply_flex_container_properties(node: FlexContainer, styles: Diction
|
|||||||
node._root.set_gap(0, parse_flex_value(styles["column-gap"]))
|
node._root.set_gap(0, parse_flex_value(styles["column-gap"]))
|
||||||
|
|
||||||
if styles.has("width"):
|
if styles.has("width"):
|
||||||
node.set_meta("custom_css_width", parse_size(styles["width"]))
|
var width_val = styles["width"]
|
||||||
|
if width_val == "full":
|
||||||
|
# For flex containers, w-full should expand to fill parent
|
||||||
|
node.set_meta("should_fill_horizontal", true)
|
||||||
|
else:
|
||||||
|
node.set_meta("custom_css_width", parse_size(width_val))
|
||||||
if styles.has("height"):
|
if styles.has("height"):
|
||||||
node.set_meta("custom_css_height", parse_size(styles["height"]))
|
var height_val = styles["height"]
|
||||||
|
if height_val == "full":
|
||||||
|
# For flex containers, h-full should expand to fill parent
|
||||||
|
node.set_meta("should_fill_vertical", true)
|
||||||
|
else:
|
||||||
|
node.set_meta("custom_css_height", parse_size(height_val))
|
||||||
if styles.has("background-color"):
|
if styles.has("background-color"):
|
||||||
node.set_meta("custom_css_background_color", styles["background-color"])
|
node.set_meta("custom_css_background_color", styles["background-color"])
|
||||||
node.update_layout()
|
node.update_layout()
|
||||||
|
|||||||
Reference in New Issue
Block a user