input (text/checkbox), form, button

This commit is contained in:
Face
2025-07-23 15:23:32 +03:00
parent 7a0b678fc2
commit a9ce6cb178
48 changed files with 1720 additions and 18 deletions

View File

@@ -80,9 +80,6 @@ class HTMLElement:
func is_inline_element() -> bool:
return tag_name in ["b", "i", "u", "small", "mark", "code", "span", "a"]
func is_heading_element() -> bool:
return tag_name in ["h1", "h2", "h3", "h4", "h5", "h6"]
class ParseResult:
var root: HTMLElement

View File

@@ -86,7 +86,7 @@ func create_tab() -> void:
# WARNING: temporary
main.render()
func _input(event: InputEvent) -> void:
func _input(_event: InputEvent) -> void:
if Input.is_action_just_pressed("NewTab"):
create_tab()
if Input.is_action_just_pressed("CloseTab"):

View File

@@ -1,4 +1,4 @@
extends Control
func init(element: HTMLParser.HTMLElement) -> void:
func init(_element: HTMLParser.HTMLElement) -> void:
pass

18
Scripts/Tags/button.gd Normal file
View File

@@ -0,0 +1,18 @@
extends Control
func init(element: HTMLParser.HTMLElement) -> void:
var button_node: Button = $ButtonNode
var button_text = element.text_content.strip_edges()
if button_text.length() == 0:
button_text = element.get_bbcode_formatted_text()
if button_text.length() > 0:
button_node.text = button_text
button_node.custom_minimum_size = button_node.get_theme_default_font().get_string_size(
button_node.text,
HORIZONTAL_ALIGNMENT_LEFT,
-1,
button_node.get_theme_default_font_size()
) + Vector2(20, 10) # Add padding

View File

@@ -0,0 +1 @@
uid://cks35eudcm1wj

4
Scripts/Tags/form.gd Normal file
View File

@@ -0,0 +1,4 @@
extends VBoxContainer
func init(_element: HTMLParser.HTMLElement) -> void:
pass

1
Scripts/Tags/form.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://cn2iolk6biupv

23
Scripts/Tags/input.gd Normal file
View File

@@ -0,0 +1,23 @@
extends Control
func init(element: HTMLParser.HTMLElement) -> void:
var line_edit: LineEdit = $LineEdit
var check_box: CheckBox = $CheckBox
var input_type = element.get_attribute("type").to_lower()
var placeholder = element.get_attribute("placeholder")
var value = element.get_attribute("value")
match input_type:
"checkbox":
line_edit.visible = false
check_box.visible = true
if value and value == "true": check_box.button_pressed = true
custom_minimum_size = check_box.size
_: # Default to text input
line_edit.visible = true
check_box.visible = false
custom_minimum_size = line_edit.size
if placeholder: line_edit.placeholder_text = placeholder
if value: line_edit.text = value

View File

@@ -0,0 +1 @@
uid://kv6ebscarj2e

View File

@@ -19,6 +19,16 @@ const H3 = preload("res://Scenes/Tags/h3.tscn")
const H4 = preload("res://Scenes/Tags/h4.tscn")
const H5 = preload("res://Scenes/Tags/h5.tscn")
const H6 = preload("res://Scenes/Tags/h6.tscn")
const FORM = preload("res://Scenes/Tags/form.tscn")
const INPUT = preload("res://Scenes/Tags/input.tscn")
const BUTTON = preload("res://Scenes/Tags/button.tscn")
const MIN_SIZE = Vector2i(750, 200)
func _ready():
ProjectSettings.set_setting("display/window/size/min_width", MIN_SIZE.x)
ProjectSettings.set_setting("display/window/size/min_height", MIN_SIZE.y)
DisplayServer.window_set_min_size(MIN_SIZE)
func render():
# Clear existing content
@@ -64,6 +74,17 @@ both spaces and
line breaks
</pre>
<form>
<span>Name:</span>
<input type=\"text\" placeholder=\"First name\" value=\"John\" />
<span>Surname:</span>
<input type=\"text\" placeholder=\"Last name\" value=\"Doe\" />
<span>Smart:</span>
<input type=\"checkbox\" />
<input type=\"checkbox\" value=\"true\" />
<button>Submit</button>
</form>
<separator direction=\"horizontal\" />
<img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQMNUPIKabszX0Js_c0kfa4cz_JQYKfGTuBUA&s\" />
<separator direction=\"vertical\" />
@@ -176,6 +197,24 @@ line breaks
var separator = SEPARATOR.instantiate()
separator.init(element)
website_container.add_child(separator)
"form":
var form = FORM.instantiate()
form.init(element)
website_container.add_child(form)
# Render form children
for child_element in element.children:
var child_node = create_element_node(child_element)
if child_node:
form.add_child(child_node)
"input":
var input = INPUT.instantiate()
input.init(element)
website_container.add_child(input)
"button":
var button = BUTTON.instantiate()
button.init(element)
website_container.add_child(button)
"span":
var span = SPAN.instantiate()
span.init(element)
@@ -213,3 +252,20 @@ func contains_hyperlink(element: HTMLParser.HTMLElement) -> bool:
return true
return false
func create_element_node(element: HTMLParser.HTMLElement) -> Control:
match element.tag_name:
"input":
var input = INPUT.instantiate()
input.init(element)
return input
"button":
var button = BUTTON.instantiate()
button.init(element)
return button
"span":
var span = SPAN.instantiate()
span.init(element)
return span
_:
return null