This commit is contained in:
phidias authored and GitHub committed 2026-11-27 00:35:12 +09:00
1 parent 216d508921
commit c62e76316c
1 file changed
+18 -3
+18 -3
View File
@@ -99,6 +99,13 @@ Elements.calculator_result_label = Gui.define("calculator/result_label")
style = "heading_2_label", style = "heading_2_label",
} }
--- Output textfield
Elements.calculator_output_textfield = Gui.define("calculator/output_textfield")
:draw{
type = "textfield",
enabled = false
}
--- Container added to the screen --- Container added to the screen
Elements.container = Gui.define("calculator/container") Elements.container = Gui.define("calculator/container")
:draw(function(def, parent) :draw(function(def, parent)
@@ -115,6 +122,7 @@ Elements.container = Gui.define("calculator/container")
Elements.calculator_input_textfield(left_table) Elements.calculator_input_textfield(left_table)
Elements.calculator_caption_label(left_table, {"exp-gui_calculator.result"}) Elements.calculator_caption_label(left_table, {"exp-gui_calculator.result"})
Elements.calculator_result_label(left_table) Elements.calculator_result_label(left_table)
Elements.calculator_output_textfield(left_table)
Elements.calculator_caption_label(right_table, {"exp-gui_calculator.reference"}) Elements.calculator_caption_label(right_table, {"exp-gui_calculator.reference"})
Elements.calculator_info_label(right_table) Elements.calculator_info_label(right_table)
return Gui.elements.screen_frame.get_root_element(screen_frame) return Gui.elements.screen_frame.get_root_element(screen_frame)
@@ -345,17 +353,24 @@ end
--- Value change --- Value change
function Elements.change(event) function Elements.change(event)
local label = event.element.parent.calculator_result_label local label = event.element.parent.calculator_result_label
local textfield = event.element.parent.calculator_output_textfield
if event.text == "" then if event.text == "" then
label.caption = "" label.caption = ""
textfield.text = ""
return return
end end
local ok, result = Elements.parse(event.text:lower()) local ok, result = Elements.parse(event.text:lower())
label.style.font_color = ok and {1, 1, 1} or {1, 0, 0} label.style.font_color = ok and {1, 1, 1} or {1, 0, 0}
label.caption = ok
and ("= " .. format_number(result, false)) if ok then
or (type(result) == "table" and result or {"", {"exp-gui_calculator.error"}, tostring(result)}) label.caption = "= " .. format_number(result, false)
textfield.text = result
else
label.caption = type(result) == "table" and result or {"", {"exp-gui_calculator.error"}, tostring(result)}
textfield.text = ""
end
end end
local e = defines.events local e = defines.events