Skip to content
This repository was archived by the owner on May 25, 2024. It is now read-only.

Commit 238383a

Browse files
committed
feat(Table): broken expanding of columns
1 parent 0451f03 commit 238383a

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

Table/Scripts/Table.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,19 @@ private int SeparatorHeight
4646
private int separatorHeight;
4747

4848
private Godot.Collections.Array<Container> _columns;
49+
private Godot.Collections.Array<HSplitContainer> _columnSplitters;
4950

5051
private Control _content;
5152

53+
private static readonly StringName getTextMethod = "get_text";
54+
private static readonly int splitOffset = 10;
55+
5256
// Called when the node enters the scene tree for the first time.
5357
public override void _Ready()
5458
{
5559
_content = GetChild<Control>(0);
5660
_columns = new();
61+
_columnSplitters = new();
5762

5863
GetViewport().GuiFocusChanged += OnGuiFocusChanged;
5964

@@ -85,7 +90,11 @@ public override void _Ready()
8590
node1.AddChild(_column);
8691
node1 = _column;
8792

88-
_columns.Add(_column.GetChild<Container>(0));
93+
var columnSplit = _column as HSplitContainer;
94+
var columnContent = _column.GetChild<Container>(0);
95+
_columns.Add(columnContent);
96+
_columnSplitters.Add(columnSplit);
97+
columnContent.ChildEnteredTree += (x) => OnItemAdded(columnContent, columnSplit, x);
8998
}
9099
node.AddChild(new Control());
91100
node1.AddChild(new Control());
@@ -101,6 +110,34 @@ public override void _Ready()
101110
}
102111
}
103112

113+
private void OnItemAdded(Container column, HSplitContainer splitter, Node element)
114+
{
115+
// Leads to MemoryAccessViolation
116+
117+
//if (element is not Control ctrl)
118+
// return;
119+
//if (!element.HasMethod(getTextMethod))
120+
// return;
121+
122+
//var text = element.Call(getTextMethod).AsString();
123+
//if (string.IsNullOrEmpty(text))
124+
// return;
125+
126+
//var font = ctrl.HasThemeFont("normal_font") ? ctrl.GetThemeFont("normal_font") : null;
127+
//font ??= ctrl.HasThemeFont("font") ? ctrl.GetThemeFont("font") : ctrl.GetThemeDefaultFont();
128+
//var fontSize = ctrl.HasThemeFontSize("font_size") ? ctrl.GetThemeFontSize("font_size") : ctrl.GetThemeDefaultFontSize();
129+
130+
//var textWidth = font.GetStringSize(text, fontSize: fontSize).x;
131+
//var newOffset = (int)(textWidth + splitOffset /*- column.GetCombinedMinimumSize().x*/);
132+
//if (newOffset < 0)
133+
// return;
134+
135+
//var currentOffset = splitter.SplitOffset;
136+
137+
//if (newOffset > currentOffset)
138+
// splitter.Call("set_synced_offset", newOffset);
139+
}
140+
104141
private void OnGuiFocusChanged(Control node)
105142
{
106143
var focussedRows = GetFocussedRows();

Themes/Ubuntu-R.ttf

346 KB
Binary file not shown.

Themes/Ubuntu-R.ttf.import

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[remap]
2+
3+
importer="font_data_dynamic"
4+
type="FontFile"
5+
uid="uid://crmfa8o57255y"
6+
path="res://.godot/imported/Ubuntu-R.ttf-b1514721c8de2317ccb858a0a7152404.fontdata"
7+
8+
[deps]
9+
10+
source_file="res://Themes/Ubuntu-R.ttf"
11+
dest_files=["res://.godot/imported/Ubuntu-R.ttf-b1514721c8de2317ccb858a0a7152404.fontdata"]
12+
13+
[params]
14+
15+
Rendering=null
16+
antialiasing=1
17+
generate_mipmaps=false
18+
multichannel_signed_distance_field=false
19+
msdf_pixel_range=8
20+
msdf_size=48
21+
allow_system_fallback=true
22+
force_autohinter=false
23+
hinting=1
24+
subpixel_positioning=1
25+
oversampling=0.0
26+
Fallbacks=null
27+
fallbacks=[]
28+
Compress=null
29+
compress=true
30+
preload=[]
31+
language_support={}
32+
script_support={}
33+
opentype_features={}

Themes/base.tres

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
[gd_resource type="Theme" load_steps=3 format=3 uid="uid://by3gpw466gxq"]
1+
[gd_resource type="Theme" load_steps=4 format=3 uid="uid://by3gpw466gxq"]
2+
3+
[ext_resource type="FontFile" uid="uid://crmfa8o57255y" path="res://Themes/Ubuntu-R.ttf" id="1_e3ugm"]
24

35
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hcbh1"]
46
content_margin_left = 4.0
@@ -36,6 +38,8 @@ corner_radius_bottom_left = 3
3638
corner_detail = 5
3739

3840
[resource]
41+
default_font = ExtResource("1_e3ugm")
42+
default_font_size = 16
3943
LabelWithBorder/base_type = &"Label"
4044
LabelWithBorder/styles/normal = SubResource("StyleBoxFlat_hcbh1")
4145
RedTextLabel/base_type = &"Label"

0 commit comments

Comments
 (0)