This commit is contained in:
Insality
2024-11-20 23:36:04 +02:00
parent f2fa5320d2
commit 7ea8691fc5
104 changed files with 451 additions and 12743 deletions

View File

@@ -34,7 +34,7 @@
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_grid" target="_blank"><b>Example Link</b></a>
-- @module StaticGrid
-- @within BaseComponent
-- @alias druid.static_grid
-- @alias druid.grid
--- On item add callback(self, node, index)
-- @tfield druid.event on_add_item druid.event
@@ -377,7 +377,7 @@ end
--- Change set position function for grid nodes. It will call on
-- update poses on grid elements. Default: gui.set_position
---@param callback function Function on node set position
---@return druid.static_grid Current grid instance
---@return druid.grid Current grid instance
function M:set_position_function(callback)
self._set_position_function = callback or gui.set_position
@@ -387,7 +387,7 @@ end
--- Clear grid nodes array. GUI nodes will be not deleted!
-- If you want to delete GUI nodes, use static_grid.nodes array before grid:clear
---@return druid.static_grid Current grid instance
---@return druid.grid Current grid instance
function M:clear()
self.border.x = 0
self.border.y = 0
@@ -421,7 +421,7 @@ end
--- Set new in_row elements for grid
---@param in_row number The new in_row value
---@return druid.static_grid Current grid instance
---@return druid.grid Current grid instance
function M:set_in_row(in_row)
self.in_row = in_row
self._grid_horizonal_offset = self.node_size.x * (self.in_row - 1) * self.anchor.x
@@ -440,7 +440,7 @@ end
--- Set new node size for grid
-- @tparam[opt] number width The new node width
-- @tparam[opt] number height The new node height
---@return druid.static_grid Current grid instance
---@return druid.grid Current grid instance
function M:set_item_size(width, height)
if width then
self.node_size.x = width
@@ -463,7 +463,7 @@ end
--- Sort grid nodes by custom comparator function
---@param comparator function The comparator function. (a, b) -> boolean
---@return druid.static_grid Current grid instance
---@return druid.grid Current grid instance
function M:sort_nodes(comparator)
table.sort(self.nodes, comparator)
self:_update(true)

View File

@@ -1,6 +1,6 @@
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"

View File

@@ -1,12 +1,9 @@
# @license MIT, Insality 2021
# @source https://github.com/Insality/druid
import os
import sys
import deftree
current_filepath = os.path.abspath(os.path.dirname(__file__))
TEMPLATE_PATH = current_filepath + "/component.lua_template"
TEMPLATE_PATH = current_filepath + "/widget.lua_template"
component_annotations = ""
component_functions = ""
@@ -44,9 +41,9 @@ def process_component(node_name, component_name):
component_define += "\n\tself.{0} = self.druid:new_lang_text(\"{1}\", \"lang_id\")".format(node_name, node_name)
if node_name.startswith("grid") or node_name.startswith("static_grid"):
component_annotations += "\n---@field {0} druid.static_grid".format(node_name)
component_annotations += "\n---@field {0} druid.grid".format(node_name)
component_define += "\n--TODO: Replace prefab_name with grid element prefab"
component_define += "\n\tself.{0} = self.druid:new_static_grid(\"{1}\", \"prefab_name\", 1)".format(node_name, node_name)
component_define += "\n\tself.{0} = self.druid:new_grid(\"{1}\", \"prefab_name\", 1)".format(node_name, node_name)
if node_name.startswith("scroll_view"):
field_name = node_name.replace("_view", "")

View File

@@ -50,7 +50,7 @@ function M.get_commands()
},
{
label = "Create Druid Component",
label = "Create Druid Widget",
locations = { "Edit", "Assets" },
query = { selection = {type = "resource", cardinality = "one"} },
active = function(opts)
@@ -62,7 +62,7 @@ function M.get_commands()
print("Run script for", editor.get(file, "path"))
save_file_from_dependency('/druid/editor_scripts/run_python_script_on_gui.sh', "./build/run_python_script_on_gui.sh")
save_file_from_dependency('/druid/editor_scripts/create_druid_component.py', "./build/create_druid_component.py")
save_file_from_dependency('/druid/editor_scripts/component.lua_template', "./build/component.lua_template")
save_file_from_dependency('/druid/editor_scripts/widget.lua_template', "./build/widget.lua_template")
return {
{
action = "shell",

View File

@@ -1,9 +1,14 @@
---@class widget.TEMPLATE: druid.widget
---This is a template for a {COMPONENT_NAME} Druid widget.
---Instantiate this template with `druid.new_widget(widget_module, [template_id], [nodes])`.
---Read more about Druid Widgets here: ...
---@class widget.{COMPONENT_TYPE}: druid.widget
local M = {}
function M:init()
self.root = self:get_node("root")
self.button = self.druid:new_button("button"), self.on_button, self)
self.button = self.druid:new_button("button", self.on_button, self)
end

View File

@@ -1,16 +1,16 @@
local component = require("druid.component")
---@class component_name : druid.base_component
local M = component.create("component_name")
---@class widget.TEMPLATE: druid.widget
local M = {}
-- Component constructor. Template name and nodes are optional. Pass it if you use it in your component
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
function M:init()
self.root = self:get_node("root")
self.button = self.druid:new_button("button", function() end)
self.button = self.druid:new_button("button", self.on_button, self)
end
return M
function M:on_button()
print("Root node", self.root)
end
return M

View File

@@ -1,10 +1,10 @@
fonts {
name: "text_regular"
font: "/druid/fonts/text_regular.font"
name: "druid_text_regular"
font: "/druid/fonts/druid_text_regular.font"
}
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"
@@ -122,7 +122,7 @@ nodes {
}
type: TYPE_TEXT
text: "12 FPS"
font: "text_regular"
font: "druid_text_regular"
id: "text_min_fps"
pivot: PIVOT_W
outline {
@@ -159,7 +159,7 @@ nodes {
}
type: TYPE_TEXT
text: "60 FPS"
font: "text_bold"
font: "druid_text_bold"
id: "text_fps"
outline {
x: 1.0

View File

@@ -75,9 +75,9 @@ function M:push_fps_value()
self.mini_graph:push_line_value(1 / average_frame_time)
self.text_fps:set_to(tostring(math.ceil(1 / average_frame_time) .. " FPS"))
self.text_fps:set_text(tostring(math.ceil(1 / average_frame_time) .. " FPS"))
local lowest_value = math.ceil(self.mini_graph:get_lowest_value())
self.text_min_fps:set_to(lowest_value .. " lowest")
self.text_min_fps:set_text(lowest_value .. " lowest")
end

View File

@@ -1,10 +1,10 @@
fonts {
name: "text_regular"
font: "/druid/fonts/text_regular.font"
name: "druid_text_regular"
font: "/druid/fonts/druid_text_regular.font"
}
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"
@@ -104,7 +104,7 @@ nodes {
}
type: TYPE_TEXT
text: "120.23 KB"
font: "text_regular"
font: "druid_text_regular"
id: "text_max_value"
pivot: PIVOT_W
outline {
@@ -142,7 +142,7 @@ nodes {
}
type: TYPE_TEXT
text: "120 KB/s"
font: "text_regular"
font: "druid_text_regular"
id: "text_per_second"
pivot: PIVOT_E
outline {
@@ -221,7 +221,7 @@ nodes {
}
type: TYPE_TEXT
text: "120 KB"
font: "text_bold"
font: "druid_text_bold"
id: "text_memory"
outline {
x: 1.0

View File

@@ -51,14 +51,14 @@ function M:push_next_value()
self.mini_graph:set_max_value(max_value)
local max_memory = math.ceil(self.mini_graph:get_highest_value())
self.max_value:set_to(max_memory .. " KB")
self.max_value:set_text(max_memory .. " KB")
local last_second = 0
local last_second_samples = math.ceil(1 / self.delta_time)
for index = #self.memory_samples - last_second_samples + 1, #self.memory_samples do
last_second = last_second + (self.memory_samples[index] or 0)
end
self.text_per_second:set_to(math.ceil(last_second) .. " KB/s")
self.text_per_second:set_text(math.ceil(last_second) .. " KB/s")
end
@@ -66,9 +66,9 @@ function M:update_text_memory()
local memory = math.ceil(collectgarbage("count")) -- in KB
if memory > 1024 then
memory = memory / 1024
self.text_memory:set_to(string.format("%.2f", memory) .. " MB")
self.text_memory:set_text(string.format("%.2f", memory) .. " MB")
else
self.text_memory:set_to(memory .. " KB")
self.text_memory:set_text(memory .. " KB")
end
end

View File

@@ -1,10 +1,10 @@
fonts {
name: "text_regular"
font: "/druid/fonts/text_regular.font"
name: "druid_text_regular"
font: "/druid/fonts/druid_text_regular.font"
}
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"
@@ -67,7 +67,7 @@ nodes {
}
type: TYPE_TEXT
text: "Mini Graph"
font: "text_regular"
font: "druid_text_regular"
id: "text_header"
pivot: PIVOT_NW
outline {

View File

@@ -1,6 +1,6 @@
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"

View File

@@ -1,6 +1,6 @@
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"

View File

@@ -1,6 +1,6 @@
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"

View File

@@ -1,6 +1,6 @@
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"

View File

@@ -1,6 +1,6 @@
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"
@@ -37,7 +37,7 @@ nodes {
}
type: TYPE_TEXT
text: "Slider"
font: "text_bold"
font: "druid_text_bold"
id: "text_name"
pivot: PIVOT_W
outline {
@@ -201,7 +201,7 @@ nodes {
}
type: TYPE_TEXT
text: "25 %"
font: "text_bold"
font: "druid_text_bold"
id: "text_value"
outline {
x: 1.0

View File

@@ -1,6 +1,6 @@
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"

View File

@@ -1,10 +1,10 @@
fonts {
name: "text_regular"
font: "/druid/fonts/text_regular.font"
name: "druid_text_regular"
font: "/druid/fonts/druid_text_regular.font"
}
fonts {
name: "text_bold"
font: "/druid/fonts/text_bold.font"
name: "druid_text_bold"
font: "/druid/fonts/druid_text_bold.font"
}
textures {
name: "druid"
@@ -67,7 +67,7 @@ nodes {
}
type: TYPE_TEXT
text: "Properties"
font: "text_regular"
font: "druid_text_regular"
id: "text_header"
pivot: PIVOT_NW
outline {