How do I make a label text BOLD with code??
Asked Answered
P

2

0

Godot Version
4.2.1

Question
simple question. I created a label with code and want to keep everything the same… but make the font bold.
I tried playing with font in the theme but cant find option to make font bold.
I tried creating a new system font and setting weight to 700 (bold) but still nothing…
I dont want to upload a custom font file or make major changes. I want to use the same default font as usual… just make it a bit bolder!

here is my come so far…

'''
var labelStyle = StyleBoxFlat.new();
labelStyle.bg_color = Color(0.25, 0.26, 0.30, 1.0);
labelStyle.set_content_margin_all( 4.0 );

var label = Label.new()
label.text = "some text"
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER

label.add_theme_stylebox_override("normal",labelStyle);
var font = SystemFont.new();
font.font_weight = 700;
label.add_theme_font_override("font", font);
'''

Plotter answered 21/3 at 4:49 Comment(0)
M
0

Labels can't have decorations. You can select the Label and change type to rich text label. The inherited property values should remain the same. But alignment will be lost because RTLs set alignment from text code.
Edit: I should've read more carefuly. You could set up a fontVariation with embolden, or swap the font for a Bold version (when downloading fonts they tend to come with normal, bold, italic, etc versions of the font in different files).

Another alternative is to (in the theme) set the label->outline_size to a value greater than 0.

Miculek answered 21/3 at 10:46 Comment(0)
J
0

Yep, like Retha commented; in this project, there's a font variation and the code changes the Embolden value:

Alternatives are to actually use the bold font variation if there is one and/or create a theme variation.

Jessalin answered 21/3 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.