Add an accent bar under dictation and correction fields (0.9.3)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Denis Defolie
2026-10-17 19:06:08 +02:00
parent 9d4251a345
commit 11e91fceb0
12 changed files with 206 additions and 1 deletions
+6
View File
@@ -11,6 +11,7 @@ extends Control
signal answer_submitted(submitted_text: String)
var _dictation: Dictionary = {}
var _accent_bar := AccentBar.new()
@onready var _instruction_label: Label = %InstructionLabel
@onready var _replay_button: Button = %ReplayButton
@@ -28,6 +29,11 @@ func _ready() -> void:
_convention_hint_label.text = UIText.get_text("dictation.convention_hint")
_validate_button.text = UIText.get_text("exercise_host.validate_button")
# Barre d'accents sous le champ : utile si le clavier n'a pas les accents.
_text_edit.get_parent().add_child(_accent_bar)
_text_edit.get_parent().move_child(_accent_bar, _text_edit.get_index() + 1)
_accent_bar.set_target(_text_edit)
_replay_button.pressed.connect(_on_replay_pressed)
_validate_button.pressed.connect(_on_validate_pressed)
# La touche Entree valide comme le bouton.
+12
View File
@@ -7,6 +7,7 @@ extends Control
signal answer_submitted(selected_indices: Array, corrections: Dictionary)
var _correction_edits: Dictionary = {}
var _accent_bar := AccentBar.new()
@onready var _instruction_label: Label = %InstructionLabel
@onready var _tokens_box: HFlowContainer = %TokensBox
@@ -17,6 +18,10 @@ var _correction_edits: Dictionary = {}
func _ready() -> void:
_validate_button.text = UIText.get_text("exercise_host.validate_button")
_validate_button.pressed.connect(_on_validate_pressed)
# Barre d'accents sous les champs de correction (masquee sans champ).
_corrections_box.get_parent().add_child(_accent_bar)
_corrections_box.get_parent().move_child(_accent_bar, _corrections_box.get_index() + 1)
_accent_bar.set_target(null)
func load_exercise(exercise: Dictionary) -> void:
@@ -27,6 +32,7 @@ func load_exercise(exercise: Dictionary) -> void:
for child in _corrections_box.get_children():
child.queue_free()
_correction_edits.clear()
_accent_bar.set_target(null)
var tokens: Array = exercise["tokens"]
for i in tokens.size():
@@ -47,12 +53,18 @@ func _on_token_toggled(pressed: bool, index: int) -> void:
edit.placeholder_text = UIText.get_text("sentence_correction.correction_placeholder")
# La touche Entree valide comme le bouton.
edit.text_submitted.connect(func(_text: String) -> void: _on_validate_pressed())
edit.focus_entered.connect(_accent_bar.set_target.bind(edit))
_corrections_box.add_child(edit)
_accent_bar.set_target(edit)
_correction_edits[index] = edit
elif _correction_edits.has(index):
var edit: LineEdit = _correction_edits[index]
edit.queue_free()
_correction_edits.erase(index)
if _correction_edits.is_empty():
_accent_bar.set_target(null)
else:
_accent_bar.set_target(_correction_edits.values().back() as LineEdit)
func _on_validate_pressed() -> void:
+67
View File
@@ -0,0 +1,67 @@
class_name AccentBar
extends HFlowContainer
## Rangee de boutons d'accents sous un champ de saisie. Les boutons ne prennent
## jamais le focus : le champ garde le clavier (et le clavier tactile reste
## ouvert). Une touche « Maj » bascule entre minuscules et majuscules (la
## dictee exige la majuscule initiale).
var _target: LineEdit = null
var _uppercase := false
var _shift_button: Button
func _ready() -> void:
add_theme_constant_override("h_separation", 6)
add_theme_constant_override("v_separation", 6)
_shift_button = Button.new()
_shift_button.text = "⇧"
_shift_button.tooltip_text = UIText.get_text("accent_bar.shift_tooltip")
_shift_button.toggle_mode = true
_shift_button.focus_mode = Control.FOCUS_NONE
_shift_button.theme_type_variation = &"SecondaryButton"
_shift_button.toggled.connect(_on_shift_toggled)
_style(_shift_button)
add_child(_shift_button)
_rebuild()
visible = _target != null
## Cible un champ de saisie ; null masque la barre.
func set_target(edit: LineEdit) -> void:
_target = edit
visible = edit != null
func _on_shift_toggled(pressed: bool) -> void:
_uppercase = pressed
_rebuild()
func _rebuild() -> void:
for child in get_children():
if child != _shift_button:
child.queue_free()
for character in AccentInserter.characters(_uppercase):
var button := Button.new()
button.text = character
button.focus_mode = Control.FOCUS_NONE
button.theme_type_variation = &"SecondaryButton"
button.pressed.connect(_on_accent_pressed.bind(character))
_style(button)
add_child(button)
func _on_accent_pressed(character: String) -> void:
if _target == null or not is_instance_valid(_target):
return
var result := AccentInserter.insert(_target.text, _target.caret_column, character)
_target.text = result["text"]
_target.caret_column = result["caret"]
# Une majuscule sert une fois : on revient aux minuscules.
if _uppercase:
_shift_button.button_pressed = false
func _style(button: Button) -> void:
button.custom_minimum_size = Vector2(52, 52)
button.add_theme_font_size_override("font_size", SettingsManager.scaled_font_size(26))
+1
View File
@@ -0,0 +1 @@
uid://eoyxrxlmqxqg