mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Add more widgets
This commit is contained in:
171
druid/widget/mini_graph/mini_graph.gui
Normal file
171
druid/widget/mini_graph/mini_graph.gui
Normal 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
|
88
druid/widget/mini_graph/mini_graph.lua
Normal file
88
druid/widget/mini_graph/mini_graph.lua
Normal 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
|
Reference in New Issue
Block a user