From 9a1653caa5c9256ee3cc6c8423d77670b670a616 Mon Sep 17 00:00:00 2001 From: Mew Pur Pur <85438892+MewPurPur@users.noreply.github.com> Date: Sat, 8 Jun 2024 13:33:26 +0300 Subject: [PATCH] Add swatch theme (#789) --- src/ThemeGenerator.gd | 30 +++++++++++++++++------- src/ui_elements/color_swatch.tscn | 28 ++-------------------- src/ui_elements/color_swatch_config.tscn | 28 ++-------------------- src/ui_elements/palette_config.gd | 6 ++--- 4 files changed, 28 insertions(+), 64 deletions(-) diff --git a/src/ThemeGenerator.gd b/src/ThemeGenerator.gd index 812e94ff..46ff40bf 100644 --- a/src/ThemeGenerator.gd +++ b/src/ThemeGenerator.gd @@ -456,6 +456,10 @@ static func setup_button(theme: Theme) -> void: normal_sidetab_stylebox.content_margin_top = 3 theme.set_stylebox("normal", "SideTab", normal_sidetab_stylebox) + var hovered_sidetab_stylebox := normal_sidetab_stylebox.duplicate() + hovered_sidetab_stylebox.bg_color = hovered_tab_color + theme.set_stylebox("hover", "SideTab", hovered_sidetab_stylebox) + var pressed_sidetab_stylebox := StyleBoxFlat.new() pressed_sidetab_stylebox.bg_color = selected_tab_color pressed_sidetab_stylebox.border_color = selected_tab_border_color @@ -466,15 +470,23 @@ static func setup_button(theme: Theme) -> void: pressed_sidetab_stylebox.content_margin_top = 3 theme.set_stylebox("pressed", "SideTab", pressed_sidetab_stylebox) - var hovered_sidetab_stylebox := StyleBoxFlat.new() - hovered_sidetab_stylebox.bg_color = hovered_tab_color - hovered_sidetab_stylebox.corner_radius_top_left = 4 - hovered_sidetab_stylebox.corner_radius_bottom_left = 4 - hovered_sidetab_stylebox.content_margin_left = 6 - hovered_sidetab_stylebox.content_margin_right = 6 - hovered_sidetab_stylebox.content_margin_bottom = 3 - hovered_sidetab_stylebox.content_margin_top = 3 - theme.set_stylebox("hover", "SideTab", hovered_sidetab_stylebox) + theme.add_type("Swatch") + theme.set_type_variation("Swatch", "Button") + var swatch_stylebox := StyleBoxFlat.new() + swatch_stylebox.set_corner_radius_all(3) + + var normal_swatch_stylebox := swatch_stylebox.duplicate() + normal_swatch_stylebox.bg_color = common_button_border_color_normal + theme.set_stylebox("normal", "Swatch", normal_swatch_stylebox) + + var hover_swatch_stylebox := swatch_stylebox.duplicate() + hover_swatch_stylebox.bg_color = common_button_border_color_hover + theme.set_stylebox("hover", "Swatch", hover_swatch_stylebox) + + var pressed_swatch_stylebox := swatch_stylebox.duplicate() + pressed_swatch_stylebox.bg_color = common_button_border_color_pressed + theme.set_stylebox("pressed", "Swatch", pressed_swatch_stylebox) + theme.set_stylebox("disabled", "Swatch", pressed_swatch_stylebox) static func setup_checkbox(theme: Theme) -> void: theme.add_type("CheckBox") diff --git a/src/ui_elements/color_swatch.tscn b/src/ui_elements/color_swatch.tscn index 498f5060..b5fb95c8 100644 --- a/src/ui_elements/color_swatch.tscn +++ b/src/ui_elements/color_swatch.tscn @@ -1,28 +1,7 @@ -[gd_scene load_steps=5 format=3 uid="uid://cpvtf3kaa2ltr"] +[gd_scene load_steps=2 format=3 uid="uid://cpvtf3kaa2ltr"] [ext_resource type="Script" path="res://src/ui_elements/color_swatch.gd" id="1_2b2yq"] -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_m3oh3"] -bg_color = Color(0.164706, 0.188235, 0.301961, 1) -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kojaf"] -bg_color = Color(0.247059, 0.313726, 0.45098, 1) -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ym6fi"] -bg_color = Color(0.34902, 0.52549, 0.701961, 1) -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 - [node name="ColorSwatch" type="Button"] custom_minimum_size = Vector2(22, 22) offset_right = 20.0 @@ -30,8 +9,5 @@ offset_bottom = 20.0 focus_mode = 0 mouse_filter = 1 mouse_default_cursor_shape = 2 -theme_override_styles/normal = SubResource("StyleBoxFlat_m3oh3") -theme_override_styles/hover = SubResource("StyleBoxFlat_kojaf") -theme_override_styles/pressed = SubResource("StyleBoxFlat_ym6fi") -theme_override_styles/disabled = SubResource("StyleBoxFlat_ym6fi") +theme_type_variation = &"Swatch" script = ExtResource("1_2b2yq") diff --git a/src/ui_elements/color_swatch_config.tscn b/src/ui_elements/color_swatch_config.tscn index a4bd65f5..dae41fc9 100644 --- a/src/ui_elements/color_swatch_config.tscn +++ b/src/ui_elements/color_swatch_config.tscn @@ -1,28 +1,7 @@ -[gd_scene load_steps=5 format=3 uid="uid://e73b7lssdp6m"] +[gd_scene load_steps=2 format=3 uid="uid://e73b7lssdp6m"] [ext_resource type="Script" path="res://src/ui_elements/color_swatch_config.gd" id="1_u3awj"] -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_m3oh3"] -bg_color = Color(0.164706, 0.188235, 0.301961, 1) -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kojaf"] -bg_color = Color(0.247059, 0.313726, 0.45098, 1) -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ym6fi"] -bg_color = Color(0.34902, 0.52549, 0.701961, 1) -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 - [node name="ColorSwatchConfig" type="Button"] custom_minimum_size = Vector2(22, 22) offset_right = 20.0 @@ -30,8 +9,5 @@ offset_bottom = 20.0 focus_mode = 0 mouse_filter = 1 mouse_default_cursor_shape = 2 -theme_override_styles/normal = SubResource("StyleBoxFlat_m3oh3") -theme_override_styles/hover = SubResource("StyleBoxFlat_kojaf") -theme_override_styles/pressed = SubResource("StyleBoxFlat_ym6fi") -theme_override_styles/disabled = SubResource("StyleBoxFlat_ym6fi") +theme_type_variation = &"Swatch" script = ExtResource("1_u3awj") diff --git a/src/ui_elements/palette_config.gd b/src/ui_elements/palette_config.gd index d7f04f4a..4f6c85bb 100644 --- a/src/ui_elements/palette_config.gd +++ b/src/ui_elements/palette_config.gd @@ -52,22 +52,22 @@ func rebuild_colors() -> void: if is_instance_valid(swatch): swatch.pressed.emit() # Add the add button. - var color_swatch_ref := ColorSwatch.instantiate() var fake_swatch := Button.new() fake_swatch.begin_bulk_theme_override() for stylebox_type in ["normal", "hover", "pressed"]: fake_swatch.add_theme_stylebox_override(stylebox_type, - color_swatch_ref.get_theme_stylebox(stylebox_type)) + fake_swatch.get_theme_stylebox(stylebox_type, "Swatch")) fake_swatch.end_bulk_theme_override() fake_swatch.icon = plus_icon fake_swatch.icon_alignment = HORIZONTAL_ALIGNMENT_CENTER fake_swatch.focus_mode = Control.FOCUS_NONE fake_swatch.mouse_filter = Control.MOUSE_FILTER_PASS fake_swatch.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + var color_swatch_ref := ColorSwatch.instantiate() fake_swatch.custom_minimum_size = color_swatch_ref.custom_minimum_size + color_swatch_ref.queue_free() fake_swatch.pressed.connect(popup_add_color) colors_container.add_child(fake_swatch) - color_swatch_ref.queue_free() func popup_configure_color(swatch: Button) -> void: var configure_popup := ConfigurePopup.instantiate()