You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
Merge pull request #69053 from KoBeWi/grabbercentrism
Add center_grabber theme property to Slider
This commit is contained in:
@@ -141,6 +141,9 @@
|
|||||||
</constant>
|
</constant>
|
||||||
</constants>
|
</constants>
|
||||||
<theme_items>
|
<theme_items>
|
||||||
|
<theme_item name="center_slider_grabbers" data_type="constant" type="int" default="1">
|
||||||
|
Overrides the [theme_item HSlider.center_grabber] theme property of the sliders.
|
||||||
|
</theme_item>
|
||||||
<theme_item name="h_width" data_type="constant" type="int" default="30">
|
<theme_item name="h_width" data_type="constant" type="int" default="30">
|
||||||
The width of the hue selection slider.
|
The width of the hue selection slider.
|
||||||
</theme_item>
|
</theme_item>
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
<tutorials>
|
<tutorials>
|
||||||
</tutorials>
|
</tutorials>
|
||||||
<theme_items>
|
<theme_items>
|
||||||
|
<theme_item name="center_grabber" data_type="constant" type="int" default="0">
|
||||||
|
Boolean constant. If [code]1[/code], the grabber texture size will be ignored and it will fit within slider's bounds based only on its center position.
|
||||||
|
</theme_item>
|
||||||
<theme_item name="grabber_offset" data_type="constant" type="int" default="0">
|
<theme_item name="grabber_offset" data_type="constant" type="int" default="0">
|
||||||
Vertical offset of the grabber.
|
Vertical offset of the grabber.
|
||||||
</theme_item>
|
</theme_item>
|
||||||
|
|||||||
@@ -14,6 +14,9 @@
|
|||||||
<member name="size_flags_vertical" type="int" setter="set_v_size_flags" getter="get_v_size_flags" overrides="Control" enum="Control.SizeFlags" default="1" />
|
<member name="size_flags_vertical" type="int" setter="set_v_size_flags" getter="get_v_size_flags" overrides="Control" enum="Control.SizeFlags" default="1" />
|
||||||
</members>
|
</members>
|
||||||
<theme_items>
|
<theme_items>
|
||||||
|
<theme_item name="center_grabber" data_type="constant" type="int" default="0">
|
||||||
|
Boolean constant. If [code]1[/code], the grabber texture size will be ignored and it will fit within slider's bounds based only on its center position.
|
||||||
|
</theme_item>
|
||||||
<theme_item name="grabber_offset" data_type="constant" type="int" default="0">
|
<theme_item name="grabber_offset" data_type="constant" type="int" default="0">
|
||||||
Horizontal offset of the grabber.
|
Horizontal offset of the grabber.
|
||||||
</theme_item>
|
</theme_item>
|
||||||
|
|||||||
@@ -1604,6 +1604,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
|||||||
theme->set_stylebox("slider", "HSlider", make_flat_stylebox(dark_color_3, 0, default_margin_size / 2, 0, default_margin_size / 2, corner_width));
|
theme->set_stylebox("slider", "HSlider", make_flat_stylebox(dark_color_3, 0, default_margin_size / 2, 0, default_margin_size / 2, corner_width));
|
||||||
theme->set_stylebox("grabber_area", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2, corner_width));
|
theme->set_stylebox("grabber_area", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2, corner_width));
|
||||||
theme->set_stylebox("grabber_area_highlight", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2));
|
theme->set_stylebox("grabber_area_highlight", "HSlider", make_flat_stylebox(contrast_color_1, 0, default_margin_size / 2, 0, default_margin_size / 2));
|
||||||
|
theme->set_constant("center_grabber", "HSlider", 0);
|
||||||
theme->set_constant("grabber_offset", "HSlider", 0);
|
theme->set_constant("grabber_offset", "HSlider", 0);
|
||||||
|
|
||||||
// VSlider
|
// VSlider
|
||||||
@@ -1612,6 +1613,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
|||||||
theme->set_stylebox("slider", "VSlider", make_flat_stylebox(dark_color_3, default_margin_size / 2, 0, default_margin_size / 2, 0, corner_width));
|
theme->set_stylebox("slider", "VSlider", make_flat_stylebox(dark_color_3, default_margin_size / 2, 0, default_margin_size / 2, 0, corner_width));
|
||||||
theme->set_stylebox("grabber_area", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0, corner_width));
|
theme->set_stylebox("grabber_area", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0, corner_width));
|
||||||
theme->set_stylebox("grabber_area_highlight", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0));
|
theme->set_stylebox("grabber_area_highlight", "VSlider", make_flat_stylebox(contrast_color_1, default_margin_size / 2, 0, default_margin_size / 2, 0));
|
||||||
|
theme->set_constant("center_grabber", "VSlider", 0);
|
||||||
theme->set_constant("grabber_offset", "VSlider", 0);
|
theme->set_constant("grabber_offset", "VSlider", 0);
|
||||||
|
|
||||||
// RichTextLabel
|
// RichTextLabel
|
||||||
@@ -1868,6 +1870,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
|||||||
theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE);
|
theme->set_constant("sv_height", "ColorPicker", 256 * EDSCALE);
|
||||||
theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE);
|
theme->set_constant("h_width", "ColorPicker", 30 * EDSCALE);
|
||||||
theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE);
|
theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE);
|
||||||
|
theme->set_constant("center_slider_grabbers", "ColorPicker", 1);
|
||||||
theme->set_icon("screen_picker", "ColorPicker", theme->get_icon(SNAME("ColorPick"), SNAME("EditorIcons")));
|
theme->set_icon("screen_picker", "ColorPicker", theme->get_icon(SNAME("ColorPick"), SNAME("EditorIcons")));
|
||||||
theme->set_icon("shape_circle", "ColorPicker", theme->get_icon(SNAME("PickerShapeCircle"), SNAME("EditorIcons")));
|
theme->set_icon("shape_circle", "ColorPicker", theme->get_icon(SNAME("PickerShapeCircle"), SNAME("EditorIcons")));
|
||||||
theme->set_icon("shape_rect", "ColorPicker", theme->get_icon(SNAME("PickerShapeRectangle"), SNAME("EditorIcons")));
|
theme->set_icon("shape_rect", "ColorPicker", theme->get_icon(SNAME("PickerShapeRectangle"), SNAME("EditorIcons")));
|
||||||
|
|||||||
@@ -67,9 +67,11 @@ void ColorPicker::_notification(int p_what) {
|
|||||||
|
|
||||||
for (int i = 0; i < SLIDER_COUNT; i++) {
|
for (int i = 0; i < SLIDER_COUNT; i++) {
|
||||||
labels[i]->set_custom_minimum_size(Size2(theme_cache.label_width, 0));
|
labels[i]->set_custom_minimum_size(Size2(theme_cache.label_width, 0));
|
||||||
|
sliders[i]->add_theme_constant_override(SNAME("center_grabber"), theme_cache.center_slider_grabbers);
|
||||||
set_offset((Side)i, get_offset((Side)i) + theme_cache.content_margin);
|
set_offset((Side)i, get_offset((Side)i) + theme_cache.content_margin);
|
||||||
}
|
}
|
||||||
alpha_label->set_custom_minimum_size(Size2(theme_cache.label_width, 0));
|
alpha_label->set_custom_minimum_size(Size2(theme_cache.label_width, 0));
|
||||||
|
alpha_label->add_theme_constant_override(SNAME("center_grabber"), theme_cache.center_slider_grabbers);
|
||||||
set_offset((Side)0, get_offset((Side)0) + theme_cache.content_margin);
|
set_offset((Side)0, get_offset((Side)0) + theme_cache.content_margin);
|
||||||
|
|
||||||
for (int i = 0; i < MODE_BUTTON_COUNT; i++) {
|
for (int i = 0; i < MODE_BUTTON_COUNT; i++) {
|
||||||
@@ -122,6 +124,8 @@ void ColorPicker::_update_theme_item_cache() {
|
|||||||
theme_cache.sv_height = get_theme_constant(SNAME("sv_height"));
|
theme_cache.sv_height = get_theme_constant(SNAME("sv_height"));
|
||||||
theme_cache.h_width = get_theme_constant(SNAME("h_width"));
|
theme_cache.h_width = get_theme_constant(SNAME("h_width"));
|
||||||
|
|
||||||
|
theme_cache.center_slider_grabbers = get_theme_constant(SNAME("center_slider_grabbers"));
|
||||||
|
|
||||||
theme_cache.screen_picker = get_theme_icon(SNAME("screen_picker"));
|
theme_cache.screen_picker = get_theme_icon(SNAME("screen_picker"));
|
||||||
theme_cache.expanded_arrow = get_theme_icon(SNAME("expanded_arrow"));
|
theme_cache.expanded_arrow = get_theme_icon(SNAME("expanded_arrow"));
|
||||||
theme_cache.folded_arrow = get_theme_icon(SNAME("folded_arrow"));
|
theme_cache.folded_arrow = get_theme_icon(SNAME("folded_arrow"));
|
||||||
|
|||||||
@@ -213,6 +213,8 @@ private:
|
|||||||
int sv_width = 0;
|
int sv_width = 0;
|
||||||
int h_width = 0;
|
int h_width = 0;
|
||||||
|
|
||||||
|
bool center_slider_grabbers = true;
|
||||||
|
|
||||||
Ref<Texture2D> screen_picker;
|
Ref<Texture2D> screen_picker;
|
||||||
Ref<Texture2D> expanded_arrow;
|
Ref<Texture2D> expanded_arrow;
|
||||||
Ref<Texture2D> folded_arrow;
|
Ref<Texture2D> folded_arrow;
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ void Slider::gui_input(const Ref<InputEvent> &p_event) {
|
|||||||
|
|
||||||
grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x;
|
grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x;
|
||||||
|
|
||||||
double grab_width = (double)grabber->get_size().width;
|
double grab_width = (double)grabber->get_width();
|
||||||
double grab_height = (double)grabber->get_size().height;
|
double grab_height = (double)grabber->get_height();
|
||||||
double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
|
double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
|
||||||
if (orientation == VERTICAL) {
|
if (orientation == VERTICAL) {
|
||||||
set_as_ratio(1 - (((double)grab.pos - (grab_height / 2.0)) / max));
|
set_as_ratio(1 - (((double)grab.pos - (grab_height / 2.0)) / max));
|
||||||
@@ -103,7 +103,7 @@ void Slider::gui_input(const Ref<InputEvent> &p_event) {
|
|||||||
if (orientation == VERTICAL) {
|
if (orientation == VERTICAL) {
|
||||||
motion = -motion;
|
motion = -motion;
|
||||||
}
|
}
|
||||||
double areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width;
|
double areasize = orientation == VERTICAL ? size.height - grabber->get_height() : size.width - grabber->get_width();
|
||||||
if (areasize <= 0) {
|
if (areasize <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -159,6 +159,9 @@ void Slider::_update_theme_item_cache() {
|
|||||||
theme_cache.grabber_hl_icon = get_theme_icon(SNAME("grabber_highlight"));
|
theme_cache.grabber_hl_icon = get_theme_icon(SNAME("grabber_highlight"));
|
||||||
theme_cache.grabber_disabled_icon = get_theme_icon(SNAME("grabber_disabled"));
|
theme_cache.grabber_disabled_icon = get_theme_icon(SNAME("grabber_disabled"));
|
||||||
theme_cache.tick_icon = get_theme_icon(SNAME("tick"));
|
theme_cache.tick_icon = get_theme_icon(SNAME("tick"));
|
||||||
|
|
||||||
|
theme_cache.center_grabber = get_theme_constant(SNAME("center_grabber"));
|
||||||
|
theme_cache.grabber_offset = get_theme_constant(SNAME("grabber_offset"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slider::_notification(int p_what) {
|
void Slider::_notification(int p_what) {
|
||||||
@@ -213,39 +216,41 @@ void Slider::_notification(int p_what) {
|
|||||||
|
|
||||||
if (orientation == VERTICAL) {
|
if (orientation == VERTICAL) {
|
||||||
int widget_width = style->get_minimum_size().width;
|
int widget_width = style->get_minimum_size().width;
|
||||||
double areasize = size.height - grabber->get_size().height;
|
double areasize = size.height - (theme_cache.center_grabber ? 0 : grabber->get_height());
|
||||||
|
int grabber_shift = theme_cache.center_grabber ? grabber->get_height() / 2 : 0;
|
||||||
style->draw(ci, Rect2i(Point2i(size.width / 2 - widget_width / 2, 0), Size2i(widget_width, size.height)));
|
style->draw(ci, Rect2i(Point2i(size.width / 2 - widget_width / 2, 0), Size2i(widget_width, size.height)));
|
||||||
grabber_area->draw(ci, Rect2i(Point2i((size.width - widget_width) / 2, size.height - areasize * ratio - grabber->get_size().height / 2), Size2i(widget_width, areasize * ratio + grabber->get_size().height / 2)));
|
grabber_area->draw(ci, Rect2i(Point2i((size.width - widget_width) / 2, size.height - areasize * ratio - grabber->get_height() / 2 + grabber_shift), Size2i(widget_width, areasize * ratio + grabber->get_height() / 2 - grabber_shift)));
|
||||||
|
|
||||||
if (ticks > 1) {
|
if (ticks > 1) {
|
||||||
int grabber_offset = (grabber->get_size().height / 2 - tick->get_height() / 2);
|
int grabber_offset = (grabber->get_height() / 2 - tick->get_height() / 2);
|
||||||
for (int i = 0; i < ticks; i++) {
|
for (int i = 0; i < ticks; i++) {
|
||||||
if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) {
|
if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
|
int ofs = (i * areasize / (ticks - 1)) + grabber_offset - grabber_shift;
|
||||||
tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs));
|
tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
grabber->draw(ci, Point2i(size.width / 2 - grabber->get_size().width / 2 + get_theme_constant(SNAME("grabber_offset")), size.height - ratio * areasize - grabber->get_size().height));
|
grabber->draw(ci, Point2i(size.width / 2 - grabber->get_width() / 2 + theme_cache.grabber_offset, size.height - ratio * areasize - grabber->get_height() + grabber_shift));
|
||||||
} else {
|
} else {
|
||||||
int widget_height = style->get_minimum_size().height;
|
int widget_height = style->get_minimum_size().height;
|
||||||
double areasize = size.width - grabber->get_size().width;
|
double areasize = size.width - (theme_cache.center_grabber ? 0 : grabber->get_size().width);
|
||||||
|
int grabber_shift = theme_cache.center_grabber ? -grabber->get_width() / 2 : 0;
|
||||||
|
|
||||||
style->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(size.width, widget_height)));
|
style->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(size.width, widget_height)));
|
||||||
grabber_area->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(areasize * ratio + grabber->get_size().width / 2, widget_height)));
|
grabber_area->draw(ci, Rect2i(Point2i(0, (size.height - widget_height) / 2), Size2i(areasize * ratio + grabber->get_width() / 2 + grabber_shift, widget_height)));
|
||||||
|
|
||||||
if (ticks > 1) {
|
if (ticks > 1) {
|
||||||
int grabber_offset = (grabber->get_size().width / 2 - tick->get_width() / 2);
|
int grabber_offset = (grabber->get_width() / 2 - tick->get_width() / 2);
|
||||||
for (int i = 0; i < ticks; i++) {
|
for (int i = 0; i < ticks; i++) {
|
||||||
if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) {
|
if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
|
int ofs = (i * areasize / (ticks - 1)) + grabber_offset + grabber_shift;
|
||||||
tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2));
|
tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
grabber->draw(ci, Point2i(ratio * areasize, size.height / 2 - grabber->get_size().height / 2 + get_theme_constant(SNAME("grabber_offset"))));
|
grabber->draw(ci, Point2i(ratio * areasize + grabber_shift, size.height / 2 - grabber->get_height() / 2 + theme_cache.grabber_offset));
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ class Slider : public Range {
|
|||||||
Ref<Texture2D> grabber_hl_icon;
|
Ref<Texture2D> grabber_hl_icon;
|
||||||
Ref<Texture2D> grabber_disabled_icon;
|
Ref<Texture2D> grabber_disabled_icon;
|
||||||
Ref<Texture2D> tick_icon;
|
Ref<Texture2D> tick_icon;
|
||||||
|
|
||||||
|
bool center_grabber = false;
|
||||||
|
int grabber_offset = 0;
|
||||||
} theme_cache;
|
} theme_cache;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -565,6 +565,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
|||||||
theme->set_icon("grabber_disabled", "HSlider", icons["slider_grabber_disabled"]);
|
theme->set_icon("grabber_disabled", "HSlider", icons["slider_grabber_disabled"]);
|
||||||
theme->set_icon("tick", "HSlider", icons["hslider_tick"]);
|
theme->set_icon("tick", "HSlider", icons["hslider_tick"]);
|
||||||
|
|
||||||
|
theme->set_constant("center_grabber", "HSlider", 0);
|
||||||
theme->set_constant("grabber_offset", "HSlider", 0);
|
theme->set_constant("grabber_offset", "HSlider", 0);
|
||||||
|
|
||||||
// VSlider
|
// VSlider
|
||||||
@@ -578,6 +579,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
|||||||
theme->set_icon("grabber_disabled", "VSlider", icons["slider_grabber_disabled"]);
|
theme->set_icon("grabber_disabled", "VSlider", icons["slider_grabber_disabled"]);
|
||||||
theme->set_icon("tick", "VSlider", icons["vslider_tick"]);
|
theme->set_icon("tick", "VSlider", icons["vslider_tick"]);
|
||||||
|
|
||||||
|
theme->set_constant("center_grabber", "VSlider", 0);
|
||||||
theme->set_constant("grabber_offset", "VSlider", 0);
|
theme->set_constant("grabber_offset", "VSlider", 0);
|
||||||
|
|
||||||
// SpinBox
|
// SpinBox
|
||||||
@@ -909,6 +911,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
|||||||
theme->set_constant("sv_height", "ColorPicker", 256 * scale);
|
theme->set_constant("sv_height", "ColorPicker", 256 * scale);
|
||||||
theme->set_constant("h_width", "ColorPicker", 30 * scale);
|
theme->set_constant("h_width", "ColorPicker", 30 * scale);
|
||||||
theme->set_constant("label_width", "ColorPicker", 10 * scale);
|
theme->set_constant("label_width", "ColorPicker", 10 * scale);
|
||||||
|
theme->set_constant("center_slider_grabbers", "ColorPicker", 1);
|
||||||
|
|
||||||
theme->set_icon("folded_arrow", "ColorPicker", icons["arrow_right"]);
|
theme->set_icon("folded_arrow", "ColorPicker", icons["arrow_right"]);
|
||||||
theme->set_icon("expanded_arrow", "ColorPicker", icons["arrow_down"]);
|
theme->set_icon("expanded_arrow", "ColorPicker", icons["arrow_down"]);
|
||||||
|
|||||||
Reference in New Issue
Block a user