Skip to content

Commit d6c3271

Browse files
committed
Add SetEnabled support for RmlUi action buttons
- Add SetEnabled method to RmlUiTabbedPanelButton - Buttons can now be enabled/disabled dynamically - Update GenerateRml to include disabled attribute - Add CSS styling for disabled action buttons - Fixes crash in texture_editor when disabling DNTS button
1 parent 4412391 commit d6c3271

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

scen_edit/view/rcss/springboard.rcss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ body#springboard {
244244
border-color: #3a7f3a;
245245
}
246246

247+
.action-button:disabled {
248+
background-color: #1a1a1a;
249+
border-color: #333333;
250+
opacity: 0.5;
251+
cursor: default;
252+
}
253+
247254
.action-button-icon {
248255
width: 35dp;
249256
height: 35dp;

scen_edit/view/rmlui_field_compat.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function RmlUiTabbedPanelButton:init(opts)
7878
self.tooltip = opts.tooltip or ""
7979
self.OnClick = opts.OnClick or {}
8080
self.pressed = false
81+
self.enabled = true
8182
self.caption = opts.caption or ""
8283
self.image = opts.image
8384
self.children = opts.children
@@ -94,10 +95,26 @@ function RmlUiTabbedPanelButton:SetPressedState(pressed)
9495
end
9596
end
9697

98+
function RmlUiTabbedPanelButton:SetEnabled(enabled)
99+
self.enabled = enabled
100+
-- Update DOM if we have the button element
101+
if SB.view and SB.view.mainDocument then
102+
local btnElement = SB.view.mainDocument:GetElementById(self.id)
103+
if btnElement then
104+
if enabled then
105+
btnElement:RemoveAttribute("disabled")
106+
else
107+
btnElement:SetAttribute("disabled", "")
108+
end
109+
end
110+
end
111+
end
112+
97113
function RmlUiTabbedPanelButton:GenerateRml()
98114
local pressedClass = self.pressed and " pressed" or ""
99-
local html = string.format('<button id="%s" class="action-button%s" title="%s">',
100-
self.id, pressedClass, self.tooltip)
115+
local disabledAttr = self.enabled and "" or ' disabled=""'
116+
local html = string.format('<button id="%s" class="action-button%s" title="%s"%s>',
117+
self.id, pressedClass, self.tooltip, disabledAttr)
101118

102119
if self.image then
103120
html = html .. string.format('<img src="%s" class="action-button-icon"/>', self.image)

0 commit comments

Comments
 (0)