Доработка. WIP Добавлено место на шкале для иконки

This commit is contained in:
sasha80
2026-03-20 10:35:51 +03:00
parent 901d160c50
commit 731ce8b3dd
2 changed files with 37 additions and 17 deletions

View File

@@ -2,6 +2,8 @@
extends PanelContainer
## Предназначено для отображения диапазонов на горизонтальной шкале
@export_range(0.0, 1.0) var gap_top: float = 0.05 ## Зазор сверху
@export_range(0.0, 1.0) var gap_bottom: float = 0.05 ## Зазор снизу
@export var ranges_group_name: StringName = 'ranges' ## Имя группы для диапазонов
@@ -15,7 +17,7 @@ extends PanelContainer
func _enter_tree() -> void:
if ResourceLoader.exists(image_file):
$image.texture = load(image_file)
$grid/image.texture = load(image_file)
## Добавляет новый диапазон.
@@ -53,20 +55,21 @@ func del_range(nm: StringName) -> bool:
func _add_range_view(nm: StringName, x0: float, x1: float, col: Color):
var rng = Polygon2D.new()
var point0 = size * Vector2(x0, gap_bottom) ## лево низ
var point1 = size * Vector2(x0, 1.0 - gap_top) ## лево верх
var point2 = size * Vector2(x1, 1.0 - gap_top) ## право верх
var point3 = size * Vector2(x1, gap_bottom) ## право низ
var canvas_size = $grid/canvas.size
var point0 = canvas_size * Vector2(x0, gap_bottom) ## лево низ
var point1 = canvas_size * Vector2(x0, 1.0 - gap_top) ## лево верх
var point2 = canvas_size * Vector2(x1, 1.0 - gap_top) ## право верх
var point3 = canvas_size * Vector2(x1, gap_bottom) ## право низ
rng.polygon = [point0, point1, point2, point3]
rng.name = nm
rng.color = col
add_child(rng)
$grid/canvas.add_child(rng)
rng.add_to_group(ranges_group_name)
## Удаляет заданный диапазон.
func _del_range_view(nm: StringName) -> void:
var rng: = get_node(NodePath(nm))
var rng: = $grid/canvas.get_node(NodePath(nm))
remove_child(rng)
rng.queue_free()
@@ -74,13 +77,14 @@ func _del_range_view(nm: StringName) -> void:
func _clear_ranges_view():
var range_views = get_tree().get_nodes_in_group(ranges_group_name)
for rng in range_views:
remove_child(rng)
$grid/canvas.remove_child(rng)
rng.queue_free()
func _on_resized() -> void:
_clear_ranges_view()
for nm in ranges_save:
var rng = ranges_save[nm][0]
var col = ranges_save[nm][1]
var range_save = ranges_save[nm]
var rng = range_save[0]
var col = range_save[1]
_add_range_view(nm, rng.x, rng.y, col)

View File

@@ -1,20 +1,36 @@
[gd_scene load_steps=4 format=3 uid="uid://hr55mkcneaer"]
[gd_scene load_steps=5 format=3 uid="uid://hr55mkcneaer"]
[ext_resource type="Script" uid="uid://jtio1scc72bl" path="res://scenes/hranges/panel.gd" id="1_pg3d7"]
[ext_resource type="Texture2D" uid="uid://c73tjrn8gr00o" path="res://data/Передатчик.png" id="2_ajqhv"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ajqhv"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ajqhv"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_56wj8"]
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[node name="panel" type="PanelContainer"]
offset_right = 340.0
offset_bottom = 40.0
theme_override_styles/panel = SubResource("StyleBoxFlat_ajqhv")
offset_right = 400.0
offset_bottom = 45.0
theme_override_styles/panel = SubResource("StyleBoxEmpty_ajqhv")
script = ExtResource("1_pg3d7")
[node name="image" type="TextureRect" parent="."]
[node name="grid" type="GridContainer" parent="."]
layout_mode = 2
columns = 2
[node name="image" type="TextureRect" parent="grid"]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 3
texture = ExtResource("2_ajqhv")
expand_mode = 2
expand_mode = 3
[node name="canvas" type="PanelContainer" parent="grid"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_56wj8")
[connection signal="resized" from="." to="." method="_on_resized"]