WIP: More work on optimizing Editor

This commit is contained in:
2023-01-31 14:31:10 -06:00
parent 27d0b7314f
commit 3d29ff46e6

View File

@@ -272,11 +272,16 @@ module TAC
def create_action(name, comment) def create_action(name, comment)
action = TAC::Config::Action.new(name: name, comment: comment, enabled: true, variables: []) action = TAC::Config::Action.new(name: name, comment: comment, enabled: true, variables: [])
@active_group.actions << action @active_group.actions << action
@active_group.actions.sort_by! { |a| a.name.downcase } @active_group.actions.sort_by! { |a| a.name.downcase }
window.backend.config_changed! window.backend.config_changed!
populate_actions_list(@active_group) @actions_list.append do
add_action_container(action)
end
update_list_children(@actions_list)
scroll_into_view(action) scroll_into_view(action)
end end
@@ -289,10 +294,21 @@ module TAC
@active_group.actions.sort_by! { |a| a.name.downcase } @active_group.actions.sort_by! { |a| a.name.downcase }
window.backend.config_changed! window.backend.config_changed!
a = @actions_list.children.find { |a| a.style.tag == old_name.downcase } action_container = find_element_by_tag(@actions_list, old_name.downcase)
label = a.children.find { |a| a.style.tag == "label" } label = find_element_by_tag(action_container, "label")
# comment = a.children.find { |a| a.style.tag == "comment" } comment_container = find_element_by_tag(action_container, "comment_container")
comment_label = find_element_by_tag(action_container, "comment")
label.value = name label.value = name
if comment.empty?
action_container.style.height = 36
comment_container.hide
comment_label.value = ""
else
action_container.style.height = 72
comment_container.show
comment_label.value = comment.to_s
end
update_list_children(@actions_list) update_list_children(@actions_list)
@@ -309,7 +325,7 @@ module TAC
@variables_list.clear @variables_list.clear
# Remove deleted action from list # Remove deleted action from list
container = @actions_list.children.find { |a| a.style.tag == action.name.downcase } container = find_element_by_tag(@actions_list, action.name.downcase)
@actions_list.remove(container) @actions_list.remove(container)
update_list_children(@actions_list) update_list_children(@actions_list)
@@ -354,12 +370,12 @@ module TAC
is_action = list == @actions_list is_action = list == @actions_list
is_variable = list == @variables_list is_variable = list == @variables_list
list.children.sort_by! { |i| i.style.tag } list.children.sort_by! { |i| i.style.tag.downcase }
list.children.each_with_index do |child, i| list.children.each_with_index do |child, i|
bg_color = i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR bg_color = i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
bg_color = THEME_HIGHLIGHTED_COLOR if is_group && @active_group&.name&.downcase == child.style.tag bg_color = THEME_HIGHLIGHTED_COLOR if is_group && @active_group&.name == child.style.tag
bg_color = THEME_HIGHLIGHTED_COLOR if is_action && @active_action&.name&.downcase == child.style.tag bg_color = THEME_HIGHLIGHTED_COLOR if is_action && @active_action&.name == child.style.tag
child.style.default[:background] = bg_color child.style.default[:background] = bg_color
@@ -386,24 +402,53 @@ module TAC
end end
@groups_list.clear do @groups_list.clear do
groups.each_with_index do |group, i| groups.each do |group|
flow width: 1.0, height: 36, **THEME_ITEM_CONTAINER_PADDING, tag: group.name.downcase do |container| add_group_container(group)
background group == @active_group ? THEME_HIGHLIGHTED_COLOR : (i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR) end
end
end
def populate_actions_list(group)
@actions_list.scroll_top = 0
actions = group.actions
@actions_list.clear do
actions.each do |action|
add_action_container(action)
end
end
end
def populate_variables_list(action)
@variables_list.scroll_top = 0
variables = action.variables
@variables_list.clear do
variables.each do |variable|
add_variable_container(variable)
end
end
end
def add_group_container(group)
index = window.backend.config.groups.index(group)
flow width: 1.0, height: 36, **THEME_ITEM_CONTAINER_PADDING, tag: group.name do |container|
background group == @active_group ? THEME_HIGHLIGHTED_COLOR : (index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR)
@active_group_container = container if group == @active_group @active_group_container = container if group == @active_group
button group.name, fill: true, text_size: THEME_ICON_SIZE - 3, tag: "label" do button group.name, fill: true, text_size: THEME_ICON_SIZE - 3, tag: "label" do
if (old_i = groups.index(@active_group))
@active_group_container.style.default[:background] = old_i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
end
@active_group = group @active_group = group
@active_group_container = container @active_group_container = container
@active_group_container.style.default[:background] = THEME_HIGHLIGHTED_COLOR
@active_group_label.value = group.name @active_group_label.value = group.name
@active_action = nil @active_action = nil
@active_action_container = nil @active_action_container = nil
@active_action_label.value = "" @active_action_label.value = ""
update_list_children(@groups_list)
populate_actions_list(group) populate_actions_list(group)
@variables_list.clear @variables_list.clear
end end
@@ -416,31 +461,22 @@ module TAC
end end
end end
end end
end
end
def populate_actions_list(group) def add_action_container(action)
@actions_list.scroll_top = 0 index = @active_group.actions.index(action)
actions = group.actions stack width: 1.0, height: action.comment.empty? ? 36 : 72, **THEME_ITEM_CONTAINER_PADDING, tag: action.name do |container|
background action == @active_action ? THEME_HIGHLIGHTED_COLOR : (index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR)
@actions_list.clear do
actions.each_with_index do |action, i|
stack width: 1.0, height: action.comment.empty? ? 36 : 72, **THEME_ITEM_CONTAINER_PADDING, tag: action.name.downcase do |container|
background action == @active_action ? THEME_HIGHLIGHTED_COLOR : (i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR)
@active_action_container = container if action == @active_action @active_action_container = container if action == @active_action
flow width: 1.0, height: 36 do flow width: 1.0, height: 36 do
button action.name, fill: true, text_size: THEME_ICON_SIZE - 3, tag: "label" do button action.name, fill: true, text_size: THEME_ICON_SIZE - 3, tag: "label" do
if (old_i = actions.index(@active_action))
@active_action_container.style.default[:background] = old_i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
end
@active_action = action @active_action = action
@active_action_container = container @active_action_container = container
@active_action_container.style.default[:background] = THEME_HIGHLIGHTED_COLOR
@active_action_label.value = action.name @active_action_label.value = action.name
update_list_children(@actions_list)
populate_variables_list(action) populate_variables_list(action)
end end
@@ -459,28 +495,20 @@ module TAC
end end
end end
unless action.comment.empty? stack(width: 1.0, fill: true, scroll: true, visible: !action.comment.empty?, tag: "comment_container") do
stack(width: 1.0, fill: true, scroll: true) do
caption action.comment.to_s, width: 1.0, text_wrap: :word_wrap, text_border: true, text_border_size: 1, text_border_color: 0xaa_000000, tag: "comment" caption action.comment.to_s, width: 1.0, text_wrap: :word_wrap, text_border: true, text_border_size: 1, text_border_color: 0xaa_000000, tag: "comment"
end end
end end
end end
end
end
end
def populate_variables_list(action) def add_variable_container(variable)
@variables_list.scroll_top = 0 index = @active_action.variables.index(variable)
variables = action.variables stack width: 1.0, height: 96, **THEME_ITEM_CONTAINER_PADDING, tag: variable.name do
background index.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
@variables_list.clear do
variables.each_with_index do |variable, i|
stack width: 1.0, height: 96, **THEME_ITEM_CONTAINER_PADDING, tag: variable.name.downcase do
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
flow(width: 1.0, fill: true) do flow(width: 1.0, fill: true) do
button "#{variable.name}", fill: true, text_size: THEME_ICON_SIZE - 3, tip: "Edit variable", tag: "label" do button variable.name, fill: true, text_size: THEME_ICON_SIZE - 3, tip: "Edit variable", tag: "label" do
push_state(Dialog::VariableDialog, title: "Edit Variable", variable: variable, list: @active_action.variables, callback_method: method(:update_variable)) push_state(Dialog::VariableDialog, title: "Edit Variable", variable: variable, list: @active_action.variables, callback_method: method(:update_variable))
end end
@@ -493,8 +521,6 @@ module TAC
caption "Value: #{variable.value}", tag: "value", fill: true caption "Value: #{variable.value}", tag: "value", fill: true
end end
end end
end
end
def button_down(id) def button_down(id)
super super