Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioStream preview filenames use different color and size from the rest of the inspector #75670

Open
Tracked by #76797
GregX999 opened this issue Apr 5, 2023 · 4 comments

Comments

@GregX999
Copy link

GregX999 commented Apr 5, 2023

Godot version

4.0.2

System information

Windows 11

Issue description

I changed the "Main Font" and "Main Font Bold" in the Editor Settings.
I have a script that's @exporting an Audio Stream, and an array of AudioStreams.
When I drag files into the Inspector to populate those @exports, the filenames aren't using the font settings I assigned.

wrong_font

Steps to reproduce

  1. Change the Main Font and Main Font Bold in Editor Preferences.
  2. Create a scene, and attach a script that @exports an AudioStream.
  3. Drag an audio file into the Inspector to populate that @export var.

Minimal reproduction project

(You'll have to change your Fonts in Editor Settings to see the issue.)
wrong_fonts.zip

  • EDIT: Changed version to 4.0.2
@YuriSizov
Copy link
Contributor

It looks like the same font to me, but at a different size. I don't see any immediate issue in the code, but it does use a Label font and font size, which indirectly should still go to the main font and main font size from the settings.

What do you expect it to look like?

@GregX999
Copy link
Author

GregX999 commented Apr 5, 2023

I'd expect it to look just like the other text that's used everywhere else (in the screenshot, the smaller, thinner text). Being so large/bold is not only jarring, but you can't see as much of the filename either. It "looks like" a bug - like someone forgot to make the label follow the style guidelines or something.

@Calinou
Copy link
Member

Calinou commented Apr 5, 2023

The file name uses a different font size and color, which is unexpected. It is indeed an intentional override. This is with the default font and default font size settings:

image

The overrides are performed here and were added by #63265:

void EditorAudioStreamPicker::_update_resource() {
EditorResourcePicker::_update_resource();
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
Ref<AudioStream> audio_stream = get_edited_resource();
if (audio_stream.is_valid() && audio_stream->get_length() > 0.0) {
set_assign_button_min_size(Size2(1, font->get_height(font_size) * 3));
} else {
set_assign_button_min_size(Size2(1, font->get_height(font_size) * 1.5));
}
stream_preview_rect->queue_redraw();
}
void EditorAudioStreamPicker::_preview_draw() {
Ref<AudioStream> audio_stream = get_edited_resource();
if (!audio_stream.is_valid()) {
get_assign_button()->set_text(TTR("<empty>"));
return;
}
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
get_assign_button()->set_text("");
Size2i size = stream_preview_rect->get_size();
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
Rect2 rect(Point2(), size);
if (audio_stream->get_length() > 0) {
rect.size.height *= 0.5;
stream_preview_rect->draw_rect(rect, Color(0, 0, 0, 1));
Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(audio_stream);
float preview_len = preview->get_length();
Vector<Vector2> lines;
lines.resize(size.width * 2);
for (int i = 0; i < size.width; i++) {
float ofs = i * preview_len / size.width;
float ofs_n = (i + 1) * preview_len / size.width;
float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5;
float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5;
int idx = i;
lines.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y);
lines.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y);
}
Vector<Color> color;
color.push_back(get_theme_color(SNAME("contrast_color_2"), SNAME("Editor")));
RS::get_singleton()->canvas_item_add_multiline(stream_preview_rect->get_canvas_item(), lines, color);
if (tagged_frame_offset_count) {
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
for (uint32_t i = 0; i < tagged_frame_offset_count; i++) {
int x = CLAMP(tagged_frame_offsets[i] * size.width / preview_len, 0, size.width);
if (x == 0) {
continue; // Because some may always return 0, ignore offset 0.
}
stream_preview_rect->draw_rect(Rect2i(x, 0, 2, rect.size.height), accent);
}
}
rect.position.y += rect.size.height;
}
Ref<Texture2D> icon;
Color icon_modulate(1, 1, 1, 1);
if (tagged_frame_offset_count > 0) {
icon = get_theme_icon(SNAME("Play"), SNAME("EditorIcons"));
if ((OS::get_singleton()->get_ticks_msec() % 500) > 250) {
icon_modulate = Color(1, 0.5, 0.5, 1); // get_theme_color(SNAME("accent_color"), SNAME("Editor"));
}
} else {
icon = EditorNode::get_singleton()->get_object_icon(audio_stream.operator->(), "Object");
}
String text;
if (!audio_stream->get_name().is_empty()) {
text = audio_stream->get_name();
} else if (audio_stream->get_path().is_resource_file()) {
text = audio_stream->get_path().get_file();
} else {
text = audio_stream->get_class().replace_first("AudioStream", "");
}
stream_preview_rect->draw_texture(icon, Point2i(EDSCALE * 2, rect.position.y + (rect.size.height - icon->get_height()) / 2), icon_modulate);
stream_preview_rect->draw_string(font, Point2i(EDSCALE * 2 + icon->get_width(), rect.position.y + font->get_ascent(font_size) + (rect.size.height - font->get_height(font_size)) / 2), text, HORIZONTAL_ALIGNMENT_CENTER, size.width - 4 * EDSCALE - icon->get_width());
}

Feel free to play around with them if you can make them look better 🙂

@Calinou Calinou changed the title Wrong font used for filenames in Inspector AudioStream preview filenames use different color and size from the rest of the inspector Apr 5, 2023
@YuriSizov
Copy link
Contributor

The file name uses a different font size and color, which is unexpected.

As I mentioned, while it refers to the label properties, those fall back onto the main font and the main font size values. Label doesn't have a font size defined in the editor theme, and it uses the configured main font as its font.

It is possible, that due to the font size missing in the label definition that instead of falling back onto the main font size it falls back onto the default theme font size. This needs to be tested. I don't think that the override was deliberate necessarily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants