...
This commit is contained in:
parent
819bcfac15
commit
820737bc69
11 changed files with 42 additions and 53774 deletions
|
|
@ -0,0 +1,41 @@
|
|||
To make an `HBoxContainer` dynamically resize with its image contents in Godot 4.3, follow these steps:
|
||||
|
||||
## Core Setup
|
||||
- **Parent with `ScrollContainer`**: Place your `HBoxContainer` inside a `ScrollContainer` to enable scrolling when content exceeds visible area. Set the scroll direction (horizontal/vertical) in the `ScrollContainer` properties[5].
|
||||
|
||||
- **Container Settings**:
|
||||
- Enable `Expand` and set **Stretch Mode** to `Keep Aspect` on all child `TextureRect` nodes[2].
|
||||
- Apply **Size Flags** (`Fill` and `Expand`) to each `TextureRect` to ensure proportional scaling[2][3].
|
||||
|
||||
## Dynamic Resizing
|
||||
For automatic width adjustment when adding/removing images:
|
||||
```gdscript
|
||||
# After adding/removing children:
|
||||
$HBoxContainer.queue_sort() # Forces layout update
|
||||
$ScrollContainer.update_scroll() # Refreshes scroll boundaries
|
||||
```
|
||||
|
||||
If automatic resizing fails (common with dynamic content), manually calculate and set the container width:
|
||||
```gdscript
|
||||
var total_width = 0
|
||||
for child in $HBoxContainer.get_children():
|
||||
total_width += child.size.x
|
||||
total_width += $HBoxContainer.get_constant("separation") * ($HBoxContainer.get_child_count() - 1)
|
||||
$HBoxContainer.custom_minimum_size.x = total_width
|
||||
```
|
||||
|
||||
## Alternative Approach
|
||||
For wrapping behavior, replace `HBoxContainer` with an `HFlowContainer` (ensuring it's inside a fixed-size Control node). This automatically wraps overflowing items to new rows while scaling contents[2][4].
|
||||
|
||||
Citations:
|
||||
[1] https://stackoverflow.com/questions/30974986/dynamically-resize-side-by-side-images-with-different-dimensions-to-the-same-hei
|
||||
[2] https://www.reddit.com/r/godot/comments/13lbizw/how_to_resize_contents_of_hbox_container/
|
||||
[3] https://forum.godotengine.org/t/image-scaling-inside-a-hboxcontainer/20753
|
||||
[4] https://www.youtube.com/watch?v=GMKZU66uZac
|
||||
[5] https://godotforums.org/d/29145-why-isn-t-the-size-of-a-hbox-container-being-updated-automatically-i-have-to-do-it-manually
|
||||
[6] https://stackoverflow.com/questions/11093414/css-row-of-images-dynamically-resized-to-fill-container
|
||||
[7] https://www.sitepoint.com/community/t/dynamically-resize-and-reshape-containers-and-images/421461
|
||||
[8] https://docs.godotengine.org/en/stable/classes/class_hboxcontainer.html
|
||||
|
||||
---
|
||||
Antwort von Perplexity: https://www.perplexity.ai/search/godot-4-3-ui-scrollable-image-XrHVby6bQ.C3e3jEh_kLow?utm_source=copy_output
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
```python
|
||||
extends Control
|
||||
|
||||
@onready var http_request: HTTPRequest = $btn_login/HTTPRequest
|
||||
@onready var te_result: TextEdit = $te_result
|
||||
|
||||
var url = "http://godotweb.local/api/login"
|
||||
|
||||
func _on_btn_login_button_up() -> void:
|
||||
var headers = ["Content-Type: application/json"]
|
||||
var data_to_send = {
|
||||
"email" : $le_user.text,
|
||||
"password" : $le_password.text
|
||||
}
|
||||
var json:String = JSON.stringify(data_to_send)
|
||||
|
||||
http_request.request(url, headers, HTTPClient.Method.METHOD_POST, json)
|
||||
|
||||
func _on_http_request_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
|
||||
if response_code != 201:
|
||||
print("Login error.")
|
||||
return
|
||||
|
||||
var data = JSON.parse_string(body.get_string_from_utf8())
|
||||
print(data)
|
||||
|
||||
if data.status == false:
|
||||
te_result.text = "Login refused"
|
||||
else:
|
||||
var token:String = data.data.token
|
||||
te_result.text = "token: " + token
|
||||
|
||||
```
|
||||
|
|
@ -0,0 +1 @@
|
|||
https://www.youtube.com/watch?v=KOI0y1OC_tM&list=WL&index=1
|
||||
Loading…
Add table
Add a link
Reference in a new issue