-
Notifications
You must be signed in to change notification settings - Fork 4
/
colorpickerdialog.lua
76 lines (60 loc) · 1.97 KB
/
colorpickerdialog.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--
-- Color Picker Dialog Widget.
-- @copyright Jefferson Gonzalez
-- @license MIT
--
local style = require "core.style"
local Button = require "libraries.widget.button"
local ColorPicker = require "libraries.widget.colorpicker"
local Dialog = require "libraries.widget.dialog"
---@class widget.colorpickerdialog : widget.dialog
---@field super widget.dialog
---@field picker widget.colorpicker
---@field apply widget.button
---@field cancel widget.button
local ColorPickerDialog = Dialog:extend()
---Constructor
---@param title? string
---@param color? renderer.color | string
function ColorPickerDialog:new(title, color)
ColorPickerDialog.super.new(self, title or "Color Picker")
self.type_name = "widget.colorpickerdialog"
self.picker = ColorPicker(self.panel, color)
local this = self
self.apply = Button(self.panel, "Apply")
self.apply:set_icon("S")
function self.apply:on_click()
this:on_apply(this.picker:get_color())
this:on_close()
end
self.cancel = Button(self.panel, "Cancel")
self.cancel:set_icon("C")
function self.cancel:on_click()
this:on_close()
end
end
---Called when the user clicks on apply
---@param value renderer.color
function ColorPickerDialog:on_apply(value) end
function ColorPickerDialog:update()
if not ColorPickerDialog.super.update(self) then return false end
self.picker:set_position(style.padding.x/2, 0)
self.apply:set_position(
style.padding.x/2,
self.picker:get_bottom() + style.padding.y
)
self.cancel:set_position(
self.apply:get_right() + style.padding.x,
self.picker:get_bottom() + style.padding.y
)
self.panel.size.x = self.panel:get_real_width() + style.padding.x
self.panel.size.y = self.panel:get_real_height()
self.size.x = self:get_real_width() - (style.padding.x / 2)
self.size.y = self:get_real_height() + (style.padding.y / 2)
self.close:set_position(
self.size.x - self.close.size.x - (style.padding.x / 2),
style.padding.y / 2
)
return true
end
return ColorPickerDialog