diff --git a/druid/base/checkbox_group.lua b/druid/base/checkbox_group.lua index 459527e..92a18a6 100644 --- a/druid/base/checkbox_group.lua +++ b/druid/base/checkbox_group.lua @@ -12,8 +12,8 @@ end function M.set_state(self, indexes) for i = 1, #indexes do - if self.checkbox[indexes[i]] then - self.checkbox[indexes[i]]:set_state(true, true) + if self.checkboxes[i] then + self.checkboxes[i]:set_state(indexes[i], true) end end end diff --git a/druid/base/slider.lua b/druid/base/slider.lua index 0caa56f..ff2881f 100644 --- a/druid/base/slider.lua +++ b/druid/base/slider.lua @@ -76,6 +76,17 @@ function M.on_input(self, action_id, action) if action.released then self.is_drag = false end + + return self.is_drag +end + + +function M.set(self, value) + value = helper.clamp(value, 0, 1) + + gui.set_position(self.node, self.start_pos + self.dist * value) + self.value = value + on_change_value(self) end diff --git a/example/kenney/page/main.lua b/example/kenney/page/main.lua index 27e2da7..b597021 100644 --- a/example/kenney/page/main.lua +++ b/example/kenney/page/main.lua @@ -63,22 +63,27 @@ end local function setup_slider(self) - self.druid:new_slider("slider_pin", vmath.vector3(95, 0, 0), function(_, value) + local slider = self.druid:new_slider("slider_pin", vmath.vector3(95, 0, 0), function(_, value) gui.set_text(gui.get_node("text_progress_slider"), math.ceil(value * 100) .. "%") end) + + slider:set(0.2) end local function setup_checkbox(self) - self.druid:new_checkbox_group( - {"radio1/check", "radio2/check", "radio3/check" }, + local group1 = self.druid:new_checkbox_group( + {"radio1/check", "radio2/check", "radio3/check"}, nil, true, {"radio1/back", "radio2/back", "radio3/back"}) - self.druid:new_checkbox_group( - {"checkbox1/check", "checkbox2/check", "checkbox3/check" }, + local group2 = self.druid:new_checkbox_group( + {"checkbox1/check", "checkbox2/check", "checkbox3/check"}, nil, false, {"checkbox1/back", "checkbox2/back", "checkbox3/back"}) + + group1:set_state({false, false, true}) + group2:set_state({true, false, true}) end