Skip to content

Commit

Permalink
feat: buffered rich text area
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark2000 committed Nov 26, 2023
1 parent f037210 commit 6c1c8c8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions addons/panku_console/common/buffered_rich_text.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extends VBoxContainer

# it is like, an infinite scroll game.

# specifically, the first buffer will be cleared and sent to the last
# when the last buffer is full.

# with buffers, we can constanly output lots of fancy stuff while keeping a smooth experience.

const BUFFER_MAX_PARAGRAPHS = 64
const BUFFERS = 4

var cur_label_idx:int = 0

func add_text(text:String):
var cur_label:RichTextLabel = get_child(cur_label_idx)
cur_label.text += text
if cur_label.get_paragraph_count() > BUFFER_MAX_PARAGRAPHS:
cur_label_idx += 1
if cur_label_idx == BUFFERS:
cur_label_idx = BUFFERS - 1
var first_label:RichTextLabel = get_child(0)
first_label.text = ""
move_child(first_label, BUFFERS - 1)

func _ready():
set("theme_override_constants/separation", 0)
for child in get_children():
child.queue_free()
for i in range(BUFFERS):
var new_buffer:RichTextLabel = RichTextLabel.new()
new_buffer.fit_content = true
new_buffer.bbcode_enabled = true
new_buffer.selection_enabled = true
add_child(new_buffer)

0 comments on commit 6c1c8c8

Please sign in to comment.