<select>, <option>
This commit is contained in:
10
Scripts/Tags/option.gd
Normal file
10
Scripts/Tags/option.gd
Normal file
@@ -0,0 +1,10 @@
|
||||
extends Control
|
||||
|
||||
func init(element: HTMLParser.HTMLElement) -> void:
|
||||
# This is mainly for cases where <option> appears outside of <select>
|
||||
var label = RichTextLabel.new()
|
||||
label.bbcode_enabled = true
|
||||
label.fit_content = true
|
||||
label.scroll_active = false
|
||||
label.text = "[font_size=24]%s[/font_size]" % element.get_bbcode_formatted_text()
|
||||
add_child(label)
|
||||
1
Scripts/Tags/option.gd.uid
Normal file
1
Scripts/Tags/option.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c66r24cncb1dp
|
||||
39
Scripts/Tags/select.gd
Normal file
39
Scripts/Tags/select.gd
Normal file
@@ -0,0 +1,39 @@
|
||||
extends Control
|
||||
|
||||
const BROWSER_TEXT = preload("res://Scenes/Styles/BrowserText.tres")
|
||||
|
||||
func init(element: HTMLParser.HTMLElement) -> void:
|
||||
var option_button: OptionButton = $OptionButton
|
||||
|
||||
var selected_index = -1
|
||||
var option_index = 0
|
||||
|
||||
# find <option>s
|
||||
for child_element in element.children:
|
||||
if child_element.tag_name == "option":
|
||||
var option_text = child_element.text_content.strip_edges()
|
||||
var option_value = child_element.get_attribute("value")
|
||||
|
||||
option_value = option_text
|
||||
|
||||
option_button.add_item(option_text, option_index)
|
||||
option_button.set_item_metadata(option_index, option_value)
|
||||
|
||||
# Check if this option is selected
|
||||
var is_selected = child_element.get_attribute("selected")
|
||||
if is_selected.length() > 0 and selected_index == -1:
|
||||
selected_index = option_index
|
||||
|
||||
# Check if this option is disabled
|
||||
var is_disabled = child_element.get_attribute("disabled")
|
||||
if is_disabled.length() > 0:
|
||||
option_button.set_item_disabled(option_index, true)
|
||||
|
||||
option_index += 1
|
||||
|
||||
# Set the selected item
|
||||
if selected_index >= 0:
|
||||
option_button.selected = selected_index
|
||||
|
||||
add_child(option_button)
|
||||
custom_minimum_size = option_button.size
|
||||
1
Scripts/Tags/select.gd.uid
Normal file
1
Scripts/Tags/select.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bmu8q4rm1wopd
|
||||
@@ -23,6 +23,8 @@ const BUTTON = preload("res://Scenes/Tags/button.tscn")
|
||||
const UL = preload("res://Scenes/Tags/ul.tscn")
|
||||
const OL = preload("res://Scenes/Tags/ol.tscn")
|
||||
const LI = preload("res://Scenes/Tags/li.tscn")
|
||||
const SELECT = preload("res://Scenes/Tags/select.tscn")
|
||||
const OPTION = preload("res://Scenes/Tags/option.tscn")
|
||||
|
||||
const MIN_SIZE = Vector2i(750, 200)
|
||||
|
||||
@@ -75,6 +77,14 @@ both spaces and
|
||||
line breaks
|
||||
</pre>
|
||||
|
||||
<select>
|
||||
<option value=\"test1\">Test 1</option>
|
||||
<option value=\"test2\" selected=\"true\">Test 2</option>
|
||||
<option value=\"test3\">Test 3</option>
|
||||
<option value=\"test4\" disabled=\"true\">Test 4</option>
|
||||
<option value=\"test5\">Test 5</option>
|
||||
</select>
|
||||
|
||||
<!-- action, method, and type=submit are for when we implement Lua -->
|
||||
<form action=\"/submit\" method=\"POST\">
|
||||
<span>Name:</span>
|
||||
@@ -463,6 +473,12 @@ func create_element_node(element: HTMLParser.HTMLElement) -> Control:
|
||||
"li":
|
||||
node = LI.instantiate()
|
||||
node.init(element)
|
||||
"select":
|
||||
node = SELECT.instantiate()
|
||||
node.init(element)
|
||||
"option":
|
||||
node = OPTION.instantiate()
|
||||
node.init(element)
|
||||
_:
|
||||
return null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user