Skip to content

Commit

Permalink
Nicer editor scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrw committed Sep 29, 2024
1 parent b9fed26 commit 904ccee
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 167 deletions.
8 changes: 8 additions & 0 deletions app/components/Editor.gdns
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="NativeScript" load_steps=2 format=2]

[ext_resource path="res://nimlib.gdnlib" type="GDNativeLibrary" id=1]

[resource]
resource_name = "Editor"
class_name = "Editor"
library = ExtResource( 1 )
58 changes: 35 additions & 23 deletions app/components/Editor.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://components/TextEdit.gdns" type="Script" id=1]
[ext_resource path="res://components/Editor.gdns" type="Script" id=1]
[ext_resource path="res://themes/DarkTheme.tres" type="Theme" id=2]
[ext_resource path="res://components/FloatingButton.gdns" type="Script" id=3]

Expand All @@ -9,9 +9,24 @@ bg_color = Color( 0, 0, 0, 0.839216 )
border_width_right = 2
border_color = Color( 0.964706, 0.952941, 0.909804, 1 )

[node name="Editor" type="TextEdit"]
margin_right = 961.0
margin_bottom = 1080.0
[node name="MarginContainer" type="MarginContainer"]
margin_right = 40.0
margin_bottom = 40.0
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource( 1 )

[node name="ScrollContainer" type="ScrollContainer" parent="."]
margin_right = 74.0
margin_bottom = 95.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="TextEdit" type="TextEdit" parent="ScrollContainer"]
margin_right = 74.0
margin_bottom = 95.0
mouse_filter = 1
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource( 2 )
custom_colors/selection_color = Color( 0.207843, 0, 0.321569, 1 )
Expand All @@ -29,50 +44,47 @@ smooth_scrolling = true
wrap_enabled = true
caret_blink = true
caret_moving_by_right_click = false
script = ExtResource( 1 )

[node name="GridContainer" type="GridContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = 14.0
margin_bottom = 55.0
mouse_filter = 0
margin_right = 74.0
margin_bottom = 95.0
mouse_filter = 2
columns = 2

[node name="Label" type="Label" parent="GridContainer"]
margin_right = 881.0
margin_bottom = 111.0
margin_bottom = 95.0
size_flags_horizontal = 3
size_flags_vertical = 1

[node name="MarginContainer" type="MarginContainer" parent="GridContainer"]
margin_left = 885.0
margin_right = 975.0
margin_bottom = 111.0
margin_left = 4.0
margin_right = 74.0
margin_bottom = 95.0
mouse_filter = 2
custom_constants/margin_right = 50
custom_constants/margin_top = 25

[node name="GridContainer" type="GridContainer" parent="GridContainer/MarginContainer"]
margin_top = 25.0
margin_right = 40.0
margin_bottom = 111.0
margin_right = 20.0
margin_bottom = 95.0
rect_pivot_offset = Vector2( -911, -78 )
mouse_filter = 0
mouse_filter = 2
custom_constants/vseparation = 30

[node name="Close" type="Button" parent="GridContainer/MarginContainer/GridContainer"]
margin_right = 40.0
margin_bottom = 28.0
margin_right = 20.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 138, 238 )
mouse_default_cursor_shape = 2
theme_type_variation = "IconButton"
text = "  "
script = ExtResource( 3 )

[node name="Run" type="Button" parent="GridContainer/MarginContainer/GridContainer"]
margin_top = 58.0
margin_right = 40.0
margin_bottom = 86.0
margin_top = 50.0
margin_right = 20.0
margin_bottom = 70.0
mouse_filter = 1
mouse_default_cursor_shape = 2
theme_type_variation = "IconButton"
Expand Down
3 changes: 2 additions & 1 deletion app/components/MarkdownLabel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ mono_font = SubResource( 12 )
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_right = 1920.0
margin_bottom = 1080.0
mouse_filter = 0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 0
Expand All @@ -77,6 +76,7 @@ visible = false
margin_bottom = 69.0
rect_clip_content = false
focus_mode = 2
mouse_filter = 1
size_flags_horizontal = 3
theme = ExtResource( 2 )
custom_colors/default_color = Color( 1, 1, 1, 1 )
Expand All @@ -92,6 +92,7 @@ __meta__ = {

[node name="TextEdit" type="TextEdit" parent="VBoxContainer"]
visible = false
mouse_filter = 1
custom_colors/selection_color = Color( 0.207843, 0, 0.321569, 1 )
custom_colors/executing_line_color = Color( 0.0392157, 0, 0.168627, 1 )
custom_colors/font_color_readonly = Color( 0.878431, 0.878431, 0.878431, 1 )
Expand Down
8 changes: 5 additions & 3 deletions app/scenes/GUI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,22 @@ custom_constants/separation = 2
margin_right = 961.0
margin_bottom = 678.0
mouse_filter = 2
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 2.0

[node name="Editor" parent="LeftPanel/ThemeHolder/MarginContainer" instance=ExtResource( 1 )]
visible = false
margin_right = 961.0
margin_bottom = 678.0
middle_mouse_paste_enabled = false
deselect_on_focus_loss_enabled = false
drag_and_drop_selection_enabled = false
mouse_filter = 1

[node name="Console" parent="LeftPanel/ThemeHolder" instance=ExtResource( 2 )]
margin_top = 680.0
margin_right = 961.0
margin_bottom = 1080.0
size_flags_horizontal = 1
size_flags_vertical = 1

[node name="RightPanel" type="MarginContainer" parent="."]
visible = false
Expand Down
5 changes: 3 additions & 2 deletions src/game.nim
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,9 @@ gdobj Game of Node:

if event.is_action_pressed("previous"):
state.update_action_index(-1)
# NOTE: alt+enter isn't being picked up on windows if the editor is
# open. Needs investigation.

# NOTE: alt+enter isn't being picked up on windows if the editor is
# open. Needs investigation.
if event.is_action_pressed("toggle_fullscreen") or (
host_os == "windows" and CommandMode in state.local_flags and
EditorVisible in state.local_flags and event of InputEventKey and
Expand Down
67 changes: 33 additions & 34 deletions src/ui/console.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,42 @@ gdobj Console of RichTextLabel:
let width = self.rect_size.x
self.rect_position = vec2(width * offset, self.rect_position.y)

proc show() =
self.opacity = 1.0
if ?self.tween:
self.tween.kill
self.tween = self.get_tree.create_tween
self.visible = true
discard
self.tween
.tween_method(
self, "_offset_x", -1.0.to_variant, 0.0.to_variant, animation_duration
)
.set_trans(TRANS_EXPO)
.set_ease(EASE_IN_OUT)

proc hide() =
if ?self.tween:
self.tween.kill
self.tween = self.get_tree.create_tween
self.rect_position = vec2(0.0, self.rect_position.y)
discard
self.tween
.tween_method(
self, "_offset_x", 0.0.to_variant, -1.0.to_variant, animation_duration
)
.set_trans(TRANS_EXPO)
.set_ease(EASE_IN_OUT)
discard self.tween.tween_callback(
self, "set_visible", new_array(false.to_variant)
)

proc init*() =
state.local_flags.changes:
if ConsoleVisible.added:
if ?self.tween:
self.tween.kill
self.tween = self.get_tree.create_tween
self.visible = true
discard
self.tween
.tween_method(
self, "_offset_x", -1.0.to_variant, 0.0.to_variant,
animation_duration
)
.set_trans(TRANS_EXPO)
.set_ease(EASE_IN_OUT)
self.show()
elif ConsoleVisible.removed:
if ?self.tween:
self.tween.kill
self.tween = self.get_tree.create_tween
self.rect_position = vec2(0.0, self.rect_position.y)
discard
self.tween
.tween_method(
self, "_offset_x", 0.0.to_variant, -1.0.to_variant,
animation_duration
)
.set_trans(TRANS_EXPO)
.set_ease(EASE_IN_OUT)
discard self.tween.tween_callback(
self, "set_visible", new_array(false.to_variant)
)
self.hide()
elif CommandMode.added:
self.ghost()
elif CommandMode.removed:
Expand All @@ -72,14 +77,8 @@ gdobj Console of RichTextLabel:
state.nodes.game.bind_signal(self, "gui_input", self.name)

if ConsoleVisible notin state.local_flags:
let tween = self.get_tree.create_tween
self.opacity = 0.0
discard tween.tween_property(
self, "rect_position:y", (self.rect_size.y).to_variant, 0.0
)
discard
tween.tween_callback(self, "set_visible", new_array(false.to_variant))
discard tween.tween_property(self, "modulate:a", 1.0.to_variant, 0.0)
self.hide()

for child in self.get_children():
let o = child.as_object(Node) as VScrollBar
Expand Down
Loading

0 comments on commit 904ccee

Please sign in to comment.