Skip to content

Commit

Permalink
Add swatch theme (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur committed Jun 8, 2024
1 parent cdb8551 commit 9a1653c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 64 deletions.
30 changes: 21 additions & 9 deletions src/ThemeGenerator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
28 changes: 2 additions & 26 deletions src/ui_elements/color_swatch.tscn
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
[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
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")
28 changes: 2 additions & 26 deletions src/ui_elements/color_swatch_config.tscn
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
[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
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")
6 changes: 3 additions & 3 deletions src/ui_elements/palette_config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9a1653c

Please sign in to comment.