Skip to content

Commit

Permalink
Fix percentages rendering incorrectly (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur committed Aug 20, 2024
1 parent 509bb78 commit b8697d2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/data_classes/Element.gd
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ func apply_to(element: Element, dropped_attributes: PackedStringArray) -> void:
if not attribute_name in dropped_attributes:
element.set_attribute(attribute_name, get_attribute_value(attribute_name))

# Converts all percentage numeric attributes to absolute.
func make_all_attributes_absolute() -> void:
for attribute_name in _attributes:
if _attributes[attribute_name] is AttributeNumeric:
make_attribute_absolute(attribute_name)

# Converts a percentage numeric attribute to absolute.
func make_attribute_absolute(attribute_name: String) -> void:
if is_attribute_percentage(attribute_name):
set_attribute(attribute_name, get_attribute_num(attribute_name))


# To be overridden in extending classes.
func get_own_default(_attribute_name: String) -> String:
Expand All @@ -304,6 +315,7 @@ func get_config_warnings() -> PackedStringArray:
func user_setup(_what = null) -> void:
return


# Helpers
func is_parent_g() -> bool:
return parent != null and parent is ElementG
Expand Down
13 changes: 6 additions & 7 deletions src/data_classes/NumberParser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ static func num_to_text(number: float, formatter: Formatter) -> String:
if number == -0.0:
number = absf(number)

if formatter.number_use_exponent_if_shorter and absf(number) >= 1000.0:
var ending_zeros := 0
while is_zero_approx(fmod(number, 10 ** (ending_zeros + 1))):
ending_zeros += 1
if ending_zeros >= 3:
return String.num_int64(int(number / 10 ** ending_zeros)) + "e" +\
String.num_uint64(ending_zeros)
if formatter.number_use_exponent_if_shorter and not is_zero_approx(number):
var e := 2
while is_zero_approx(fposmod(absf(number), 10 ** (e + 1))):
e += 1
if e >= 3:
return String.num_int64(int(number / 10 ** e)) + "e" + String.num_int64(e)

var output := String.num(number, Utils.MAX_NUMERIC_PRECISION)
if formatter.number_remove_leading_zero and not is_zero_approx(fmod(number, 1)):
Expand Down
8 changes: 6 additions & 2 deletions src/data_classes/SVGParser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ custom_height: float, custom_viewbox: Rect2) -> String:
text = text.strip_edges(false, true).left(-6) # Remove the </svg> at the end.)
for child_idx in root_element.get_child_count():
text += _element_to_text(root_element.get_element(PackedInt32Array([child_idx])),
blank_formatter)
blank_formatter, true)
return text + "</svg>"

static func root_to_text(root_element: ElementRoot,
Expand All @@ -24,7 +24,11 @@ formatter: Formatter = GlobalSettings.savedata.editor_formatter) -> String:
text += "\n"
return text

static func _element_to_text(element: Element, formatter: Formatter) -> String:
static func _element_to_text(element: Element, formatter: Formatter,
make_attributes_absolute := false) -> String:
if make_attributes_absolute:
element.make_all_attributes_absolute()

var text := ""
if formatter.xml_pretty_formatting:
if formatter.xml_indentation_use_spaces:
Expand Down
1 change: 0 additions & 1 deletion src/ui_widgets/BetterTextEdit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func _ready() -> void:
add_child(_timer)
_timer.timeout.connect(blink)
get_v_scroll_bar().value_changed.connect(queue_redraw_caret.unbind(1))
resized.connect(queue_redraw_caret.unbind(1), CONNECT_DEFERRED)
get_h_scroll_bar().value_changed.connect(queue_redraw_caret.unbind(1))
mouse_exited.connect(_on_base_class_mouse_exited)
focus_entered.connect(_on_base_class_focus_entered)
Expand Down

0 comments on commit b8697d2

Please sign in to comment.