Commit cedfd4bc authored by adud's avatar adud

remove the "same width" condition

The Same Height condition is still here though, but who would want characters
of different heights in the same line?
parent 453d8a74
......@@ -6,6 +6,11 @@
.. warning::
For the sign symbols to work with the Workspace, every symbol must have the
same height
.. todo::
For the moment, SignSymb is only a dummy text display that is used to test
the :class:`WorkSpace`
......
......@@ -3,10 +3,11 @@ extends Control
func set_text(st):
$Text.set_text(st)
set_size($Text.get_minimum_size())
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
set_size($Text.get_minimum_size())
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
......
......@@ -3,19 +3,16 @@
[ext_resource path="res://SignSymb.gd" type="Script" id=1]
[node name="SignSymb" type="Control"]
anchor_bottom = 1.0
margin_right = 100.0
margin_bottom = 14.0
margin_bottom = -586.0
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
[node name="Text" type="Label" parent="."]
margin_right = 100.0
margin_right = 50.0
margin_bottom = 14.0
mouse_filter = 1
mouse_default_cursor_shape = 1
text = "Aristotélicien"
align = 1
clip_text = true
text = "Aristotélicien·ne·s"
valign = 1
......@@ -12,7 +12,7 @@ export (PackedScene) var SignSymb
# Properties
export var sep = Vector2(5, 5)
export var sep = Vector2(10, 5)
var text = []
......@@ -22,18 +22,18 @@ func dispose_childs():
if text == []:
return
# Assumption: all symbols have same size
var symb_size = text[0].get_size()
var space = symb_size + sep
# Assumption: all symbols have same height
var symb_height = text[0].rect_size.y
var yspace = symb_height + sep.y
var pos = Vector2(0, 0)
for symb in text:
if pos.x + symb_size.x > rect_size.x: # Line Wrapping
pos.y += space.y
if pos.x + symb.rect_size.x > rect_size.x: # Line Wrapping
pos.y += yspace
pos.x = 0
fit_child_in_rect(symb, Rect2(pos, symb_size))
pos.x += space.x
fit_child_in_rect(symb, Rect2(pos, symb.rect_size))
pos.x += symb.rect_size.x + sep.x
# return true iff the nearest gap from position pos is before the sign sig
......@@ -80,20 +80,15 @@ func test_disposition(n):
var est_pos
var real_pos
var dtext = ["Hello", "World", "Lorem", "Ipsum"]
for _i in range(n): # underscore is for preventing unused var warnings
symb = SignSymb.instance()
add_child(symb)
text.append(symb)
for i in range(len(dtext)):
text[i].set_text(dtext[i])
dispose_childs()
# test the naive position of elements (no linebreak)
# test the naive position of elements (no linebreak, all same width)
var symb_size = text[0].get_size()
var words_per_line = int((rect_size + sep).x / (symb_size + sep).x)
for i in range(len(text)):
line_number = i / words_per_line
......@@ -105,19 +100,29 @@ func test_disposition(n):
push_error("Workspace Test Failure, pos should be: %s, it is %s"
% [est_pos, real_pos])
# test nearest gap (random)
var bound = Rect2(- sep.x - symb_size.x/2, -sep.y/2,
sep.x + symb_size.x, sep.y + symb_size.y)
# test text changes
var dtext = ["Hello", "World", "Lorem", "Ipsum", "Sed", "Dolor", "Amet"]
for i in range(len(dtext)):
text[i].set_text(dtext[i])
dispose_childs()
# test nearest gap (random)
var twid = Vector2(0,0)
var twid = Vector2(0, 0)
var gap = 0
var pos = Vector2(0,0)
var pos = Vector2(0, 0)
randomize()
for i in range(len(text)):
twid = Vector2(rand_range(bound.position.x, bound.end.x),
rand_range(bound.position.y, bound.end.y))
pos = text[i].get_position() + twid
for i in range(1, len(text)):
twid = Vector2(rand_range(-text[i-1].rect_size.x/2 - sep.x,
text[i].rect_size.x/2),
rand_range(-sep.y/2, text[i].rect_size.y + sep.y/2))
pos = text[i].rect_position + twid
gap = get_nearest_gap(pos)
if gap != i:
push_error("Nearest Gap Error: should be %s, is %s, pos %s"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment