Add more widgets

This commit is contained in:
Insality
2024-11-19 00:48:15 +02:00
parent 6cb2c9ca9a
commit 37190684c4
6 changed files with 570 additions and 3 deletions

View File

@@ -0,0 +1,58 @@
nodes {
size {
x: 200.0
y: 100.0
}
type: TYPE_BOX
id: "root"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
visible: false
}
nodes {
type: TYPE_TEMPLATE
id: "mini_graph"
parent: "root"
inherit_alpha: true
template: "/druid/widget/mini_graph/mini_graph.gui"
}
nodes {
type: TYPE_BOX
id: "mini_graph/root"
parent: "mini_graph"
template_node_child: true
}
nodes {
type: TYPE_TEXT
text: "Memory Panel"
id: "mini_graph/text_header"
parent: "mini_graph/root"
overridden_fields: 8
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "mini_graph/icon_drag"
parent: "mini_graph/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "mini_graph/panel_diagram"
parent: "mini_graph/root"
template_node_child: true
}
nodes {
type: TYPE_BOX
id: "mini_graph/prefab_line"
parent: "mini_graph/panel_diagram"
template_node_child: true
}
nodes {
type: TYPE_TEXT
id: "mini_graph/text_value"
parent: "mini_graph/root"
template_node_child: true
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

View File

@@ -0,0 +1,22 @@
local mini_graph = require("druid.widget.mini_graph.mini_graph")
---@class widget.memory_panel: druid.widget
---@field root node
local M = {}
function M:init()
self.druid = self:get_druid()
self.mini_graph = self.druid:new_widget(mini_graph, "mini_graph")
--for index = 1, 32 do
-- self.mini_graph:set_line_value(index, 0)
--end
timer.delay(0.1, true, function()
self.mini_graph:push_line_value(math.random())
end)
end
return M

View File

@@ -0,0 +1,171 @@
fonts {
name: "text_regular"
font: "/druid/fonts/text_regular.font"
}
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
}
textures {
name: "druid"
texture: "/druid/druid.atlas"
}
nodes {
size {
x: 200.0
y: 140.0
}
color {
x: 0.173
y: 0.184
z: 0.204
}
type: TYPE_BOX
texture: "druid/ui_circle_16"
id: "root"
inherit_alpha: true
slice9 {
x: 8.0
y: 8.0
z: 8.0
w: 8.0
}
}
nodes {
position {
x: -92.0
y: 63.0
}
scale {
x: 0.5
y: 0.5
}
size {
x: 260.0
y: 50.0
}
color {
x: 0.463
y: 0.475
z: 0.49
}
type: TYPE_TEXT
text: "Mini Graph"
font: "text_regular"
id: "text_header"
pivot: PIVOT_NW
outline {
x: 1.0
y: 1.0
z: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
}
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
position {
x: 92.0
y: 67.0
}
color {
x: 0.129
y: 0.141
z: 0.157
}
type: TYPE_BOX
texture: "druid/ui_circle_32"
id: "icon_drag"
pivot: PIVOT_NE
parent: "root"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
y: -70.0
}
size {
x: 200.0
y: 100.0
}
color {
x: 0.129
y: 0.141
z: 0.157
}
type: TYPE_BOX
texture: "druid/ui_circle_16"
id: "panel_diagram"
pivot: PIVOT_S
parent: "root"
inherit_alpha: true
slice9 {
x: 8.0
y: 8.0
z: 8.0
w: 8.0
}
clipping_mode: CLIPPING_MODE_STENCIL
}
nodes {
size {
x: 8.0
y: 70.0
}
color {
x: 0.957
y: 0.608
z: 0.608
}
type: TYPE_BOX
texture: "druid/pixel"
id: "prefab_line"
pivot: PIVOT_S
parent: "panel_diagram"
inherit_alpha: true
}
nodes {
position {
y: 12.0
}
scale {
x: 0.7
y: 0.7
}
size {
x: 260.0
y: 40.0
}
color {
x: 0.463
y: 0.475
z: 0.49
}
type: TYPE_TEXT
text: "120.23 KB"
font: "text_bold"
id: "text_value"
outline {
x: 1.0
y: 1.0
z: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
}
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

View File

@@ -0,0 +1,88 @@
local color = require("druid.color")
---@class widget.mini_graph: druid.widget
local M = {}
local SIZE_Y = hash("size.y")
function M:init()
self.druid = self:get_druid()
self.root = self:get_node("root")
self.container = self.druid:new_container(self.root)
self.text_header = self.druid:new_text("text_header")
self.text_value = self.druid:new_text("text_value")
self.drag_corner = self.druid:new_drag("icon_drag", self.on_drag_corner)
self.layout = self.druid:new_layout("panel_diagram", "horizontal")
:set_margin(0, 0)
:set_padding(0, 0, 0, 0)
self.prefab_line = self:get_node("prefab_line")
gui.set_enabled(self.prefab_line, false)
self.color_zero = color.hex2vector4("#8ED59E")
self.color_one = color.hex2vector4("#F49B9B")
self.lines = {}
self.values = {}
self.samples = 64
local line_width = self.layout:get_size().x / self.samples
for index = 1, self.samples do
local line = gui.clone(self.prefab_line)
gui.set_enabled(line, true)
gui.set(line, "size.x", line_width)
self.layout:add(line)
table.insert(self.lines, line)
end
for index = 1, self.samples do
local outsine = index/self.samples
self:set_line_value(index, outsine)
end
end
---@param index number
---@param value number The normalized value from 0 to 1
function M:set_line_value(index, value)
local line = self.lines[index]
if not line then
return
end
local target_color = color.lerp(value * value, self.color_zero, self.color_one)
gui.set(line, SIZE_Y, value * 70)
gui.set_color(line, target_color)
self.values[index] = value
end
---@return number
function M:get_line_value(index)
return self.values[index]
end
function M:push_line_value(value)
for index = 1, self.samples - 1 do
self:set_line_value(index, self:get_line_value(index + 1), true)
end
self:set_line_value(self.samples, value, true)
end
---@param text string
function M:set_text(text)
self.text_value:set_to(text)
end
function M:on_drag_corner(dx, dy)
local position = self.container:get_position()
self.container:set_position(position.x + dx, position.y + dy)
end
return M