Update examples to widgets instead components

This commit is contained in:
Insality
2025-03-27 00:19:32 +02:00
parent dee77ab313
commit 7640e207a4
47 changed files with 183 additions and 422 deletions

View File

@@ -9,7 +9,7 @@ function M.get_examples()
template = "hover_hint_example",
root = "hover_hint_example/root",
code_url = "example/examples/widgets/hover_hint/hover_hint_example.lua",
component_class = require("example.examples.widgets.hover_hint.hover_hint_example"),
widget_class = require("example.examples.widgets.hover_hint.hover_hint_example"),
},
{
name_id = "ui_example_widget_properties_panel",
@@ -83,7 +83,7 @@ function M.get_examples()
template = "property_button",
root = "property_button/root",
code_url = "example/components/properties_panel/properties/property_button.lua",
component_class = require("example.components.properties_panel.properties.property_button"),
widget_class = require("example.components.properties_panel.properties.property_button"),
on_create = function(instance, output_list)
---@cast instance property_button
instance.button.on_click:subscribe(function()
@@ -105,7 +105,7 @@ function M.get_examples()
template = "property_slider",
root = "property_slider/root",
code_url = "example/components/properties_panel/properties/property_slider.lua",
component_class = require("example.components.properties_panel.properties.property_slider"),
widget_class = require("example.components.properties_panel.properties.property_slider"),
on_create = function(instance, output_list)
---@cast instance property_slider
instance.slider.on_change_value:subscribe(function(_, value)
@@ -119,7 +119,7 @@ function M.get_examples()
template = "property_checkbox",
root = "property_checkbox/root",
code_url = "example/components/properties_panel/properties/property_checkbox.lua",
component_class = require("example.components.properties_panel.properties.property_checkbox"),
widget_class = require("example.components.properties_panel.properties.property_checkbox"),
on_create = function(instance, output_list)
---@cast instance property_checkbox
instance.button.on_click:subscribe(function()

View File

@@ -1,9 +1,7 @@
local helper = require("druid.helper")
local druid_const = require("druid.const")
local component = require("druid.component")
---@class examples.hover_hint: druid.component
---@field druid druid.instance
---@class examples.hover_hint: druid.widget
---@field root node
---@field panel_hint node
---@field text_hint druid.text
@@ -11,7 +9,7 @@ local component = require("druid.component")
---@field is_shown boolean
---@field private _hint_text string
---@field private _hover_timer_id hash
local M = component.create("hover_hint")
local M = {}
local TIMER_DELAY = 0.5
local MIN_PANEL_WIDTH = 100
@@ -19,10 +17,7 @@ local MIN_PANEL_HEIGHT = 50
local PANEL_MARGIN = 40
local HINT_OFFSET = 20
---@param template string
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
function M:init()
self.root = self:get_node("root")
self.panel_hint = self:get_node("panel_hint")
self.text_hint = self.druid:new_text("text_hint")

View File

@@ -1,17 +1,10 @@
local hover_hint = require("example.examples.widgets.hover_hint.hover_hint")
local component = require("druid.component")
---@class examples.hover_hint_example: druid.widget
local M = {}
---@class examples.hover_hint_example: druid.component
---@field druid druid.instance
local M = component.create("hover_hint_example")
---@param template string
---@param nodes table<hash, node>
function M:init(template, nodes)
self.druid = self:get_druid(template, nodes)
self.hover_hint = self.druid:new(hover_hint, "hover_hint")
function M:init()
self.hover_hint = self.druid:new_widget(hover_hint, "hover_hint")
self.hover_hint:add_hover_hint(self:get_node("node_yellow"), "Yellow box", gui.PIVOT_N, gui.PIVOT_S)
self.hover_hint:add_hover_hint(self:get_node("node_green"), "Green box", gui.PIVOT_S, gui.PIVOT_N)