Add set_default_margin_all/individual to StyleBox

This commit is contained in:
FireForge
2022-03-11 22:38:44 -06:00
committed by Yuri Sizov
parent 019253512d
commit dd7ee37c8a
9 changed files with 98 additions and 94 deletions
@@ -51,10 +51,7 @@ static const int default_corner_radius = 3;
static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = default_margin, float p_margin_top = default_margin, float p_margin_right = default_margin, float p_margin_bottom = default_margin, int p_corner_radius = default_corner_radius, bool p_draw_center = true, int p_border_width = 0) {
Ref<StyleBoxFlat> style(memnew(StyleBoxFlat));
style->set_bg_color(p_color);
style->set_default_margin(SIDE_LEFT, p_margin_left * scale);
style->set_default_margin(SIDE_RIGHT, p_margin_right * scale);
style->set_default_margin(SIDE_BOTTOM, p_margin_bottom * scale);
style->set_default_margin(SIDE_TOP, p_margin_top * scale);
style->set_default_margin_individual(p_margin_left * scale, p_margin_top * scale, p_margin_right * scale, p_margin_bottom * scale);
style->set_corner_radius_all(p_corner_radius);
style->set_anti_aliased(true);
@@ -93,12 +90,7 @@ static Ref<ImageTexture> generate_icon(int p_index) {
static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
Ref<StyleBox> style(memnew(StyleBoxEmpty));
style->set_default_margin(SIDE_LEFT, p_margin_left * scale);
style->set_default_margin(SIDE_RIGHT, p_margin_right * scale);
style->set_default_margin(SIDE_BOTTOM, p_margin_bottom * scale);
style->set_default_margin(SIDE_TOP, p_margin_top * scale);
style->set_default_margin_individual(p_margin_left * scale, p_margin_top * scale, p_margin_right * scale, p_margin_bottom * scale);
return style;
}
@@ -279,15 +271,9 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
// CheckBox
Ref<StyleBox> cbx_empty = memnew(StyleBoxEmpty);
cbx_empty->set_default_margin(SIDE_LEFT, 4 * scale);
cbx_empty->set_default_margin(SIDE_RIGHT, 4 * scale);
cbx_empty->set_default_margin(SIDE_TOP, 4 * scale);
cbx_empty->set_default_margin(SIDE_BOTTOM, 4 * scale);
cbx_empty->set_default_margin_all(4 * scale);
Ref<StyleBox> cbx_focus = focus;
cbx_focus->set_default_margin(SIDE_LEFT, 4 * scale);
cbx_focus->set_default_margin(SIDE_RIGHT, 4 * scale);
cbx_focus->set_default_margin(SIDE_TOP, 4 * scale);
cbx_focus->set_default_margin(SIDE_BOTTOM, 4 * scale);
cbx_focus->set_default_margin_all(4 * scale);
theme->set_stylebox("normal", "CheckBox", cbx_empty);
theme->set_stylebox("pressed", "CheckBox", cbx_empty);
@@ -323,10 +309,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
// CheckButton
Ref<StyleBox> cb_empty = memnew(StyleBoxEmpty);
cb_empty->set_default_margin(SIDE_LEFT, 6 * scale);
cb_empty->set_default_margin(SIDE_RIGHT, 6 * scale);
cb_empty->set_default_margin(SIDE_TOP, 4 * scale);
cb_empty->set_default_margin(SIDE_BOTTOM, 4 * scale);
cb_empty->set_default_margin_individual(6 * scale, 4 * scale, 6 * scale, 4 * scale);
theme->set_stylebox("normal", "CheckButton", cb_empty);
theme->set_stylebox("pressed", "CheckButton", cb_empty);
@@ -638,16 +621,10 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
Ref<StyleBoxLine> separator_horizontal = memnew(StyleBoxLine);
separator_horizontal->set_thickness(Math::round(scale));
separator_horizontal->set_color(style_separator_color);
separator_horizontal->set_default_margin(SIDE_LEFT, default_margin);
separator_horizontal->set_default_margin(SIDE_TOP, 0);
separator_horizontal->set_default_margin(SIDE_RIGHT, default_margin);
separator_horizontal->set_default_margin(SIDE_BOTTOM, 0);
separator_horizontal->set_default_margin_individual(default_margin, 0, default_margin, 0);
Ref<StyleBoxLine> separator_vertical = separator_horizontal->duplicate();
separator_vertical->set_vertical(true);
separator_vertical->set_default_margin(SIDE_LEFT, 0);
separator_vertical->set_default_margin(SIDE_TOP, default_margin);
separator_vertical->set_default_margin(SIDE_RIGHT, 0);
separator_vertical->set_default_margin(SIDE_BOTTOM, default_margin);
separator_vertical->set_default_margin_individual(0, default_margin, 0, default_margin);
// Always display a border for PopupMenus so they can be distinguished from their background.
Ref<StyleBoxFlat> style_popup_panel = make_flat_stylebox(style_popup_color);