/
d.vision
/
division_engine_cpp
Обзор
Документация
Войти
/
d.vision
/
division_engine_cpp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
resources/scripts/views/text.lua
56 строк
1 KB
den163
Improved annotations
27 ноя 2024, 11:06
27 ноя 2024, 11:06
0828538
Код
Авторство
О чём код?
local base_view = require 'views.view' local color = require 'color' local division = require 'division' local constrained_size = require 'constrained_size' ---@class text.options ---@field text string ---@field color vec4? ---@field font_size number? ---@field block_input boolean? ---@class text: view, text.options ---@overload fun(options: text.options): text ---@diagnostic disable-next-line: assign-type-mismatch local text = base_view:inherit 'text' ---@class text.state: view.state ---@field id entity_id text.state = base_view.state:inherit 'text.state' ---@param options text.options ---@return text function text:__call(options) local text = text:new(options) assert(options.text, "Text view must have a text option") text.color = options.color or color.BLACK text.font_size = options.font_size or 16 text.block_input = options.block_input or false return text end function text:create_state() return text.state:new { id = division:create_drawable_text(self.block_input) } end ---@param constraints constraints ---@param view text function text.state:layout(constraints, view) return constrained_size:unconstrained() end ---@param render_rect rect ---@param view text function text.state:render(render_rect, view) division:set_drawable_text( self.id, view.text, render_rect, view.color, view.font_size) end function text.state:destroy() division:destroy_entity(self.id) end return text