diff --git a/editor/src/asset/creator.rs b/editor/src/asset/creator.rs index d9c60670d..6c740db80 100644 --- a/editor/src/asset/creator.rs +++ b/editor/src/asset/creator.rs @@ -32,6 +32,7 @@ use crate::{ list_view::{ListViewBuilder, ListViewMessage}, message::UiMessage, stack_panel::StackPanelBuilder, + style::resource::StyleResourceExt, text::TextMessage, text_box::TextBoxBuilder, utils::make_dropdown_list_option, @@ -41,7 +42,7 @@ use crate::{ }, }, message::MessageSender, - Message, + Editor, Message, }; use fyrox::gui::button::Button; use fyrox::gui::list_view::ListView; @@ -73,6 +74,8 @@ impl ResourceCreator { items.push(make_dropdown_list_option( ctx, make_pretty_type_name(&constructor.type_name), + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), )) } } @@ -83,7 +86,11 @@ impl ResourceCreator { let cancel; let resource_constructors_list; let window = WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) - .with_title(WindowTitle::text("Resource Creator")) + .with_title(WindowTitle::text_with_font_size( + "Resource Creator", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .open(false) .with_content( GridBuilder::new( @@ -97,6 +104,7 @@ impl ResourceCreator { .with_margin(Thickness::uniform(1.0)), ) .with_text(&name_str) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); name }) @@ -121,7 +129,11 @@ impl ResourceCreator { .with_width(100.0) .with_height(22.0), ) - .with_text("OK") + .with_text_and_font_size( + "OK", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); ok }) @@ -132,7 +144,11 @@ impl ResourceCreator { .with_width(100.0) .with_height(22.0), ) - .with_text("Cancel") + .with_text_and_font_size( + "Cancel", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); cancel }), diff --git a/editor/src/asset/dependency.rs b/editor/src/asset/dependency.rs index e1d4d524c..e5822f910 100644 --- a/editor/src/asset/dependency.rs +++ b/editor/src/asset/dependency.rs @@ -18,31 +18,34 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -use crate::fyrox::{ - asset::{ - graph::{ResourceDependencyGraph, ResourceGraphNode}, - untyped::UntypedResource, - }, - core::{log::Log, pool::Handle}, - gui::{ - button::{ButtonBuilder, ButtonMessage}, - copypasta::ClipboardProvider, - grid::{Column, GridBuilder, Row}, - message::UiMessage, - scroll_viewer::ScrollViewerBuilder, - stack_panel::StackPanelBuilder, - text::TextBuilder, - tree::{TreeBuilder, TreeRootBuilder, TreeRootMessage}, - widget::WidgetBuilder, - window::{WindowBuilder, WindowMessage, WindowTitle}, - BuildContext, HorizontalAlignment, Orientation, Thickness, UserInterface, - VerticalAlignment, +use crate::{ + fyrox::{ + asset::{ + graph::{ResourceDependencyGraph, ResourceGraphNode}, + untyped::UntypedResource, + }, + core::{log::Log, pool::Handle}, + gui::{ + button::{ButtonBuilder, ButtonMessage}, + copypasta::ClipboardProvider, + grid::{Column, GridBuilder, Row}, + message::UiMessage, + scroll_viewer::ScrollViewerBuilder, + stack_panel::StackPanelBuilder, + text::TextBuilder, + tree::{TreeBuilder, TreeRootBuilder, TreeRootMessage}, + widget::WidgetBuilder, + window::{WindowBuilder, WindowMessage, WindowTitle}, + BuildContext, HorizontalAlignment, Orientation, Thickness, UserInterface, + VerticalAlignment, + }, }, + Editor, }; -use fyrox::asset::manager::ResourceManager; use fyrox::gui::button::Button; use fyrox::gui::tree::{Tree, TreeRoot}; use fyrox::gui::window::{Window, WindowAlignment}; +use fyrox::{asset::manager::ResourceManager, gui::style::resource::StyleResourceExt}; pub struct DependencyViewer { pub window: Handle, @@ -77,6 +80,7 @@ fn build_tree_recursively( WidgetBuilder::new().with_vertical_alignment(VerticalAlignment::Center), ) .with_text(format!("{name} ({data_type})")) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .build(ctx) @@ -89,7 +93,11 @@ impl DependencyViewer { let close; let window = WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) .open(false) - .with_title(WindowTitle::text("Dependency Viewer")) + .with_title(WindowTitle::text_with_font_size( + "Dependency Viewer", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_content( GridBuilder::new( WidgetBuilder::new() @@ -116,7 +124,11 @@ impl DependencyViewer { .with_width(130.0) .with_margin(Thickness::uniform(1.0)), ) - .with_text("Copy To Clipboard") + .with_text_and_font_size( + "Copy To Clipboard", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); copy_to_clipboard }) @@ -126,7 +138,11 @@ impl DependencyViewer { .with_width(130.0) .with_margin(Thickness::uniform(1.0)), ) - .with_text("Close") + .with_text_and_font_size( + "Close", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); close }), diff --git a/editor/src/asset/item.rs b/editor/src/asset/item.rs index 3566eb9ef..5bca42899 100644 --- a/editor/src/asset/item.rs +++ b/editor/src/asset/item.rs @@ -49,7 +49,7 @@ use crate::{ scene::tilemap::{brush::TileMapBrush, tileset::TileSet}, }, message::MessageSender, - Message, + Editor, Message, }; use fyrox::core::ok_or_return; use fyrox::gui::border::Border; @@ -357,6 +357,7 @@ fn make_tooltip(ctx: &mut BuildContext, text: &str) -> RcUiNodeHandle { ) .with_wrap(WrapMode::Letter) .with_text(text) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ), ) @@ -421,6 +422,7 @@ impl AssetItemBuilder { .to_string(), ) .with_shadow(true) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ), ) diff --git a/editor/src/asset/menu.rs b/editor/src/asset/menu.rs index f02cfb562..325eb0be7 100644 --- a/editor/src/asset/menu.rs +++ b/editor/src/asset/menu.rs @@ -23,9 +23,14 @@ use crate::{ fyrox::{ asset::manager::ResourceManager, core::{ - futures::executor::block_on, log::Log, ok_or_return, pool::Handle, - pool::HandlesVecExtension, reflect::prelude::*, type_traits::prelude::*, - visitor::prelude::*, SafeLock, + futures::executor::block_on, + log::Log, + ok_or_return, + pool::{Handle, HandlesVecExtension}, + reflect::prelude::*, + type_traits::prelude::*, + visitor::prelude::*, + SafeLock, }, engine::Engine, graph::SceneGraph, @@ -44,6 +49,7 @@ use crate::{ }, popup::{Placement, PopupBuilder, PopupMessage}, stack_panel::StackPanelBuilder, + style::resource::StyleResourceExt, text::{TextBuilder, TextMessage}, text_box::{TextBox, TextBoxBuilder, TextCommitMode}, widget::{Widget, WidgetBuilder, WidgetMessage}, @@ -53,7 +59,7 @@ use crate::{ }, }, message::MessageSender, - Message, + Editor, Message, }; use std::{ fs::File, @@ -163,6 +169,7 @@ impl AssetRenameDialogBuilder { "Enter a new name for {old_file_name}.{extension} resource." )) .with_wrap(WrapMode::Word) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child({ @@ -174,6 +181,7 @@ impl AssetRenameDialogBuilder { ) .with_text(&old_file_name) .with_text_commit_mode(TextCommitMode::Immediate) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); name_field }) @@ -190,7 +198,11 @@ impl AssetRenameDialogBuilder { .with_height(24.0) .with_tab_index(Some(1)), ) - .with_text("Rename") + .with_text_and_font_size( + "Rename", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); rename }) @@ -202,7 +214,11 @@ impl AssetRenameDialogBuilder { .with_height(24.0) .with_tab_index(Some(2)), ) - .with_text("Cancel") + .with_text_and_font_size( + "Cancel", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); cancel }), @@ -256,6 +272,7 @@ impl AssetItemContextMenu { fn item(text: &str, ctx: &mut BuildContext) -> Handle { MenuItemBuilder::new(WidgetBuilder::new()) .with_content(MenuItemContent::text(text)) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx) } @@ -365,9 +382,15 @@ impl AssetItemContextMenu { ) .open(false) .with_remove_on_close(true) - .with_title(WindowTitle::text("Confirm Deletion")), + .with_title(WindowTitle::text_with_font_size( + "Confirm Deletion", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )), ) .with_text(&text) + .with_font(ui.default_font.clone()) + .with_font_size(ui.style.property(Editor::UI_FONT_SIZE)) .with_buttons(MessageBoxButtons::YesNo) .build(&mut ui.build_ctx()); @@ -494,19 +517,29 @@ impl AssetItemContextMenu { item.path.extension(), item.path.parent(), ) { + let (old_file_name, extension_name, folder_name, old_path) = ( + file_stem.to_string_lossy().to_string(), + extension.to_string_lossy().to_string(), + parent.to_string_lossy().to_string(), + item.path.clone(), + ); let dialog = AssetRenameDialogBuilder::new( WindowBuilder::new( WidgetBuilder::new().with_width(350.0).with_height(100.0), ) - .with_title(WindowTitle::text("Rename a Resource")) + .with_title(WindowTitle::text_with_font_size( + "Rename a Resource", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .with_remove_on_close(true) .open(false), ) .build( - file_stem.to_string_lossy().to_string(), - extension.to_string_lossy().to_string(), - parent.to_string_lossy().to_string(), - item.path.clone(), + old_file_name, + extension_name, + folder_name, + old_path, engine.resource_manager.clone(), &mut ui.build_ctx(), ); diff --git a/editor/src/asset/mod.rs b/editor/src/asset/mod.rs index c8e73851d..89f7d3680 100644 --- a/editor/src/asset/mod.rs +++ b/editor/src/asset/mod.rs @@ -63,8 +63,9 @@ use crate::{ preview::PreviewPanel, scene::{commands::ChangeSelectionCommand, container::EditorSceneEntry, Selection}, utils::window_content, - Message, Mode, + Editor, Message, Mode, }; +use fyrox::gui::style::resource::StyleResourceExt; use menu::AssetItemContextMenu; use notify::{EventKind, RecommendedWatcher, RecursiveMode, Watcher}; use std::{ @@ -311,7 +312,11 @@ impl AssetBrowser { let folder_browser; let scroll_panel; let folder_browser_window = WindowBuilder::new(WidgetBuilder::new()) - .with_title(WindowTitle::text("Folders")) + .with_title(WindowTitle::text_with_font_size( + "Folders", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("Folders") .can_close(false) .can_minimize(false) @@ -323,13 +328,19 @@ impl AssetBrowser { .with_no_items_text("There are no subfolders. Right-click to add one.") .with_show_path(false) .with_filter(PathFilter::folder()) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); folder_browser }) .build(ctx); let main_window = WindowBuilder::new(WidgetBuilder::new()) - .with_title(WindowTitle::text("Folder Content")) + .with_title(WindowTitle::text_with_font_size( + "Folder Content", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("Content") .can_close(false) .can_minimize(false) @@ -382,7 +393,11 @@ impl AssetBrowser { .build(ctx); let window = WindowBuilder::new(WidgetBuilder::new().with_name("AssetBrowser")) - .with_title(WindowTitle::text("Asset Browser")) + .with_title(WindowTitle::text_with_font_size( + "Asset Browser", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("Asset Browser") .with_content(docking_manager) .build(ctx); @@ -516,10 +531,11 @@ impl AssetBrowser { self.current_path = path.to_path_buf(); ui.send( self.main_window, - WindowMessage::Title(WindowTitle::text(format!( - "Folder Content - {}", - self.current_path.display() - ))), + WindowMessage::Title(WindowTitle::text_with_font_size( + format!("Folder Content - {}", self.current_path.display()), + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )), ); ui.send( self.add_resource, @@ -992,7 +1008,11 @@ impl AssetBrowser { .with_width(100.0) .with_margin(Thickness::uniform(1.0)), ) - .with_text("Apply") + .with_text_and_font_size( + "Apply", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); apply }) @@ -1002,7 +1022,11 @@ impl AssetBrowser { .with_width(100.0) .with_margin(Thickness::uniform(1.0)), ) - .with_text("Revert") + .with_text_and_font_size( + "Revert", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); revert }), diff --git a/editor/src/asset/selector.rs b/editor/src/asset/selector.rs index 338186f6d..dd61b2f14 100644 --- a/editor/src/asset/selector.rs +++ b/editor/src/asset/selector.rs @@ -61,6 +61,7 @@ use crate::{ UserInterface, VerticalAlignment, }, }, + Editor, }; use fyrox::gui::style::resource::StyleResourceExt; use fyrox::gui::style::Style; @@ -197,6 +198,7 @@ impl ItemBuilder { .map(|file_name| file_name.to_string_lossy().to_string()) .unwrap_or_default(), ) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ), ) @@ -509,7 +511,11 @@ impl<'a> AssetSelectorWindowBuilder<'a> { .with_margin(Thickness::uniform(1.0)) .with_tab_index(Some(2)), ) - .with_text("Select") + .with_text_and_font_size( + "Select", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); ok }) @@ -521,7 +527,11 @@ impl<'a> AssetSelectorWindowBuilder<'a> { .with_margin(Thickness::uniform(1.0)) .with_tab_index(Some(3)), ) - .with_text("Cancel") + .with_text_and_font_size( + "Cancel", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); cancel }), @@ -559,9 +569,14 @@ impl<'a> AssetSelectorWindowBuilder<'a> { resource_manager: ResourceManager, ui: &mut UserInterface, ) -> Handle { + let ctx = ui.build_ctx(); let selector = AssetSelectorWindowBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) - .with_title(WindowTitle::text("Select a Resource")) + .with_title(WindowTitle::text_with_font_size( + "Select a Resource", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_remove_on_close(true) .open(false), ) diff --git a/editor/src/audio/bus.rs b/editor/src/audio/bus.rs index 7a43c8827..b042a58c0 100644 --- a/editor/src/audio/bus.rs +++ b/editor/src/audio/bus.rs @@ -36,6 +36,7 @@ use crate::fyrox::{ }, scene::sound::{AudioBus, AudioBusGraph}, }; +use crate::Editor; use fyrox::gui::dropdown_list::DropdownList; use fyrox::gui::list_view::ListView; use fyrox::gui::message::MessageData; @@ -107,7 +108,14 @@ impl Control for AudioBusView { fn make_items(buses: &[(Handle, String)], ctx: &mut BuildContext) -> Vec> { buses .iter() - .map(|(_, name)| make_dropdown_list_option(ctx, name)) + .map(|(_, name)| { + make_dropdown_list_option( + ctx, + name, + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) + }) .collect::>() } @@ -118,6 +126,8 @@ fn make_effect_names(names: &[String], ctx: &mut BuildContext) -> Vec Vec>(), ) .build(ctx); @@ -280,6 +289,7 @@ impl AudioPanel { ) .with_vertical_text_alignment(VerticalAlignment::Center) .with_text("Renderer") + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child({ @@ -293,23 +303,33 @@ impl AudioPanel { .with_items( Renderer::VARIANTS .iter() - .map(|v| make_dropdown_list_option(ctx, v)) + .map(|v| { + make_dropdown_list_option( + ctx, + v, + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) + }) .collect::>(), ) .build(ctx); renderer }) .with_child({ - hrir_resource = - ResourceFieldBuilder::::new( - WidgetBuilder::new().with_tab_index(Some(2)), - sender, - ) - .build( - ctx, - icon_request_sender, - engine.resource_manager.clone(), - ); + hrir_resource = ResourceFieldBuilder::< + HrirSphereResourceData, + >::new( + WidgetBuilder::new().with_tab_index(Some(2)), + sender, + ) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) + .build( + ctx, + icon_request_sender, + engine.resource_manager.clone(), + ); hrir_resource }), ) @@ -339,7 +359,11 @@ impl AudioPanel { .with_width(100.0) .with_margin(Thickness::uniform(1.0)), ) - .with_text("Add Bus") + .with_text_and_font_size( + "Add Bus", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); add_bus }) @@ -351,7 +375,11 @@ impl AudioPanel { .with_enabled(false) .with_margin(Thickness::uniform(1.0)), ) - .with_text("Remove Bus") + .with_text_and_font_size( + "Remove Bus", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); remove_bus }), @@ -366,7 +394,11 @@ impl AudioPanel { .add_row(Row::strict(25.0)) .build(ctx), ) - .with_title(WindowTitle::text("Audio Context")) + .with_title(WindowTitle::text_with_font_size( + "Audio Context", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("Audio") .build(ctx); diff --git a/editor/src/audio/preview.rs b/editor/src/audio/preview.rs index 5857fa57a..981b27b8b 100644 --- a/editor/src/audio/preview.rs +++ b/editor/src/audio/preview.rs @@ -30,6 +30,7 @@ use crate::{ message::UiMessage, scroll_bar::{ScrollBar, ScrollBarBuilder, ScrollBarMessage}, stack_panel::StackPanel, + style::resource::StyleResourceExt, text::TextBuilder, widget::{WidgetBuilder, WidgetMessage}, BuildContext, Thickness, VerticalAlignment, @@ -40,7 +41,7 @@ use crate::{ }, }, scene::{GameScene, Selection}, - Message, + Editor, Message, }; pub struct AudioPreviewPanel { @@ -60,7 +61,11 @@ fn make_button(text: &str, column: usize, ctx: &mut BuildContext) -> Handle Ha TextBuilder::new(WidgetBuilder::new().with_margin(Thickness::left(5.0))) .with_text(format!("{}", entry.work_dir.display(),)) .with_vertical_text_alignment(VerticalAlignment::Center) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ), )) @@ -105,9 +107,15 @@ impl Configurator { let work_dir_selector = FileSelectorBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) .open(false) - .with_title(WindowTitle::text("Select Working Directory")), + .with_title(WindowTitle::text_with_font_size( + "Select Working Directory", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_filter(PathFilter::folder()) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); // Load history. @@ -135,7 +143,11 @@ impl Configurator { .with_height(250.0) .with_min_size(Vector2::new(370.0, 250.0)), ) - .with_title(WindowTitle::text("Configure Editor")) + .with_title(WindowTitle::text_with_font_size( + "Configure Editor", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .open(false) .can_close(false) .with_content( @@ -146,6 +158,7 @@ impl Configurator { TextBuilder::new(WidgetBuilder::new().with_margin(Thickness::uniform(1.0))) .with_text(message) .with_wrap(WrapMode::Word) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child( @@ -161,6 +174,7 @@ impl Configurator { .with_vertical_alignment(VerticalAlignment::Center), ) .with_text("Working Directory") + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child({ @@ -178,6 +192,7 @@ impl Configurator { .unwrap(), ) .with_vertical_text_alignment(VerticalAlignment::Center) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); tb_work_dir }) @@ -189,7 +204,11 @@ impl Configurator { .on_column(2) .with_margin(Thickness::uniform(1.0)), ) - .with_text("...") + .with_text_and_font_size( + "...", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); select_work_dir }), @@ -208,6 +227,7 @@ impl Configurator { ) .with_text("Previous Configurations") .with_horizontal_text_alignment(HorizontalAlignment::Center) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child({ @@ -238,7 +258,11 @@ impl Configurator { .with_height(25.0) .with_margin(Thickness::uniform(1.0)), ) - .with_text("OK") + .with_text_and_font_size( + "OK", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); ok }), diff --git a/editor/src/export/mod.rs b/editor/src/export/mod.rs index 76ec0662a..3512f0872 100644 --- a/editor/src/export/mod.rs +++ b/editor/src/export/mod.rs @@ -43,7 +43,7 @@ use crate::{ message::UiMessage, scroll_viewer::{ScrollViewer, ScrollViewerBuilder, ScrollViewerMessage}, stack_panel::{StackPanel, StackPanelBuilder}, - style::{resource::StyleResourceExt, Style}, + style::{resource::StyleResourceExt, Style, StyledProperty}, text::{Text, TextBuilder}, utils::make_dropdown_list_option, widget::{WidgetBuilder, WidgetMessage}, @@ -54,7 +54,7 @@ use crate::{ }, }, message::MessageSender, - Message, + Editor, Message, }; use fyrox_build_tools::export::{BuildResult, ExportOptions}; use std::sync::{ @@ -89,6 +89,7 @@ fn make_title_text(text: &str, row: usize, ctx: &mut BuildContext) -> Handle>(), ) .with_selected(0) @@ -198,6 +211,8 @@ impl ExportWindow { WidgetBuilder::new().with_margin(Thickness::uniform(2.0)), ) .with_content({ + let font = Some(ctx.default_font()); + let font_size = Some(ctx.style.property(Editor::UI_FONT_SIZE)); let context = InspectorContext::from_object(InspectorContextArgs { object: &export_options, ctx, @@ -211,6 +226,8 @@ impl ExportWindow { name_column_width: 150.0, base_path: Default::default(), has_parent_object: false, + font: font, + font_size: font_size, }); inspector = InspectorBuilder::new(WidgetBuilder::new()) @@ -263,7 +280,11 @@ impl ExportWindow { .with_width(100.0) .with_margin(Thickness::uniform(2.0)), ) - .with_text("Export") + .with_text_and_font_size( + "Export", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); export }) @@ -273,7 +294,11 @@ impl ExportWindow { .with_width(100.0) .with_margin(Thickness::uniform(2.0)), ) - .with_text("Cancel") + .with_text_and_font_size( + "Cancel", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); cancel }), @@ -294,6 +319,7 @@ impl ExportWindow { ) .with_wrap(WrapMode::Word) .with_text(instructions) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child(platform_section) @@ -311,7 +337,11 @@ impl ExportWindow { .add_column(Column::stretch()) .build(ctx), ) - .with_title(WindowTitle::text("Export Project")) + .with_title(WindowTitle::text_with_font_size( + "Export Project", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .build(ctx); Self { @@ -426,10 +456,20 @@ impl ExportWindow { } self.build_targets = build_targets.clone(); + let font = ui.build_ctx().default_font(); + let font_size: StyledProperty = + ui.build_ctx().style.property(Style::FONT_SIZE); let ui_items = self .build_targets .iter() - .map(|name| make_dropdown_list_option(&mut ui.build_ctx(), name)) + .map(|name| { + make_dropdown_list_option( + &mut ui.build_ctx(), + name, + font.clone(), + font_size.clone(), + ) + }) .collect::>(); ui.send( @@ -489,6 +529,7 @@ impl ExportWindow { ) .with_wrap(WrapMode::Letter) .with_text(format!("> {}", message.content)) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); ui.send(entry, WidgetMessage::link_with(self.log)); diff --git a/editor/src/interaction/navmesh/mod.rs b/editor/src/interaction/navmesh/mod.rs index 3750a8e78..e99474806 100644 --- a/editor/src/interaction/navmesh/mod.rs +++ b/editor/src/interaction/navmesh/mod.rs @@ -37,6 +37,7 @@ use crate::{ grid::{Column, GridBuilder, Row}, message::{KeyCode, UiMessage}, stack_panel::StackPanelBuilder, + style::resource::StyleResourceExt, widget::{WidgetBuilder, WidgetMessage}, window::{WindowBuilder, WindowMessage, WindowTitle}, BuildContext, Orientation, Thickness, UserInterface, @@ -66,7 +67,7 @@ use crate::{ }, settings::Settings, utils::window_content, - Mode, + Editor, Mode, }; use fyrox::gui::button::Button; use fyrox::gui::image::Image; @@ -97,7 +98,11 @@ impl NavmeshPanel { let connect_edges; let window = WindowBuilder::new(WidgetBuilder::new().with_name("NavmeshPanel")) .open(false) - .with_title(WindowTitle::text("Navmesh")) + .with_title(WindowTitle::text_with_font_size( + "Navmesh", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("Navmesh") .with_content( GridBuilder::new( @@ -106,7 +111,11 @@ impl NavmeshPanel { connect_edges = ButtonBuilder::new( WidgetBuilder::new().with_margin(Thickness::uniform(1.0)), ) - .with_text("Connect Edges") + .with_text_and_font_size( + "Connect Edges", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); connect_edges })) diff --git a/editor/src/interaction/terrain.rs b/editor/src/interaction/terrain.rs index d60c85fa9..5f0a2bcb1 100644 --- a/editor/src/interaction/terrain.rs +++ b/editor/src/interaction/terrain.rs @@ -73,11 +73,13 @@ use crate::{ GameScene, Selection, SelectionContainer, }, settings::Settings, + Editor, }; use fyrox::gui::button::Button; use fyrox::gui::image::Image; use fyrox::gui::inspector::InspectorContextArgs; +use fyrox::gui::style::resource::StyleResourceExt; use fyrox::gui::window::{Window, WindowAlignment}; use fyrox::scene::mesh::Mesh; use std::sync::mpsc::channel; @@ -631,6 +633,8 @@ impl BrushPanel { property_editors.insert(make_brush_target_enum_property_editor_definition()); property_editors.insert(make_brush_shape_enum_property_editor_definition()); + let font = Some(ctx.default_font()); + let font_size = Some(ctx.style.property(Editor::UI_FONT_SIZE)); let context = InspectorContext::from_object(InspectorContextArgs { object: brush, ctx, @@ -642,6 +646,8 @@ impl BrushPanel { name_column_width: 150.0, base_path: Default::default(), has_parent_object: false, + font: font, + font_size: font_size, }); let inspector; @@ -655,7 +661,11 @@ impl BrushPanel { inspector }) .open(false) - .with_title(WindowTitle::text("Brush Options")) + .with_title(WindowTitle::text_with_font_size( + "Brush Options", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .build(ctx); Self { window, inspector } diff --git a/editor/src/lib.rs b/editor/src/lib.rs index 367348b87..df8ede7fe 100644 --- a/editor/src/lib.rs +++ b/editor/src/lib.rs @@ -116,7 +116,10 @@ use crate::{ }, screen::ScreenBuilder, stack_panel::StackPanelBuilder, - style::{resource::StyleResource, Style}, + style::{ + resource::{StyleResource, StyleResourceExt}, + Style, + }, text::{Text, TextBuilder, TextMessage}, widget::{WidgetBuilder, WidgetMessage}, window::{Window, WindowAlignment, WindowBuilder, WindowMessage, WindowTitle}, @@ -314,13 +317,19 @@ pub fn make_save_file_selector( .with_width(300.0) .with_height(400.0), ) - .with_title(WindowTitle::text("Save Scene As")) + .with_title(WindowTitle::text_with_font_size( + "Save Scene As", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .open(false) .with_remove_on_close(true), ) .with_mode(FileSelectorMode::Save { default_file_name }) .with_filter(PathFilter::new().with_file_type(file_type)) .with_path("./") + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx) } @@ -394,9 +403,15 @@ impl SaveSceneConfirmationDialog { .can_close(false) .can_minimize(false) .open(false) - .with_title(WindowTitle::text("Unsaved changes")), + .with_title(WindowTitle::text_with_font_size( + "Unsaved changes", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_buttons(MessageBoxButtons::YesNoCancel) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); Self { @@ -551,9 +566,15 @@ pub struct SceneLoadingWindow { impl SceneLoadingWindow { pub fn new(ctx: &mut BuildContext) -> Self { - let scene_list_text = TextBuilder::new(WidgetBuilder::new()).build(ctx); + let scene_list_text = TextBuilder::new(WidgetBuilder::new()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) + .build(ctx); let window = WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(100.0)) - .with_title(WindowTitle::text("Please wait...")) + .with_title(WindowTitle::text_with_font_size( + "Please wait...", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .can_close(false) .can_minimize(false) .open(false) @@ -567,6 +588,7 @@ impl SceneLoadingWindow { TextBuilder::new( WidgetBuilder::new().with_margin(Thickness::uniform(2.0)), ) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .with_wrap(WrapMode::Word) .with_text( "Please wait until the following scene(s) are \ @@ -800,6 +822,8 @@ impl Editor { let ui = engine.user_interfaces.first_mut(); if let Some(style) = styles.get(&settings.general.style) { + // style.set(Style::FONT_SIZE, settings.general.ui_font_size); + style.set(Self::UI_FONT_SIZE, settings.general.ui_font_size); ui.set_style(style.clone()); } @@ -841,7 +865,11 @@ impl Editor { load_image!("../resources/clear.png"), true, ); - let inspector_plugin = InspectorPlugin::new(ctx); + let inspector_plugin = InspectorPlugin::new( + ctx, + Some(ctx.default_font()), + Some(ctx.style.property(Editor::UI_FONT_SIZE)), + ); let bbcode_panel = BBCodePanel::new(inspector_plugin.head, ctx); let particle_system_control_panel = ParticleSystemPreviewControlPanel::new(inspector_plugin.head, ctx); @@ -850,7 +878,12 @@ impl Editor { let audio_preview_panel = AudioPreviewPanel::new(inspector_plugin.head, ctx); let doc_window = DocWindow::new(ctx); let node_removal_dialog = NodeRemovalDialog::new(ctx); - let scene_settings = SceneSettingsWindow::new(ctx, property_editors.clone()); + let scene_settings = SceneSettingsWindow::new( + ctx, + property_editors.clone(), + Some(ctx.default_font()), + Some(ctx.style.property(Editor::UI_FONT_SIZE)), + ); let docking_manager; let root_grid = GridBuilder::new( @@ -991,9 +1024,15 @@ impl Editor { .can_close(false) .can_minimize(false) .open(false) - .with_title(WindowTitle::text("Unsaved changes")), + .with_title(WindowTitle::text_with_font_size( + "Unsaved changes", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_buttons(MessageBoxButtons::YesNoCancel) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); let validation_message_box = MessageBoxBuilder::new( @@ -1001,9 +1040,15 @@ impl Editor { .can_close(false) .can_minimize(false) .open(false) - .with_title(WindowTitle::text("Validation failed!")), + .with_title(WindowTitle::text_with_font_size( + "Validation failed!", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_buttons(MessageBoxButtons::Ok) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); let save_scene_dialog = SaveSceneConfirmationDialog::new(ctx); @@ -2262,11 +2307,16 @@ impl Editor { .with_height(32.0) .with_desired_position(Vector2::new(20.0, 20.0)), ) - .with_text("Click Me!") + .with_text_and_font_size( + "Click Me!", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + ) .build(&mut ui.build_ctx()); TextBuilder::new(WidgetBuilder::new().with_desired_position(Vector2::new(300.0, 300.0))) .with_text("This is some text.") + .with_font_size(ui.build_ctx().style.property(Editor::UI_FONT_SIZE)) .build(&mut ui.build_ctx()); let entry = EditorSceneEntry::new_ui_scene( @@ -2784,11 +2834,41 @@ impl Editor { } if self.settings.try_save() { + println!("Need Update"); let ui = self.engine.user_interfaces.first_mut(); + println!( + "Old style font size: {}", + ui.style.get(Self::UI_FONT_SIZE).unwrap_or(0.0) + ); if let Some(style) = self.styles.get(&self.settings.general.style) { + // ISSUE: They are the same resource ref + // style.set(Style::FONT_SIZE, self.settings.general.ui_font_size); + style.set(Self::UI_FONT_SIZE, self.settings.general.ui_font_size); + println!("Got new style"); + println!( + "New style font size: {}", + style.get(Self::UI_FONT_SIZE).unwrap_or(0.0) + ); + println!( + "Again Old style font size: {}", + ui.style.get(Self::UI_FONT_SIZE).unwrap_or(0.0) + ); + // ERROR: If two styles are generated from the same + // "make_style" function, they will always return same on comparison + // even if the inner contents are modified after creation + // This is because style comparisons only care about "resource handles" if style != ui.style() { + println!("Old/New style are different"); + // ui.set_style(style.clone()); + } + if (ui.style().get(Self::UI_FONT_SIZE) as Option).unwrap() + != self.settings.general.ui_font_size + { + println!("Old/New font size are different"); ui.set_style(style.clone()); } + // Update anyway + ui.set_style(style.clone()); } } } diff --git a/editor/src/light.rs b/editor/src/light.rs index 68a479432..bcf74acbf 100644 --- a/editor/src/light.rs +++ b/editor/src/light.rs @@ -33,6 +33,7 @@ use crate::{ progress_bar::{ProgressBar, ProgressBarBuilder, ProgressBarMessage}, scroll_viewer::ScrollViewerBuilder, stack_panel::StackPanelBuilder, + style::resource::StyleResourceExt, text::{Text, TextBuilder, TextMessage}, widget::{WidgetBuilder, WidgetMessage}, window::{Window, WindowAlignment, WindowBuilder, WindowMessage, WindowTitle}, @@ -45,7 +46,7 @@ use crate::{ }, }, scene::GameScene, - Engine, + Editor, Engine, }; use std::{ path::PathBuf, @@ -117,7 +118,11 @@ impl ProgressWindow { let text; let window = WindowBuilder::new(WidgetBuilder::new().with_width(400.0).with_height(120.0)) .open(false) - .with_title(WindowTitle::text("Progress")) + .with_title(WindowTitle::text_with_font_size( + "Progress", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_content( GridBuilder::new( WidgetBuilder::new() @@ -128,6 +133,7 @@ impl ProgressWindow { take different amount of time depending on the settings.", ) .with_wrap(WrapMode::Word) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child({ @@ -144,6 +150,7 @@ impl ProgressWindow { .with_horizontal_alignment(HorizontalAlignment::Center) .with_vertical_alignment(VerticalAlignment::Center), ) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); text }) @@ -155,7 +162,11 @@ impl ProgressWindow { .with_height(25.0) .with_horizontal_alignment(HorizontalAlignment::Right), ) - .with_text("Cancel") + .with_text_and_font_size( + "Cancel", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); cancel }), @@ -244,7 +255,11 @@ impl LightPanel { .with_width(300.0) .with_height(400.0), ) - .with_title(WindowTitle::text("Light Settings")) + .with_title(WindowTitle::text_with_font_size( + "Light Settings", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .open(false) .with_content( GridBuilder::new( @@ -256,6 +271,8 @@ impl LightPanel { .on_row(0), ) .with_content({ + let font = Some(ctx.default_font()); + let font_size = Some(ctx.style.property(Editor::UI_FONT_SIZE)); inspector = InspectorBuilder::new( WidgetBuilder::new().with_margin(Thickness::uniform(1.0)), ) @@ -270,6 +287,8 @@ impl LightPanel { name_column_width: 150.0, base_path: Default::default(), has_parent_object: false, + font: font, + font_size: font_size, })) .build(ctx); inspector @@ -286,7 +305,11 @@ impl LightPanel { generate = ButtonBuilder::new( WidgetBuilder::new().with_margin(Thickness::uniform(2.0)), ) - .with_text("Generate Lightmap") + .with_text_and_font_size( + "Generate Lightmap", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); generate }) @@ -294,7 +317,11 @@ impl LightPanel { clear_lightmap = ButtonBuilder::new( WidgetBuilder::new().with_margin(Thickness::uniform(2.0)), ) - .with_text("Clear Lightmap") + .with_text_and_font_size( + "Clear Lightmap", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); clear_lightmap }), diff --git a/editor/src/menu/file.rs b/editor/src/menu/file.rs index e42361b91..69488471a 100644 --- a/editor/src/menu/file.rs +++ b/editor/src/menu/file.rs @@ -29,6 +29,7 @@ use crate::{ menu::{self, MenuItemMessage}, message::UiMessage, messagebox::{MessageBoxBuilder, MessageBoxButtons, MessageBoxMessage}, + style::resource::StyleResourceExt, widget::{WidgetBuilder, WidgetMessage}, window::{WindowAlignment, WindowBuilder, WindowMessage, WindowTitle}, BuildContext, UserInterface, @@ -39,7 +40,7 @@ use crate::{ message::MessageSender, scene::container::EditorSceneEntry, settings::{recent::RecentFiles, Settings}, - Engine, Message, Mode, Panels, SaveSceneConfirmationDialogAction, + Editor, Engine, Message, Mode, Panels, SaveSceneConfirmationDialogAction, }; use fyrox::core::parking_lot::Mutex; use fyrox::graph::SceneGraph; @@ -122,10 +123,16 @@ impl FileMenu { let configure_message = MessageBoxBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(250.0).with_height(150.0)) .open(false) - .with_title(WindowTitle::text("Warning")), + .with_title(WindowTitle::text_with_font_size( + "Warning", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_text("Cannot reconfigure editor while scene is open! Close scene first and retry.") .with_buttons(MessageBoxButtons::Ok) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); let recent_files = make_recent_files_items(ctx, &settings.recent); @@ -258,7 +265,11 @@ impl FileMenu { let load_file_selector = FileSelectorBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) .open(false) - .with_title(WindowTitle::text("Select a Scene To Load")), + .with_title(WindowTitle::text_with_font_size( + "Select a Scene To Load", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_filter( PathFilter::new() @@ -273,6 +284,8 @@ impl FileMenu { .with_description("User Interface"), ), ) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); Self { diff --git a/editor/src/menu/mod.rs b/editor/src/menu/mod.rs index d0ca01aba..5ba9d545b 100644 --- a/editor/src/menu/mod.rs +++ b/editor/src/menu/mod.rs @@ -38,13 +38,14 @@ use crate::{ scene::{container::EditorSceneEntry, controller::SceneController}, settings::Settings, stats::StatisticsWindow, - Engine, Mode, SceneSettingsWindow, + Editor, Engine, Mode, SceneSettingsWindow, }; use fyrox::asset::manager::ResourceManager; use fyrox::core::Uuid; use fyrox::gui::file_browser::FileType; use fyrox::gui::image::{Image, ImageBuilder}; use fyrox::gui::menu::MenuItem; +use fyrox::gui::style::resource::StyleResourceExt; use fyrox::gui::texture::TextureResource; use fyrox::gui::window::Window; use std::path::PathBuf; @@ -107,6 +108,7 @@ pub fn create_root_menu_item( ) .with_content(MenuItemContent::text_centered(text)) .with_items(items) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx) } @@ -123,6 +125,7 @@ pub fn create_menu_item( ) .with_content(MenuItemContent::text(text)) .with_items(items) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx) } @@ -153,6 +156,7 @@ pub fn create_menu_item_shortcut( ) .with_content(icon) .with_items(items) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx) } diff --git a/editor/src/mesh.rs b/editor/src/mesh.rs index 879c81563..a5eb4db7b 100644 --- a/editor/src/mesh.rs +++ b/editor/src/mesh.rs @@ -32,6 +32,7 @@ use crate::{ scroll_viewer::ScrollViewerBuilder, stack_panel::StackPanel, stack_panel::StackPanelBuilder, + style::resource::StyleResourceExt, text::{Text, TextBuilder, TextMessage}, utils::make_simple_tooltip, widget::WidgetBuilder, @@ -60,7 +61,7 @@ use crate::{ GameScene, Selection, }, world::selection::GraphSelection, - Message, + Editor, Message, }; use fyrox::core::math::TriangleDefinition; use fyrox::gui::VerticalAlignment; @@ -80,7 +81,11 @@ fn make_button(text: &str, tooltip: &str, ctx: &mut BuildContext) -> Handle, + font: Option, + font_size: Option>, ) -> Self { let state_graph_viewer = StateGraphViewer::new(ctx); let state_viewer = StateViewer::new(ctx); - let parameter_panel = ParameterPanel::new(ctx, property_editors); + let parameter_panel = + ParameterPanel::new(ctx, property_editors, font.clone(), font_size.clone()); let blend_space_editor = BlendSpaceEditor::new(ctx); let docking_manager = DockingManagerBuilder::new( @@ -279,7 +288,13 @@ impl AbsmEditor { ) .open(false) .with_content(content) - .with_title(WindowTitle::text("ABSM Editor")) + .with_title(WindowTitle::text_with_font_size( + "ABSM Editor", + font.clone().unwrap_or_else(|| ctx.default_font()), + font_size + .clone() + .unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)), + )) .with_tab_label("ABSM") .build(ctx); @@ -744,9 +759,12 @@ impl AbsmEditorPlugin { &mut self, ui: &mut UserInterface, property_editors: Arc, + font: Option, + font_size: Option>, ) -> &mut AbsmEditor { - self.absm_editor - .get_or_insert_with(|| AbsmEditor::new(&mut ui.build_ctx(), property_editors)) + self.absm_editor.get_or_insert_with(|| { + AbsmEditor::new(&mut ui.build_ctx(), property_editors, font, font_size) + }) } } @@ -756,7 +774,12 @@ impl EditorPlugin for AbsmEditorPlugin { if let Some(layout) = editor.settings.windows.layout.as_ref() { if layout.has_window(AbsmEditor::WINDOW_NAME) { - self.get_or_create_absm_editor(ui, editor.property_editors.clone()); + self.get_or_create_absm_editor( + ui, + editor.property_editors.clone(), + Some(ui.default_font.clone()), + Some(ui.style().property(Editor::UI_FONT_SIZE)), + ); } } @@ -881,7 +904,12 @@ impl EditorPlugin for AbsmEditorPlugin { fn on_message(&mut self, message: &Message, editor: &mut Editor) { if let Message::OpenAbsmEditor = message { let ui = editor.engine.user_interfaces.first_mut(); - let absm_editor = self.get_or_create_absm_editor(ui, editor.property_editors.clone()); + let absm_editor = self.get_or_create_absm_editor( + ui, + editor.property_editors.clone(), + Some(ui.default_font.clone()), + Some(ui.style().property(Editor::UI_FONT_SIZE)), + ); absm_editor.open(ui); @@ -926,7 +954,7 @@ mod test { fn test_deletion() { let screen_size = Vector2::new(100.0, 100.0); let mut ui = UserInterface::new(screen_size); - let editor = AbsmEditor::new(&mut ui.build_ctx(), Default::default()); + let editor = AbsmEditor::new(&mut ui.build_ctx(), Default::default(), None, None); editor.destroy(&ui, Handle::NONE); ui.update(screen_size, 1.0 / 60.0, &Default::default()); while ui.poll_message().is_some() {} diff --git a/editor/src/plugins/absm/node.rs b/editor/src/plugins/absm/node.rs index e3cff5bdc..113865a9d 100644 --- a/editor/src/plugins/absm/node.rs +++ b/editor/src/plugins/absm/node.rs @@ -38,6 +38,7 @@ use crate::fyrox::{ }; use crate::plugins::absm::selectable::{Selectable, SelectableMessage}; use crate::plugins::absm::socket::Socket; +use crate::Editor; use fyrox::core::pool::HandlesVecExtension; use fyrox::gui::border::Border; use fyrox::gui::button::Button; @@ -358,7 +359,11 @@ where .on_row(1) .on_column(0), ) - .with_text("+Input") + .with_text_and_font_size( + "+Input", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); add_input }), @@ -379,6 +384,7 @@ where .with_vertical_text_alignment(VerticalAlignment::Center) .with_horizontal_text_alignment(HorizontalAlignment::Center) .with_text(format!("{} ({})", self.name, self.model_handle)) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); name }) @@ -386,7 +392,11 @@ where edit = ButtonBuilder::new( WidgetBuilder::new().with_margin(Thickness::uniform(1.0)), ) - .with_text("Edit") + .with_text_and_font_size( + "Edit", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); edit } else { @@ -431,6 +441,7 @@ where .with_margin(Thickness::uniform(2.0)), ) .with_text(title) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ), ) diff --git a/editor/src/plugins/absm/parameter.rs b/editor/src/plugins/absm/parameter.rs index be6b12821..c7c763b59 100644 --- a/editor/src/plugins/absm/parameter.rs +++ b/editor/src/plugins/absm/parameter.rs @@ -39,6 +39,7 @@ use crate::{ }, message::UiMessage, scroll_viewer::ScrollViewerBuilder, + style::resource::StyleResourceExt, widget::WidgetBuilder, window::{WindowBuilder, WindowTitle}, BuildContext, UserInterface, @@ -48,21 +49,29 @@ use crate::{ plugins::absm::command::fetch_machine, Message, }; -use fyrox::gui::inspector::Inspector; use fyrox::gui::window::Window; use fyrox::gui::Thickness; +use fyrox::gui::{ + font::FontResource, + inspector::Inspector, + style::{Style, StyledProperty}, +}; use std::sync::Arc; pub struct ParameterPanel { pub window: Handle, inspector: Handle, property_editors: Arc, + font: Option, + font_size: Option>, } impl ParameterPanel { pub fn new( ctx: &mut BuildContext, property_editors: Arc, + font: Option, + font_size: Option>, ) -> Self { property_editors .insert(VecCollectionPropertyEditorDefinition::::new()); @@ -71,7 +80,13 @@ impl ParameterPanel { let inspector; let window = WindowBuilder::new(WidgetBuilder::new()) - .with_title(WindowTitle::text("Parameters")) + .with_title(WindowTitle::text_with_font_size( + "Parameters", + font.clone().unwrap_or_else(|| ctx.default_font()), + font_size + .clone() + .unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)), + )) .with_content( ScrollViewerBuilder::new(WidgetBuilder::new()) .with_content({ @@ -91,6 +106,8 @@ impl ParameterPanel { window, inspector, property_editors, + font, + font_size, } } @@ -112,6 +129,8 @@ impl ParameterPanel { name_column_width: 150.0, base_path: Default::default(), has_parent_object: false, + font: self.font.clone(), + font_size: self.font_size.clone(), }) }) .unwrap_or_default(); diff --git a/editor/src/plugins/absm/socket.rs b/editor/src/plugins/absm/socket.rs index b64ab16fc..f6d9fa420 100644 --- a/editor/src/plugins/absm/socket.rs +++ b/editor/src/plugins/absm/socket.rs @@ -34,6 +34,7 @@ use crate::fyrox::{ BuildContext, Control, Orientation, Thickness, UiNode, UserInterface, VerticalAlignment, }, }; +use crate::Editor; use fyrox::gui::message::MessageData; use fyrox::gui::style::resource::StyleResourceExt; @@ -200,6 +201,7 @@ impl SocketBuilder { ) .with_vertical_text_alignment(VerticalAlignment::Center) .with_text(format!("{:?}", self.index)) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx) } else { Handle::NONE diff --git a/editor/src/plugins/absm/state_graph/mod.rs b/editor/src/plugins/absm/state_graph/mod.rs index 2b3455b54..422403e19 100644 --- a/editor/src/plugins/absm/state_graph/mod.rs +++ b/editor/src/plugins/absm/state_graph/mod.rs @@ -45,6 +45,7 @@ use crate::{ command::{Command, CommandGroup}, message::MessageSender, scene::{commands::ChangeSelectionCommand, Selection}, + Editor, }; use fyrox::core::reflect::Reflect; @@ -90,7 +91,11 @@ impl StateGraphViewer { .build(ctx); let window = WindowBuilder::new(WidgetBuilder::new()) - .with_title(WindowTitle::text("State Graph")) + .with_title(WindowTitle::text_with_font_size( + "State Graph", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("State Graph") .can_close(false) .can_minimize(false) diff --git a/editor/src/plugins/absm/state_viewer/mod.rs b/editor/src/plugins/absm/state_viewer/mod.rs index ea06a995c..3c12ac736 100644 --- a/editor/src/plugins/absm/state_viewer/mod.rs +++ b/editor/src/plugins/absm/state_viewer/mod.rs @@ -58,6 +58,7 @@ use crate::plugins::absm::{ use crate::scene::{commands::ChangeSelectionCommand, Selection}; use crate::plugins::absm::canvas::AbsmCanvas; +use crate::Editor; use fyrox::core::reflect::Reflect; use fyrox::gui::style::resource::StyleResourceExt; use fyrox::gui::style::Style; @@ -181,7 +182,11 @@ impl StateViewer { let window = WindowBuilder::new(WidgetBuilder::new()) .can_close(false) .can_minimize(false) - .with_title(WindowTitle::text("State Viewer")) + .with_title(WindowTitle::text_with_font_size( + "State Viewer", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_content( BorderBuilder::new( WidgetBuilder::new() diff --git a/editor/src/plugins/absm/toolbar.rs b/editor/src/plugins/absm/toolbar.rs index b16f84e3a..190e70eae 100644 --- a/editor/src/plugins/absm/toolbar.rs +++ b/editor/src/plugins/absm/toolbar.rs @@ -31,6 +31,7 @@ use crate::{ input::{InputBox, InputBoxBuilder, InputBoxMessage, InputBoxResult}, message::UiMessage, stack_panel::{StackPanel, StackPanelBuilder}, + style::{resource::StyleResourceExt, Style, StyledProperty}, toggle::{ToggleButton, ToggleButtonMessage}, utils::{make_dropdown_list_option, ImageButtonBuilder}, widget::{WidgetBuilder, WidgetMessage}, @@ -54,6 +55,7 @@ use crate::{ }, Selection, }, + Editor, }; use std::any::TypeId; @@ -189,23 +191,35 @@ impl Toolbar { if message.destination() == self.rename_layer { self.rename_layer_input_box = InputBoxBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(320.0).with_height(120.0)) - .with_title(WindowTitle::text("Rename Layer")) + .with_title(WindowTitle::text_with_font_size( + "Rename Layer", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false) .with_remove_on_close(true), ) .with_text("Type the new name for the selected layer:") .with_value("Layer".to_string()) + .with_font(ui.default_font.clone()) + .with_font_size(ui.style.property(Editor::UI_FONT_SIZE)) .build(&mut ui.build_ctx()); ui.send(self.rename_layer_input_box, InputBoxMessage::open_as_is()); } else if message.destination() == self.add_layer { self.add_layer_input_box = InputBoxBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(320.0).with_height(120.0)) - .with_title(WindowTitle::text("Add Layer")) + .with_title(WindowTitle::text_with_font_size( + "Add Layer", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false) .with_remove_on_close(true), ) .with_text("Type the name for the new layer:") .with_value("Layer".to_string()) + .with_font(ui.default_font.clone()) + .with_font_size(ui.style.property(Editor::UI_FONT_SIZE)) .build(&mut ui.build_ctx()); ui.send(self.add_layer_input_box, InputBoxMessage::open_as_is()); } else if message.destination() == self.edit_mask { @@ -255,7 +269,11 @@ impl Toolbar { WidgetBuilder::new().with_width(300.0).with_height(400.0), ) .open(false) - .with_title(WindowTitle::text("Select nodes that will NOT be animated")), + .with_title(WindowTitle::text_with_font_size( + "Select nodes that will NOT be animated", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )), ) .with_allowed_types( [AllowedType { @@ -376,10 +394,19 @@ impl Toolbar { G: SceneGraph, N: SceneGraphNode, { + let font = ui.build_ctx().default_font(); + let font_size: StyledProperty = ui.build_ctx().style.property(Style::FONT_SIZE); let layers = machine .layers() .iter() - .map(|l| make_dropdown_list_option(&mut ui.build_ctx(), l.name())) + .map(|l| { + make_dropdown_list_option( + &mut ui.build_ctx(), + l.name(), + font.clone(), + font_size.clone(), + ) + }) .collect(); ui.send_sync(self.layers, DropdownListMessage::Items(layers)); diff --git a/editor/src/plugins/animation/mod.rs b/editor/src/plugins/animation/mod.rs index 50b8528e4..da38b351a 100644 --- a/editor/src/plugins/animation/mod.rs +++ b/editor/src/plugins/animation/mod.rs @@ -281,6 +281,11 @@ impl AnimationEditor { .on_row(1), ) .with_show_x_values(false) + .with_font(ctx.default_font()) + .with_font_size( + ctx.style + .property(Editor::UI_FONT_SIZE), + ) .build(ctx); curve_editor }), @@ -330,7 +335,11 @@ impl AnimationEditor { ) .with_content(content) .open(false) - .with_title(WindowTitle::text("Animation Editor")) + .with_title(WindowTitle::text_with_font_size( + "Animation Editor", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("Animation") .build(ctx); diff --git a/editor/src/plugins/animation/ruler.rs b/editor/src/plugins/animation/ruler.rs index 84354dd3a..2436f9c7e 100644 --- a/editor/src/plugins/animation/ruler.rs +++ b/editor/src/plugins/animation/ruler.rs @@ -43,6 +43,7 @@ use crate::fyrox::{ }, }; use crate::menu::create_menu_item; +use crate::Editor; use fyrox::gui::curve::{CurveTransformCell, STANDARD_GRID_SIZE}; use fyrox::gui::menu::{ContextMenuBuilder, MenuItem}; @@ -470,7 +471,11 @@ impl RulerBuilder { .with_foreground(ctx.style.property(Style::BRUSH_LIGHTER)) .build(ctx), transform: Default::default(), - text: RefCell::new(FormattedTextBuilder::new(ctx.default_font()).build()), + text: RefCell::new( + FormattedTextBuilder::new(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) + .build(), + ), value: self.value, drag_context: None, signals: Default::default(), diff --git a/editor/src/plugins/animation/toolbar.rs b/editor/src/plugins/animation/toolbar.rs index 9805d318d..d3aee1cfc 100644 --- a/editor/src/plugins/animation/toolbar.rs +++ b/editor/src/plugins/animation/toolbar.rs @@ -22,7 +22,12 @@ use crate::{ command::{Command, CommandGroup}, fyrox::{ asset::manager::ResourceManager, - core::{futures::executor::block_on, log::Log, pool::ErasedHandle, pool::Handle}, + core::{ + color::Color, + futures::executor::block_on, + log::Log, + pool::{ErasedHandle, Handle}, + }, generic_animation::{Animation, AnimationContainer, RootMotionSettings}, graph::{PrefabData, SceneGraph, SceneGraphNode}, gui::{ @@ -39,10 +44,10 @@ use crate::{ message::{MessageDirection, UiMessage}, numeric::{NumericUpDown, NumericUpDownBuilder, NumericUpDownMessage}, popup::{Placement, Popup, PopupBuilder, PopupMessage}, - style::{resource::StyleResourceExt, Style}, + style::{resource::StyleResourceExt, Style, StyledProperty}, text::{Text, TextBuilder, TextMessage}, toggle::{ToggleButton, ToggleButtonMessage}, - utils::{make_dropdown_list_option_universal, make_simple_tooltip}, + utils::{make_dropdown_list_option_universal, make_simple_tooltip, ImageButtonBuilder}, widget::{WidgetBuilder, WidgetMessage}, window::{WindowAlignment, WindowBuilder, WindowMessage, WindowTitle}, wrap_panel::WrapPanelBuilder, @@ -64,13 +69,14 @@ use crate::{ }, scene::{ commands::ChangeSelectionCommand, - selector::NodeSelectorWindow, - selector::{AllowedType, HierarchyNode, NodeSelectorMessage, NodeSelectorWindowBuilder}, + selector::{ + AllowedType, HierarchyNode, NodeSelectorMessage, NodeSelectorWindow, + NodeSelectorWindowBuilder, + }, Selection, }, + Editor, }; -use fyrox::core::color::Color; -use fyrox::gui::utils::ImageButtonBuilder; use std::any::TypeId; enum ImportMode { @@ -124,6 +130,7 @@ impl RootMotionDropdownArea { TextBuilder::new(WidgetBuilder::new().on_row(row).on_column(0)) .with_vertical_text_alignment(VerticalAlignment::Center) .with_text(text) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx) } @@ -168,7 +175,11 @@ impl RootMotionDropdownArea { .on_row(1) .on_column(1), ) - .with_text("") + .with_text_and_font_size( + "", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); select_node }) @@ -270,7 +281,11 @@ impl RootMotionDropdownArea { WindowBuilder::new( WidgetBuilder::new().with_width(300.0).with_height(400.0), ) - .with_title(WindowTitle::text("Select a Root Node")) + .with_title(WindowTitle::text_with_font_size( + "Select a Root Node", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false), ) .with_allowed_types( @@ -535,6 +550,7 @@ impl Toolbar { TextBuilder::new(WidgetBuilder::new()) .with_vertical_text_alignment(VerticalAlignment::Center) .with_text("Enabled") + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .build(ctx); @@ -609,6 +625,8 @@ impl Toolbar { )), ) .with_value(1.0) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); speed }) @@ -641,6 +659,8 @@ impl Toolbar { ) .with_min_value(0.0) .with_value(0.0) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); time_slice_start }) @@ -657,6 +677,8 @@ impl Toolbar { ) .with_min_value(0.0) .with_value(1.0) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); time_slice_end }), @@ -673,7 +695,11 @@ impl Toolbar { let import_file_selector = FileSelectorBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) .open(false) - .with_title(WindowTitle::text("Select Animation To Import")), + .with_title(WindowTitle::text_with_font_size( + "Select Animation To Import", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_filter( // TODO: Here we allow importing only FBX and GLTF files, but they can contain @@ -684,6 +710,8 @@ impl Toolbar { .with_file_type(FileType::new_extension("gltf")) .with_file_type(FileType::new_extension("glb")), ) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); let root_motion_dropdown_area = RootMotionDropdownArea::new(ctx); @@ -792,7 +820,11 @@ impl Toolbar { } else if message.destination() == self.rename_current_animation { self.rename_animation_input_box = InputBoxBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(320.0).with_height(120.0)) - .with_title(WindowTitle::text("Rename Animation")) + .with_title(WindowTitle::text_with_font_size( + "Rename Animation", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false) .with_remove_on_close(true), ) @@ -804,6 +836,8 @@ impl Toolbar { .map(|a| a.name().to_string()) .unwrap_or_else(|| "Animation".to_string()), ) + .with_font(ui.default_font.clone()) + .with_font_size(ui.style.property(Editor::UI_FONT_SIZE)) .build(&mut ui.build_ctx()); ui.send( self.rename_animation_input_box, @@ -812,12 +846,18 @@ impl Toolbar { } else if message.destination() == self.add_animation { self.animation_name_input_box = InputBoxBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(320.0).with_height(120.0)) - .with_title(WindowTitle::text("New Animation Name")) + .with_title(WindowTitle::text_with_font_size( + "New Animation Name", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false) .with_remove_on_close(true), ) .with_text("Type the name for the new animation:") .with_value("Animation".to_string()) + .with_font(ui.default_font.clone()) + .with_font_size(ui.style.property(Editor::UI_FONT_SIZE)) .build(&mut ui.build_ctx()); ui.send(self.animation_name_input_box, InputBoxMessage::open_as_is()); } else if message.destination() == self.clone_current_animation { @@ -923,7 +963,11 @@ impl Toolbar { self.node_selector = NodeSelectorWindowBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) .with_remove_on_close(true) - .with_title(WindowTitle::text("Select a Target Node")) + .with_title(WindowTitle::text_with_font_size( + "Select a Target Node", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false), ) .with_allowed_types( @@ -1068,10 +1112,19 @@ impl Toolbar { G: SceneGraph, N: SceneGraphNode, { + let font = ui.build_ctx().default_font(); + let font_size: StyledProperty = ui.build_ctx().style.property(Editor::UI_FONT_SIZE); let new_items = animations .pair_iter() .map(|(h, a)| { - make_dropdown_list_option_universal(&mut ui.build_ctx(), a.name(), 22.0, h) + make_dropdown_list_option_universal( + &mut ui.build_ctx(), + a.name(), + 22.0, + h, + font.clone(), + font_size.clone(), + ) }) .collect(); diff --git a/editor/src/plugins/animation/track.rs b/editor/src/plugins/animation/track.rs index f7d3d63bd..eb1eb4178 100644 --- a/editor/src/plugins/animation/track.rs +++ b/editor/src/plugins/animation/track.rs @@ -103,6 +103,7 @@ use crate::{ Selection, }, utils::{self}, + Editor, }; use fyrox::core::warn; use std::{ @@ -525,6 +526,7 @@ impl TrackViewBuilder { .on_column(1), ) .with_text(self.name) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); name_text }), @@ -950,7 +952,11 @@ impl TrackList { { self.node_selector = NodeSelectorWindowBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) - .with_title(WindowTitle::text("Select a Node To Animate")), + .with_title(WindowTitle::text_with_font_size( + "Select a Node To Animate", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )), ) .with_allowed_types( [AllowedType { @@ -1193,7 +1199,11 @@ impl TrackList { } else if message.destination() == self.context_menu.set_target { self.context_menu.target_node_selector = NodeSelectorWindowBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) - .with_title(WindowTitle::text("Select a New Target Node")), + .with_title(WindowTitle::text_with_font_size( + "Select a New Target Node", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )), ) .with_hierarchy(HierarchyNode::from_scene_node(root, Handle::NONE, graph)) .build(&mut ui.build_ctx()); @@ -1298,7 +1308,11 @@ impl TrackList { let property_selector = PropertySelectorWindowBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) - .with_title(WindowTitle::text("Select a Numeric Property To Animate")) + .with_title(WindowTitle::text_with_font_size( + "Select a Numeric Property To Animate", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false), ) .with_allowed_types(Some(FxHashSet::from_iter(define_allowed_types! { @@ -1525,6 +1539,9 @@ impl TrackList { model_track_binding.target().index(), model_track_binding.target().generation() )) + .with_font_size( + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx), ) .build(ctx); @@ -1600,6 +1617,9 @@ impl TrackList { ), ) .with_text(curve_name) + .with_font_size( + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx), ), ) diff --git a/editor/src/plugins/collider/panel.rs b/editor/src/plugins/collider/panel.rs index 8c38f515d..804739982 100644 --- a/editor/src/plugins/collider/panel.rs +++ b/editor/src/plugins/collider/panel.rs @@ -40,10 +40,11 @@ use crate::{ message::MessageSender, plugins::collider::ColliderShapeInteractionMode, scene::{commands::GameSceneContext, GameScene, Selection}, - Message, + Editor, Message, }; use fyrox::gui::button::Button; use fyrox::gui::stack_panel::StackPanel; +use fyrox::gui::style::resource::StyleResourceExt; pub struct ColliderControlPanel { pub root_widget: Handle, @@ -92,7 +93,11 @@ impl ColliderControlPanel { .with_height(24.0) .with_tooltip(make_simple_tooltip(ctx, try_fit_tooltip)), ) - .with_text("Try Fit") + .with_text_and_font_size( + "Try Fit", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); fit }) @@ -103,7 +108,11 @@ impl ColliderControlPanel { .with_height(24.0) .with_tooltip(make_simple_tooltip(ctx, edit_tooltip)), ) - .with_text("Edit") + .with_text_and_font_size( + "Edit", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); edit }), diff --git a/editor/src/plugins/curve_editor.rs b/editor/src/plugins/curve_editor.rs index bdb00a728..e0ac477e6 100644 --- a/editor/src/plugins/curve_editor.rs +++ b/editor/src/plugins/curve_editor.rs @@ -143,21 +143,33 @@ impl CurveEditorWindow { let save_changes_message_box = MessageBoxBuilder::new( WindowBuilder::new(WidgetBuilder::new()) .open(false) - .with_title(WindowTitle::text("Unsaved Changes")), + .with_title(WindowTitle::text_with_font_size( + "Unsaved Changes", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_text( "You have unsaved changes, do you want to save it before closing the curve editor?", ) .with_buttons(MessageBoxButtons::YesNoCancel) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); let cancel_message_box = MessageBoxBuilder::new( WindowBuilder::new(WidgetBuilder::new()) .open(false) - .with_title(WindowTitle::text("Unsaved Changes")), + .with_title(WindowTitle::text_with_font_size( + "Unsaved Changes", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )), ) .with_text("You have unsaved changes, do you want to quit the curve editor without saving?") .with_buttons(MessageBoxButtons::YesNo) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); let curve_editor; @@ -186,6 +198,10 @@ impl CurveEditorWindow { "New", "Ctrl+N", ), ) + .with_font(ctx.default_font()) + .with_font_size( + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); new }, @@ -196,6 +212,10 @@ impl CurveEditorWindow { "Load", "Ctrl+L", ), ) + .with_font(ctx.default_font()) + .with_font_size( + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); load }, @@ -206,10 +226,16 @@ impl CurveEditorWindow { "Save", "Ctrl+S", ), ) + .with_font(ctx.default_font()) + .with_font_size( + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); save }, ]) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), MenuItemBuilder::new(WidgetBuilder::new()) .with_content(MenuItemContent::text("Edit")) @@ -221,6 +247,10 @@ impl CurveEditorWindow { "Undo", "Ctrl+Z", ), ) + .with_font(ctx.default_font()) + .with_font_size( + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); undo }, @@ -231,10 +261,16 @@ impl CurveEditorWindow { "Redo", "Ctrl+Y", ), ) + .with_font(ctx.default_font()) + .with_font_size( + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); redo }, ]) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ]) .build(ctx), @@ -249,6 +285,8 @@ impl CurveEditorWindow { curve_editor = CurveEditorBuilder::new( WidgetBuilder::new().with_enabled(false), ) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); curve_editor }), @@ -267,7 +305,11 @@ impl CurveEditorWindow { .with_margin(Thickness::uniform(1.0)) .with_width(100.0), ) - .with_text("OK") + .with_text_and_font_size( + "OK", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); ok }) @@ -277,7 +319,11 @@ impl CurveEditorWindow { .with_margin(Thickness::uniform(1.0)) .with_width(100.0), ) - .with_text("Cancel") + .with_text_and_font_size( + "Cancel", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); cancel }), @@ -293,7 +339,11 @@ impl CurveEditorWindow { .build(ctx), ) .with_remove_on_close(true) - .with_title(WindowTitle::text("Curve Editor")) + .with_title(WindowTitle::text_with_font_size( + "Curve Editor", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("Curve") .build(ctx); diff --git a/editor/src/plugins/inspector/editors/animation.rs b/editor/src/plugins/inspector/editors/animation.rs index 251f7f9e5..8df229772 100644 --- a/editor/src/plugins/inspector/editors/animation.rs +++ b/editor/src/plugins/inspector/editors/animation.rs @@ -20,29 +20,31 @@ //! Animation selector for `Handle` fields. -use crate::fyrox::generic_animation::EntityId; -use crate::fyrox::{ - core::pool::Handle, - gui::{ - button::{ButtonBuilder, ButtonMessage}, - dropdown_list::{DropdownListBuilder, DropdownListMessage}, - generic_animation::machine::Machine, - inspector::{ - editors::{ - PropertyEditorBuildContext, PropertyEditorDefinition, PropertyEditorInstance, - PropertyEditorMessageContext, PropertyEditorTranslationContext, +use crate::{ + fyrox::{ + core::{pool::Handle, reflect::Reflect}, + generic_animation::EntityId, + gui::{ + button::{ButtonBuilder, ButtonMessage}, + dropdown_list::{DropdownListBuilder, DropdownListMessage}, + generic_animation::machine::Machine, + inspector::{ + editors::{ + PropertyEditorBuildContext, PropertyEditorDefinition, PropertyEditorInstance, + PropertyEditorMessageContext, PropertyEditorTranslationContext, + }, + FieldAction, InspectorError, PropertyChanged, }, - FieldAction, InspectorError, PropertyChanged, + message::{MessageDirection, UiMessage}, + style::{resource::StyleResourceExt, Style}, + utils::make_dropdown_list_option_universal, + widget::WidgetBuilder, }, - message::{MessageDirection, UiMessage}, - widget::WidgetBuilder, }, + plugins::inspector::EditorEnvironment, + Editor, Message, }; -use crate::plugins::inspector::EditorEnvironment; -use crate::Message; -use fyrox::core::reflect::Reflect; -use fyrox::gui::utils::make_dropdown_list_option_universal; use std::{ any::TypeId, fmt::{Debug, Formatter}, @@ -81,6 +83,10 @@ where ) -> Result { let value = ctx.property_info.cast_value::>()?; let environment = EditorEnvironment::try_get_from(&ctx.environment)?; + let font = ctx.font.unwrap_or_else(|| ctx.build_context.default_font()); + let font_size = ctx + .font_size + .unwrap_or_else(|| ctx.build_context.style.property(Editor::UI_FONT_SIZE)); Ok(PropertyEditorInstance::simple( DropdownListBuilder::new(WidgetBuilder::new()) .with_items( @@ -93,6 +99,8 @@ where &d.name, 22.0, *value, + font.clone(), + font_size.clone(), ) }) .collect(), @@ -184,7 +192,12 @@ where ) -> Result { Ok(PropertyEditorInstance::Simple { editor: ButtonBuilder::new(WidgetBuilder::new()) - .with_text("Open Animation Editor...") + .with_text_and_font_size( + "Open Animation Editor...", + ctx.font.unwrap_or_else(|| ctx.build_context.default_font()), + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build(ctx.build_context) .to_base(), }) @@ -241,7 +254,12 @@ where ) -> Result { Ok(PropertyEditorInstance::Simple { editor: ButtonBuilder::new(WidgetBuilder::new()) - .with_text("Open ABSM Editor...") + .with_text_and_font_size( + "Open ABSM Editor...", + ctx.font.unwrap_or_else(|| ctx.build_context.default_font()), + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build(ctx.build_context) .to_base(), }) diff --git a/editor/src/plugins/inspector/editors/dyntype.rs b/editor/src/plugins/inspector/editors/dyntype.rs index 46dea8da3..a05e64b82 100644 --- a/editor/src/plugins/inspector/editors/dyntype.rs +++ b/editor/src/plugins/inspector/editors/dyntype.rs @@ -29,7 +29,6 @@ use crate::{ }, dropdown_list::{DropdownList, DropdownListBuilder, DropdownListMessage}, grid::{GridBuilder, GridDimension}, - inspector::InspectorContextArgs, inspector::{ editors::{ PropertyEditorBuildContext, PropertyEditorDefinition, @@ -37,11 +36,10 @@ use crate::{ PropertyEditorMessageContext, PropertyEditorTranslationContext, }, make_expander_container, FieldAction, Inspector, InspectorBuilder, - InspectorContext, InspectorEnvironment, InspectorError, InspectorMessage, - PropertyChanged, PropertyFilter, + InspectorContext, InspectorContextArgs, InspectorEnvironment, InspectorError, + InspectorMessage, PropertyChanged, PropertyFilter, }, - message::MessageData, - message::{MessageDirection, UiMessage}, + message::{MessageData, MessageDirection, UiMessage}, utils::make_dropdown_list_option, widget::{Widget, WidgetBuilder}, BuildContext, Control, UiNode, UserInterface, @@ -49,7 +47,13 @@ use crate::{ }, plugins::inspector::EditorEnvironment, }; -use fyrox::core::dyntype::DynTypeWrapper; +use fyrox::{ + core::dyntype::DynTypeWrapper, + gui::{ + font::FontResource, + style::{resource::StyleResourceExt, Style, StyledProperty}, + }, +}; use std::{ any::TypeId, cell::Cell, @@ -132,11 +136,27 @@ impl Control for DynTypePropertyEditor { pub struct DynTypePropertyEditorBuilder { widget_builder: WidgetBuilder, + font: Option, + font_size: Option>, } impl DynTypePropertyEditorBuilder { pub fn new(widget_builder: WidgetBuilder) -> Self { - Self { widget_builder } + Self { + widget_builder, + font: None, + font_size: None, + } + } + + pub fn with_font(mut self, font: FontResource) -> Self { + self.font = Some(font); + self + } + + pub fn with_font_size(mut self, font_size: StyledProperty) -> Self { + self.font_size = Some(font_size); + self } pub fn build( @@ -165,6 +185,8 @@ impl DynTypePropertyEditorBuilder { name_column_width, base_path: Default::default(), has_parent_object, + font: self.font, + font_size: self.font_size, }) }); @@ -191,13 +213,23 @@ fn create_items( ctx: &mut BuildContext, ) -> Vec> { let mut items = vec![{ - let empty = make_dropdown_list_option(ctx, ""); + let empty = make_dropdown_list_option( + ctx, + "", + ctx.default_font(), + ctx.style.property(Style::FONT_SIZE), + ); ctx[empty].user_data = Some(Arc::new(Mutex::new(Uuid::default()))); empty }]; items.extend(constructors.inner().iter().map(|(type_uuid, constructor)| { - let item = make_dropdown_list_option(ctx, &constructor.name); + let item = make_dropdown_list_option( + ctx, + &constructor.name, + ctx.default_font(), + ctx.style.property(Style::FONT_SIZE), + ); ctx[item].user_data = Some(Arc::new(Mutex::new(*type_uuid))); item })); @@ -263,19 +295,25 @@ impl PropertyEditorDefinition for DynTypePropertyEditorDefinition { ctx.property_info.doc, dyn_type_selector_panel, { - editor = DynTypePropertyEditorBuilder::new(WidgetBuilder::new()).build( - variant_selector, - value.value_ref().map(|s| s.type_uuid()), - ctx.environment.clone(), - ctx.layer_index, - ctx.generate_property_string_values, - ctx.filter, - value, - ctx.definition_container.clone(), - ctx.name_column_width, - ctx.has_parent_object, - ctx.build_context, - ); + editor = DynTypePropertyEditorBuilder::new(WidgetBuilder::new()) + .with_font(ctx.font.unwrap_or_else(|| ctx.build_context.default_font())) + .with_font_size( + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) + .build( + variant_selector, + value.value_ref().map(|s| s.type_uuid()), + ctx.environment.clone(), + ctx.layer_index, + ctx.generate_property_string_values, + ctx.filter, + value, + ctx.definition_container.clone(), + ctx.name_column_width, + ctx.has_parent_object, + ctx.build_context, + ); editor }, ctx.name_column_width, @@ -357,6 +395,8 @@ impl PropertyEditorDefinition for DynTypePropertyEditorDefinition { name_column_width: ctx.name_column_width, base_path: Default::default(), has_parent_object: ctx.has_parent_object, + font: ctx.font, + font_size: ctx.font_size, }) }) .unwrap_or_default(); diff --git a/editor/src/plugins/inspector/editors/font.rs b/editor/src/plugins/inspector/editors/font.rs index 917e1dd65..c95c3df6f 100644 --- a/editor/src/plugins/inspector/editors/font.rs +++ b/editor/src/plugins/inspector/editors/font.rs @@ -39,6 +39,7 @@ use crate::{ FieldAction, InspectorError, PropertyChanged, }, message::{MessageDirection, UiMessage}, + style::resource::StyleResourceExt, text::{TextBuilder, TextMessage}, widget::{Widget, WidgetBuilder, WidgetMessage}, BuildContext, Control, UiNode, UserInterface, @@ -46,9 +47,12 @@ use crate::{ }, }; -use fyrox::asset::manager::ResourceManager; use fyrox::gui::message::MessageData; use fyrox::gui::text::Text; +use fyrox::{ + asset::manager::ResourceManager, + gui::style::{Style, StyledProperty}, +}; use std::{ any::TypeId, fmt::{Debug, Formatter}, @@ -138,6 +142,7 @@ impl Control for FontField { pub struct FontFieldBuilder { widget_builder: WidgetBuilder, font: FontResource, + font_size: Option>, } fn make_name(resource_manager: &ResourceManager, font: &FontResource) -> String { @@ -158,6 +163,7 @@ impl FontFieldBuilder { Self { widget_builder, font: BUILT_IN_FONT.resource(), + font_size: None, } } @@ -166,11 +172,22 @@ impl FontFieldBuilder { self } + /// Sets a desired font size property of the field. + pub fn with_font_size(mut self, font_size: StyledProperty) -> Self { + self.font_size = Some(font_size); + self + } + pub fn build( self, resource_manager: ResourceManager, ctx: &mut BuildContext, ) -> Handle { + let font_size = self + .font_size + .clone() + .unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)); + let text_preview; let widget = self .widget_builder @@ -180,6 +197,7 @@ impl FontFieldBuilder { .with_wrap(WrapMode::Word) .with_text(make_name(&resource_manager, &self.font)) .with_font(self.font.clone()) + .with_font_size(font_size.clone()) .build(ctx); text_preview }) @@ -215,6 +233,10 @@ impl PropertyEditorDefinition for FontPropertyEditorDefinition { Ok(PropertyEditorInstance::simple( FontFieldBuilder::new(WidgetBuilder::new().with_min_size(Vector2::new(0.0, 17.0))) .with_font(value.clone()) + .with_font_size( + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build(self.resource_manager.clone(), ctx.build_context), )) } diff --git a/editor/src/plugins/inspector/editors/handle.rs b/editor/src/plugins/inspector/editors/handle.rs index ea1d08b42..04a784558 100644 --- a/editor/src/plugins/inspector/editors/handle.rs +++ b/editor/src/plugins/inspector/editors/handle.rs @@ -52,12 +52,14 @@ use crate::{ message::MessageSender, scene::selector::{HierarchyNode, NodeSelectorMessage, NodeSelectorWindowBuilder}, world::item::SceneItem, - Message, UiMessage, UiNode, UserInterface, VerticalAlignment, + Editor, Message, UiMessage, UiNode, UserInterface, VerticalAlignment, }; use fyrox::core::PhantomDataSendSync; use fyrox::gui::button::Button; +use fyrox::gui::font::FontResource; use fyrox::gui::image::Image; use fyrox::gui::message::MessageData; +use fyrox::gui::style::StyledProperty; use fyrox::gui::text::Text; use fyrox::gui::window::WindowAlignment; use std::{ @@ -266,7 +268,11 @@ impl Control for HandlePropertyEditor { } else if message.destination == self.pick { let node_selector = NodeSelectorWindowBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)) - .with_title(WindowTitle::text("Select a Node")) + .with_title(WindowTitle::text_with_font_size( + "Select a Node", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false), ) .with_allowed_types( @@ -319,6 +325,8 @@ struct HandlePropertyEditorBuilder { widget_builder: WidgetBuilder, value: Handle, sender: MessageSender, + font: Option, + font_size: Option>, } fn make_icon(data: &[u8], color: Color, ctx: &mut BuildContext) -> Handle { @@ -358,6 +366,8 @@ impl HandlePropertyEditorBuilder { widget_builder, sender, value: Default::default(), + font: None, + font_size: None, } } @@ -366,7 +376,25 @@ impl HandlePropertyEditorBuilder { self } + /// Sets the desired font of the editor. + pub fn with_font(mut self, font: FontResource) -> Self { + self.font = Some(font); + self + } + + /// Sets a desired font size property of the editor. + pub fn with_font_size(mut self, font_size: StyledProperty) -> Self { + self.font_size = Some(font_size); + self + } + pub fn build(self, ctx: &mut BuildContext) -> Handle> { + let font = self.font.clone().unwrap_or_else(|| ctx.default_font()); + let font_size = self + .font_size + .clone() + .unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)); + let text = TextBuilder::new( WidgetBuilder::new() .on_column(0) @@ -378,6 +406,8 @@ impl HandlePropertyEditorBuilder { } else { "Err: Desync!".to_owned() }) + .with_font(font.clone()) + .with_font_size(font_size.clone()) .build(ctx); let locate_img = include_bytes!("../../../../resources/locate.png"); let locate = make_button(ctx, locate_img, Color::repeat(180), 2, "Locate Object"); @@ -470,6 +500,11 @@ impl PropertyEditorDefinition for NodeHandlePropertyEditorDefinition let editor = HandlePropertyEditorBuilder::new(WidgetBuilder::new(), sender.clone()) .with_value(*value) + .with_font(ctx.font.unwrap_or_else(|| ctx.build_context.default_font())) + .with_font_size( + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build(ctx.build_context); request_name_sync(&sender, editor.to_base(), ErasedHandle::from(*value)); diff --git a/editor/src/plugins/inspector/editors/resource.rs b/editor/src/plugins/inspector/editors/resource.rs index 0cb6c809d..7d13f8c25 100644 --- a/editor/src/plugins/inspector/editors/resource.rs +++ b/editor/src/plugins/inspector/editors/resource.rs @@ -18,6 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +use fyrox::gui::{ + font::FontResource, + style::{Style, StyledProperty}, +}; + use crate::{ asset::{ item::AssetItem, item::AssetItemMessage, preview::cache::IconRequest, @@ -44,6 +49,7 @@ use crate::{ FieldAction, InspectorError, PropertyChanged, }, message::{MessageData, MessageDirection, UiMessage}, + style::resource::StyleResourceExt, text::{Text, TextBuilder, TextMessage}, utils::{make_asset_preview_tooltip, ImageButtonBuilder}, widget::{Widget, WidgetBuilder, WidgetMessage}, @@ -279,6 +285,8 @@ where widget_builder: WidgetBuilder, resource: Option>, sender: MessageSender, + font: Option, + font_size: Option>, } impl ResourceFieldBuilder @@ -290,6 +298,8 @@ where widget_builder, resource: None, sender, + font: None, + font_size: None, } } @@ -298,6 +308,18 @@ where self } + /// Sets the desired font of the field. + pub fn with_font(mut self, font: FontResource) -> Self { + self.font = Some(font); + self + } + + /// Sets a desired font size property of the field. + pub fn with_font_size(mut self, font_size: StyledProperty) -> Self { + self.font_size = Some(font_size); + self + } + pub fn build( self, ctx: &mut BuildContext, @@ -306,6 +328,12 @@ where ) -> Handle> { let (image_preview_tooltip, image_preview) = make_asset_preview_tooltip(None, ctx); + let font = self.font.clone().unwrap_or_else(|| ctx.default_font()); + let font_size = self + .font_size + .clone() + .unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)); + let name; let locate; let select; @@ -338,6 +366,8 @@ where ) .with_vertical_text_alignment(VerticalAlignment::Center) .with_text(resource_path(&resource_manager, &self.resource)) + .with_font(font.clone()) + .with_font_size(font_size.clone()) .build(ctx); name }) @@ -438,6 +468,11 @@ where Ok(PropertyEditorInstance::simple( ResourceFieldBuilder::new(WidgetBuilder::new(), self.sender.clone()) .with_resource(value.clone()) + .with_font(ctx.font.unwrap_or_else(|| ctx.build_context.default_font())) + .with_font_size( + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build( ctx.build_context, environment.icon_request_sender.clone(), diff --git a/editor/src/plugins/inspector/editors/script.rs b/editor/src/plugins/inspector/editors/script.rs index ac76ecb66..433c683d7 100644 --- a/editor/src/plugins/inspector/editors/script.rs +++ b/editor/src/plugins/inspector/editors/script.rs @@ -18,46 +18,43 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -use crate::fyrox::{ - core::{ - log::Log, parking_lot::Mutex, pool::Handle, reflect::prelude::*, type_traits::prelude::*, - uuid_provider, visitor::prelude::*, - }, - engine::SerializationContext, - graph::SceneGraph, - gui::{ - button::{ButtonBuilder, ButtonMessage}, - dropdown_list::{DropdownList, DropdownListMessage}, - grid::{GridBuilder, GridDimension}, - inspector::{ - editors::{ - PropertyEditorBuildContext, PropertyEditorDefinition, - PropertyEditorDefinitionContainer, PropertyEditorInstance, - PropertyEditorMessageContext, PropertyEditorTranslationContext, +use crate::{ + fyrox::{ + core::{ + log::Log, parking_lot::Mutex, pool::Handle, reflect::prelude::*, + type_traits::prelude::*, uuid_provider, visitor::prelude::*, + }, + engine::SerializationContext, + graph::SceneGraph, + gui::{ + button::{Button, ButtonBuilder, ButtonMessage}, + dropdown_list::{DropdownList, DropdownListMessage}, + font::FontResource, + grid::{GridBuilder, GridDimension}, + inspector::{ + editors::{ + PropertyEditorBuildContext, PropertyEditorDefinition, + PropertyEditorDefinitionContainer, PropertyEditorInstance, + PropertyEditorMessageContext, PropertyEditorTranslationContext, + }, + make_expander_container, FieldAction, Inspector, InspectorBuilder, + InspectorContext, InspectorContextArgs, InspectorEnvironment, InspectorError, + InspectorMessage, PropertyChanged, PropertyFilter, }, - make_expander_container, FieldAction, Inspector, InspectorBuilder, InspectorContext, - InspectorEnvironment, InspectorError, InspectorMessage, PropertyChanged, - PropertyFilter, + message::{MessageData, MessageDirection, UiMessage}, + style::{resource::StyleResourceExt, Style, StyledProperty}, + text::TextBuilder, + utils::{make_dropdown_list_option, make_simple_tooltip}, + widget::{Widget, WidgetBuilder}, + BuildContext, Control, Thickness, UiNode, UserInterface, VerticalAlignment, }, - message::{MessageDirection, UiMessage}, - text::TextBuilder, - utils::make_simple_tooltip, - widget::{Widget, WidgetBuilder}, - BuildContext, Control, UiNode, UserInterface, + script::Script, }, - script::Script, -}; -use crate::plugins::inspector::EditorEnvironment; -use crate::{ + plugins::inspector::EditorEnvironment, settings::{general::ScriptEditor, SettingsData}, - DropdownListBuilder, + DropdownListBuilder, Editor, }; -use fyrox::gui::button::Button; -use fyrox::gui::inspector::InspectorContextArgs; -use fyrox::gui::message::MessageData; -use fyrox::gui::utils::make_dropdown_list_option; -use fyrox::gui::{Thickness, VerticalAlignment}; use std::{ any::TypeId, cell::Cell, @@ -206,11 +203,27 @@ impl Control for ScriptPropertyEditor { pub struct ScriptPropertyEditorBuilder { widget_builder: WidgetBuilder, + font: Option, + font_size: Option>, } impl ScriptPropertyEditorBuilder { pub fn new(widget_builder: WidgetBuilder) -> Self { - Self { widget_builder } + Self { + widget_builder, + font: None, + font_size: None, + } + } + + pub fn with_font(mut self, font: FontResource) -> Self { + self.font = Some(font); + self + } + + pub fn with_font_size(mut self, font_size: StyledProperty) -> Self { + self.font_size = Some(font_size); + self } pub fn build( @@ -240,6 +253,8 @@ impl ScriptPropertyEditorBuilder { name_column_width, base_path: Default::default(), has_parent_object, + font: self.font, + font_size: self.font_size, }) }); @@ -267,7 +282,12 @@ fn create_items( ctx: &mut BuildContext, ) -> Vec> { let mut items = vec![{ - let empty = make_dropdown_list_option(ctx, ""); + let empty = make_dropdown_list_option( + ctx, + "", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ); ctx[empty].user_data = Some(Arc::new(Mutex::new(( Uuid::default(), Option::::None, @@ -277,7 +297,12 @@ fn create_items( items.extend(serialization_context.script_constructors.map().iter().map( |(type_uuid, constructor)| { - let item = make_dropdown_list_option(ctx, &constructor.name); + let item = make_dropdown_list_option( + ctx, + &constructor.name, + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ); ctx[item].user_data = Some(Arc::new(Mutex::new(( *type_uuid, @@ -345,6 +370,16 @@ impl PropertyEditorDefinition for ScriptPropertyEditorDefinition { TextBuilder::new(WidgetBuilder::new().with_margin(Thickness::uniform(3.0))) .with_text("Edit...") .with_vertical_text_alignment(VerticalAlignment::Center) + .with_font( + ctx.font + .clone() + .unwrap_or_else(|| ctx.build_context.default_font()), + ) + .with_font_size( + ctx.font_size + .clone() + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build(ctx.build_context), ) .build(ctx.build_context); @@ -366,20 +401,31 @@ impl PropertyEditorDefinition for ScriptPropertyEditorDefinition { ctx.property_info.doc, script_selector_panel, { - editor = ScriptPropertyEditorBuilder::new(WidgetBuilder::new()).build( - open_in_ide, - variant_selector, - value.as_ref().map(|s| s.id()), - ctx.environment.clone(), - ctx.layer_index, - ctx.generate_property_string_values, - ctx.filter, - value, - ctx.definition_container.clone(), - ctx.name_column_width, - ctx.has_parent_object, - ctx.build_context, - ); + editor = ScriptPropertyEditorBuilder::new(WidgetBuilder::new()) + .with_font( + ctx.font + .clone() + .unwrap_or_else(|| ctx.build_context.default_font()), + ) + .with_font_size( + ctx.font_size + .clone() + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) + .build( + open_in_ide, + variant_selector, + value.as_ref().map(|s| s.id()), + ctx.environment.clone(), + ctx.layer_index, + ctx.generate_property_string_values, + ctx.filter, + value, + ctx.definition_container.clone(), + ctx.name_column_width, + ctx.has_parent_object, + ctx.build_context, + ); editor }, ctx.name_column_width, @@ -462,6 +508,8 @@ impl PropertyEditorDefinition for ScriptPropertyEditorDefinition { name_column_width: ctx.name_column_width, base_path: Default::default(), has_parent_object: ctx.has_parent_object, + font: ctx.font, + font_size: ctx.font_size, }) }) .unwrap_or_default(); diff --git a/editor/src/plugins/inspector/editors/shader/field.rs b/editor/src/plugins/inspector/editors/shader/field.rs index 4b2377b9c..d21db6e42 100644 --- a/editor/src/plugins/inspector/editors/shader/field.rs +++ b/editor/src/plugins/inspector/editors/shader/field.rs @@ -32,6 +32,7 @@ use crate::{ FieldAction, InspectorError, PropertyChanged, }, message::{MessageDirection, UiMessage}, + style::resource::StyleResourceExt, widget::{Widget, WidgetBuilder}, window::{WindowBuilder, WindowTitle}, BuildContext, Control, UiNode, UserInterface, @@ -41,8 +42,13 @@ use crate::{ plugins::inspector::editors::shader::{ ShaderSourceCodeEditor, ShaderSourceCodeEditorBuilder, ShaderSourceCodeEditorMessage, }, + Editor, +}; +use fyrox::gui::{ + button::Button, + font::FontResource, + style::{Style, StyledProperty}, }; -use fyrox::gui::button::Button; use std::{any::TypeId, cell::RefCell}; #[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider)] @@ -64,7 +70,11 @@ impl Control for ShaderSourceCodeEditorField { if let Some(ButtonMessage::Click) = message.data() { self.editor = ShaderSourceCodeEditorBuilder::new( WindowBuilder::new(WidgetBuilder::new().with_width(400.0).with_height(600.0)) - .with_title(WindowTitle::text("Edit Shader Source Code")) + .with_title(WindowTitle::text_with_font_size( + "Edit Shader Source Code", + ui.default_font.clone(), + ui.style.property(Editor::UI_FONT_SIZE), + )) .open(false), ) .with_code(self.code.borrow().clone()) @@ -87,6 +97,8 @@ impl Control for ShaderSourceCodeEditorField { pub struct ShaderSourceCodeEditorFieldBuilder { widget_builder: WidgetBuilder, code: ShaderSourceCode, + font: Option, + font_size: Option>, } impl ShaderSourceCodeEditorFieldBuilder { @@ -94,6 +106,8 @@ impl ShaderSourceCodeEditorFieldBuilder { Self { widget_builder, code: Default::default(), + font: None, + font_size: None, } } @@ -102,9 +116,27 @@ impl ShaderSourceCodeEditorFieldBuilder { self } + /// Sets the desired font of the editor. + pub fn with_font(mut self, font: FontResource) -> Self { + self.font = Some(font); + self + } + + /// Sets a desired font size property of the editor. + pub fn with_font_size(mut self, font_size: StyledProperty) -> Self { + self.font_size = Some(font_size); + self + } + pub fn build(self, ctx: &mut BuildContext) -> Handle { + let font = self.font.clone().unwrap_or_else(|| ctx.default_font()); + let font_size = self + .font_size + .clone() + .unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)); + let button = ButtonBuilder::new(WidgetBuilder::new()) - .with_text("Edit Source Code...") + .with_text_and_font_size("Edit Source Code...", font.clone(), font_size.clone()) .build(ctx); let editor = ShaderSourceCodeEditorField { @@ -138,6 +170,11 @@ impl PropertyEditorDefinition for ShaderSourceCodeEditorDefinition { Ok(PropertyEditorInstance::Simple { editor: ShaderSourceCodeEditorFieldBuilder::new(WidgetBuilder::new()) .with_code(value.clone()) + .with_font(ctx.font.unwrap_or_else(|| ctx.build_context.default_font())) + .with_font_size( + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build(ctx.build_context) .transmute(), }) diff --git a/editor/src/plugins/inspector/editors/shader/mod.rs b/editor/src/plugins/inspector/editors/shader/mod.rs index a29bb79f9..b58febae2 100644 --- a/editor/src/plugins/inspector/editors/shader/mod.rs +++ b/editor/src/plugins/inspector/editors/shader/mod.rs @@ -18,6 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +use crate::Editor; use fyrox::{ core::{pool::Handle, reflect::prelude::*, type_traits::prelude::*, visitor::prelude::*}, gui::{ @@ -25,6 +26,7 @@ use fyrox::{ formatted_text::WrapMode, message::{MessageData, UiMessage}, scroll_viewer::ScrollViewerBuilder, + style::resource::StyleResourceExt, text::TextMessage, text_box::{TextBox, TextBoxBuilder, TextCommitMode}, widget::WidgetBuilder, @@ -97,6 +99,7 @@ impl ShaderSourceCodeEditorBuilder { .with_padding(Thickness::uniform(2.0)) .with_text_commit_mode(TextCommitMode::LostFocusPlusEnter) .with_text(&self.code.0) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); let content = ScrollViewerBuilder::new(WidgetBuilder::new()) diff --git a/editor/src/plugins/inspector/editors/spritesheet/mod.rs b/editor/src/plugins/inspector/editors/spritesheet/mod.rs index 1f33f3ef8..75dbf65d2 100644 --- a/editor/src/plugins/inspector/editors/spritesheet/mod.rs +++ b/editor/src/plugins/inspector/editors/spritesheet/mod.rs @@ -32,6 +32,7 @@ use crate::fyrox::{ FieldAction, InspectorError, PropertyChanged, }, message::{MessageDirection, UiMessage}, + style::resource::StyleResourceExt, text::TextBuilder, widget::{Widget, WidgetBuilder}, window::WindowMessage, @@ -40,6 +41,7 @@ use crate::fyrox::{ scene::animation::spritesheet::prelude::*, }; use crate::plugins::inspector::editors::spritesheet::window::SpriteSheetFramesEditorWindow; +use crate::Editor; use fyrox::gui::button::Button; use fyrox::gui::message::MessageData; @@ -113,6 +115,7 @@ impl SpriteSheetFramesPropertyEditor { .on_column(0), ) .with_text(format!("Frames: {}", container.len())) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child({ @@ -122,7 +125,11 @@ impl SpriteSheetFramesPropertyEditor { .with_margin(Thickness::uniform(1.0)) .on_column(1), ) - .with_text("Edit...") + .with_text_and_font_size( + "Edit...", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); edit_button }), diff --git a/editor/src/plugins/inspector/editors/spritesheet/window.rs b/editor/src/plugins/inspector/editors/spritesheet/window.rs index 02f93f40d..d9445cf3c 100644 --- a/editor/src/plugins/inspector/editors/spritesheet/window.rs +++ b/editor/src/plugins/inspector/editors/spritesheet/window.rs @@ -44,6 +44,7 @@ use crate::fyrox::{ scene::animation::spritesheet::prelude::*, }; use crate::plugins::inspector::editors::spritesheet::SpriteSheetFramesPropertyEditorMessage; +use crate::Editor; use fyrox::core::pool::HandlesVecExtension; use fyrox::gui::border::Border; @@ -269,12 +270,15 @@ impl SpriteSheetFramesEditorWindow { .with_tooltip(make_simple_tooltip(ctx, column_tooltip)), ) .with_text("Width") + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child({ width = NumericUpDownBuilder::new(WidgetBuilder::new().on_column(1).on_row(0)) .with_min_value(0) .with_value(container.size().x) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); width }) @@ -288,12 +292,15 @@ impl SpriteSheetFramesEditorWindow { .with_tooltip(make_simple_tooltip(ctx, row_tooltip)), ) .with_text("Height") + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx), ) .with_child({ height = NumericUpDownBuilder::new(WidgetBuilder::new().on_column(1).on_row(1)) .with_min_value(0) .with_value(container.size().y) + .with_font(ctx.default_font()) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); height }), @@ -327,7 +334,11 @@ impl SpriteSheetFramesEditorWindow { .with_width(70.0) .with_margin(Thickness::uniform(1.0)), ) - .with_text("OK") + .with_text_and_font_size( + "OK", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); ok }) @@ -337,7 +348,11 @@ impl SpriteSheetFramesEditorWindow { .with_width(70.0) .with_margin(Thickness::uniform(1.0)), ) - .with_text("Cancel") + .with_text_and_font_size( + "Cancel", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); cancel }), @@ -399,7 +414,11 @@ impl SpriteSheetFramesEditorWindow { ) .open(false) .can_minimize(false) - .with_title(WindowTitle::text("Sprite Sheet Frames Editor")) + .with_title(WindowTitle::text_with_font_size( + "Sprite Sheet Frames Editor", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + )) .with_tab_label("Sprite Sheet Frames") .build_window(ctx), animation: SpriteSheetAnimation::with_container(container), diff --git a/editor/src/plugins/inspector/editors/surface.rs b/editor/src/plugins/inspector/editors/surface.rs index f3c282568..4f254bf3a 100644 --- a/editor/src/plugins/inspector/editors/surface.rs +++ b/editor/src/plugins/inspector/editors/surface.rs @@ -46,6 +46,7 @@ use crate::{ }, message::{MessageData, MessageDirection, UiMessage}, stack_panel::StackPanelBuilder, + style::resource::StyleResourceExt, text::{Text, TextBuilder, TextMessage}, utils::{make_asset_preview_tooltip, ImageButtonBuilder}, widget::{Widget, WidgetBuilder, WidgetMessage}, @@ -57,7 +58,7 @@ use crate::{ message::MessageSender, plugins::inspector::EditorEnvironment, utils::make_pick_button, - Message, + Editor, Message, }; use std::{any::TypeId, sync::mpsc::Sender}; @@ -219,13 +220,18 @@ impl SurfaceDataPropertyEditor { .with_width(55.0) .with_height(22.0), ) - .with_text("View...") + .with_text_and_font_size( + "View...", + ctx.default_font(), + ctx.style.property(Editor::UI_FONT_SIZE), + ) .build(ctx); let select = make_pick_button(1, ctx); let text = TextBuilder::new(WidgetBuilder::new().with_margin(Thickness::uniform(1.0))) .with_text(surface_data_info(&resource_manager, &surface_resource)) + .with_font_size(ctx.style.property(Editor::UI_FONT_SIZE)) .build(ctx); let (image_preview_tooltip, image_preview) = make_asset_preview_tooltip(None, ctx); diff --git a/editor/src/plugins/inspector/editors/texture.rs b/editor/src/plugins/inspector/editors/texture.rs index 859a08409..c5c42c133 100644 --- a/editor/src/plugins/inspector/editors/texture.rs +++ b/editor/src/plugins/inspector/editors/texture.rs @@ -18,6 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +use fyrox::gui::{ + font::FontResource, + style::{Style, StyledProperty}, +}; + use crate::{ asset::{item::AssetItem, preview::cache::IconRequest, selector::AssetSelectorMixin}, fyrox::{ @@ -39,6 +44,7 @@ use crate::{ FieldAction, InspectorError, PropertyChanged, }, message::{MessageData, MessageDirection, UiMessage}, + style::resource::StyleResourceExt, text::{Text, TextBuilder, TextMessage}, utils::{make_asset_preview_tooltip, ImageButtonBuilder}, widget::{Widget, WidgetBuilder, WidgetMessage}, @@ -178,6 +184,8 @@ impl TextureEditor { pub struct TextureEditorBuilder { widget_builder: WidgetBuilder, texture: Option, + font: Option, + font_size: Option>, } impl TextureEditorBuilder { @@ -185,6 +193,8 @@ impl TextureEditorBuilder { Self { widget_builder, texture: None, + font: None, + font_size: None, } } @@ -193,6 +203,18 @@ impl TextureEditorBuilder { self } + /// Sets the desired font for the editor. + pub fn with_font(mut self, font: FontResource) -> Self { + self.font = Some(font); + self + } + + /// Sets the desired font size property of the editor. + pub fn with_font_size(mut self, font_size: StyledProperty) -> Self { + self.font_size = Some(font_size); + self + } + pub fn build( self, ctx: &mut BuildContext, @@ -200,6 +222,12 @@ impl TextureEditorBuilder { icon_request_sender: Sender, resource_manager: ResourceManager, ) -> Handle { + let font = self.font.clone().unwrap_or_else(|| ctx.default_font()); + let font_size = self + .font_size + .clone() + .unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)); + let image = ImageBuilder::new( WidgetBuilder::new() .on_column(0) @@ -224,6 +252,8 @@ impl TextureEditorBuilder { .with_vertical_alignment(VerticalAlignment::Center), ) .with_text(texture_name(self.texture.as_ref(), &resource_manager)) + .with_font(font.clone()) + .with_font_size(font_size.clone()) .build(ctx); let locate = ImageButtonBuilder::default() @@ -317,6 +347,11 @@ impl PropertyEditorDefinition for TexturePropertyEditorDefinition { Ok(PropertyEditorInstance::simple( TextureEditorBuilder::new(WidgetBuilder::new().with_min_size(Vector2::new(0.0, 17.0))) .with_texture(value.clone()) + .with_font(ctx.font.unwrap_or_else(|| ctx.build_context.default_font())) + .with_font_size( + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build( ctx.build_context, environment.sender.clone(), diff --git a/editor/src/plugins/inspector/editors/triangle_buffer.rs b/editor/src/plugins/inspector/editors/triangle_buffer.rs index ebe18cddc..a30e606ad 100644 --- a/editor/src/plugins/inspector/editors/triangle_buffer.rs +++ b/editor/src/plugins/inspector/editors/triangle_buffer.rs @@ -29,6 +29,7 @@ use crate::fyrox::{ InspectorError, PropertyChanged, }, message::UiMessage, + style::{resource::StyleResourceExt, Style}, text::{TextBuilder, TextMessage}, widget::WidgetBuilder, Thickness, VerticalAlignment, @@ -65,6 +66,11 @@ impl PropertyEditorDefinition for TriangleBufferPropertyEditorDefinition { .with_vertical_alignment(VerticalAlignment::Center), ) .with_text(triangle_buffer_description(value)) + .with_font(ctx.font.unwrap_or_else(|| ctx.build_context.default_font())) + .with_font_size( + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build(ctx.build_context), )) } diff --git a/editor/src/plugins/inspector/editors/vertex_buffer.rs b/editor/src/plugins/inspector/editors/vertex_buffer.rs index 5e1324f64..530e42c3c 100644 --- a/editor/src/plugins/inspector/editors/vertex_buffer.rs +++ b/editor/src/plugins/inspector/editors/vertex_buffer.rs @@ -18,6 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +use fyrox::gui::style::Style; + use crate::fyrox::{ gui::{ inspector::{ @@ -28,6 +30,7 @@ use crate::fyrox::{ InspectorError, PropertyChanged, }, message::UiMessage, + style::resource::StyleResourceExt, text::{TextBuilder, TextMessage}, widget::WidgetBuilder, Thickness, VerticalAlignment, @@ -65,6 +68,11 @@ impl PropertyEditorDefinition for VertexBufferPropertyEditorDefinition { .with_vertical_alignment(VerticalAlignment::Center), ) .with_text(vertex_buffer_description(value)) + .with_font(ctx.font.unwrap_or_else(|| ctx.build_context.default_font())) + .with_font_size( + ctx.font_size + .unwrap_or_else(|| ctx.build_context.style.property(Style::FONT_SIZE)), + ) .build(ctx.build_context), )) } diff --git a/editor/src/plugins/inspector/mod.rs b/editor/src/plugins/inspector/mod.rs index e92508b0a..93c514887 100644 --- a/editor/src/plugins/inspector/mod.rs +++ b/editor/src/plugins/inspector/mod.rs @@ -61,6 +61,15 @@ use crate::{ utils::window_content, Editor, Message, WidgetMessage, WrapMode, }; +use fyrox::gui::button::Button; +use fyrox::gui::stack_panel::StackPanel; +use fyrox::gui::text::Text; +use fyrox::gui::utils::ImageButtonBuilder; +use fyrox::gui::window::Window; +use fyrox::{ + core::{color::Color, err}, + gui::{font::FontResource, style::StyledProperty}, +}; use std::{any::Any, sync::mpsc::Sender, sync::Arc}; pub mod editors; @@ -120,6 +129,8 @@ pub struct InspectorPlugin { type_name_text: Handle, docs_button: Handle