add memory usage module with collector, scene, and script
This commit is contained in:
parent
cd6295e26f
commit
4169e0c5b6
4 changed files with 129 additions and 0 deletions
49
panels/memory/memory_module.gd
Normal file
49
panels/memory/memory_module.gd
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
extends ModuleBase
|
||||
class_name MemoryModule
|
||||
|
||||
|
||||
@onready var title_label: Label = %Title
|
||||
@onready var label: Label = %Label
|
||||
@onready var progress: ProgressBar = %ProgressBar
|
||||
|
||||
var _collector: MemoryCollector
|
||||
|
||||
|
||||
func initialize() -> void:
|
||||
module_title = "Memory"
|
||||
_collector = MemoryCollector.new()
|
||||
_style()
|
||||
|
||||
|
||||
func refresh(data: Dictionary) -> void:
|
||||
var usage: float = _collector.collect()
|
||||
if usage < 0.0:
|
||||
return
|
||||
|
||||
var pct: int = roundi(usage)
|
||||
label.text = "%d%%" % pct
|
||||
progress.value = pct
|
||||
|
||||
|
||||
func _style() -> void:
|
||||
title_label.add_theme_color_override("font_color", Color(0.7, 0.7, 0.8, 1.0))
|
||||
|
||||
label.add_theme_color_override("font_color", Color(0.9, 0.9, 1.0, 1.0))
|
||||
label.add_theme_font_size_override("font_size", 48)
|
||||
|
||||
var fg := StyleBoxFlat.new()
|
||||
fg.bg_color = Color(0.2, 0.7, 0.4, 1.0)
|
||||
fg.corner_radius_top_left = 4
|
||||
fg.corner_radius_top_right = 4
|
||||
fg.corner_radius_bottom_right = 4
|
||||
fg.corner_radius_bottom_left = 4
|
||||
|
||||
var bg := StyleBoxFlat.new()
|
||||
bg.bg_color = Color(0.1, 0.1, 0.14, 1.0)
|
||||
bg.corner_radius_top_left = 4
|
||||
bg.corner_radius_top_right = 4
|
||||
bg.corner_radius_bottom_right = 4
|
||||
bg.corner_radius_bottom_left = 4
|
||||
|
||||
progress.add_theme_stylebox_override("fill", fg)
|
||||
progress.add_theme_stylebox_override("background", bg)
|
||||
Loading…
Add table
Add a link
Reference in a new issue