more typed handles for widgets

This commit is contained in:
Dmitry Stepanov
2026-01-22 19:34:37 +03:00
parent 66b78b2e8a
commit da549573f9
30 changed files with 144 additions and 139 deletions
+2 -1
View File
@@ -69,6 +69,7 @@ use crate::{
Message, Mode,
};
use fyrox::asset::event::ResourceEvent;
use fyrox::gui::file_browser::FileBrowser;
use fyrox::gui::grid::Grid;
use fyrox::gui::scroll_viewer::ScrollViewer;
use fyrox::gui::searchbar::SearchBar;
@@ -159,7 +160,7 @@ pub struct AssetBrowser {
pub window: Handle<Window>,
pub docking_manager: Handle<UiNode>,
content_panel: Handle<WrapPanel>,
folder_browser: Handle<UiNode>,
folder_browser: Handle<FileBrowser>,
scroll_viewer: Handle<ScrollViewer>,
search_bar: Handle<SearchBar>,
add_resource: Handle<Button>,
+6 -5
View File
@@ -48,6 +48,7 @@ use crate::{
Engine, Message,
};
use fyrox::gui::button::Button;
use fyrox::gui::file_browser::FileSelector;
use fyrox::gui::list_view::ListView;
use fyrox::gui::text_box::TextBox;
use fyrox::gui::window::Window;
@@ -62,7 +63,7 @@ pub const HISTORY_PATH: &str = "history.bin";
pub struct Configurator {
pub window: Handle<Window>,
work_dir_browser: Handle<UiNode>,
work_dir_selector: Handle<FileSelector>,
select_work_dir: Handle<Button>,
ok: Handle<Button>,
sender: MessageSender,
@@ -101,7 +102,7 @@ impl Configurator {
let current_path = env::current_dir().unwrap();
let folder_browser = FileSelectorBuilder::new(
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")),
@@ -258,7 +259,7 @@ impl Configurator {
Self {
window,
work_dir_browser: folder_browser,
work_dir_selector,
select_work_dir,
ok,
sender,
@@ -302,7 +303,7 @@ impl Configurator {
} else if let Some(FileSelectorMessage::Commit(path)) =
message.data::<FileSelectorMessage>()
{
if message.destination() == self.work_dir_browser {
if message.destination() == self.work_dir_selector {
if let Ok(work_dir) = path.clone().canonicalize() {
self.work_dir = work_dir;
engine.user_interfaces.first().send(
@@ -342,7 +343,7 @@ impl Configurator {
.send(self.window, WindowMessage::Close);
} else if message.destination() == self.select_work_dir {
engine.user_interfaces.first().send(
self.work_dir_browser,
self.work_dir_selector,
WindowMessage::Open {
alignment: WindowAlignment::Center,
modal: true,
+2 -2
View File
@@ -181,7 +181,7 @@ use crate::{
use fyrox::core::{info, uuid};
use fyrox::engine::GraphicsContext;
use fyrox::event_loop::ActiveEventLoop;
use fyrox::gui::file_browser::{FileSelectorMode, FileType, PathFilter};
use fyrox::gui::file_browser::{FileSelector, FileSelectorMode, FileType, PathFilter};
use fyrox::gui::grid::Grid;
use fyrox::gui::inspector::editors::PropertyEditorDefinitionContainer;
use fyrox::gui::messagebox::MessageBox;
@@ -313,7 +313,7 @@ pub fn make_save_file_selector(
default_file_name: PathBuf,
file_type: FileType,
id: Uuid,
) -> Handle<UiNode> {
) -> Handle<FileSelector> {
FileSelectorBuilder::new(
WindowBuilder::new(
WidgetBuilder::new()
+4 -3
View File
@@ -31,7 +31,7 @@ use crate::{
messagebox::{MessageBoxBuilder, MessageBoxButtons, MessageBoxMessage},
widget::{WidgetBuilder, WidgetMessage},
window::{WindowAlignment, WindowBuilder, WindowMessage, WindowTitle},
BuildContext, UiNode, UserInterface,
BuildContext, UserInterface,
},
},
load_image, make_save_file_selector,
@@ -41,6 +41,7 @@ use crate::{
settings::{recent::RecentFiles, Settings},
Engine, Message, Mode, Panels, SaveSceneConfirmationDialogAction,
};
use fyrox::gui::file_browser::FileSelector;
use fyrox::gui::menu::MenuItem;
use fyrox::gui::messagebox::MessageBox;
use std::{path::PathBuf, sync::mpsc::Sender};
@@ -56,8 +57,8 @@ pub struct FileMenu {
pub close_scene: Handle<MenuItem>,
pub exit: Handle<MenuItem>,
pub configure: Handle<MenuItem>,
pub save_file_selector: Handle<UiNode>,
pub load_file_selector: Handle<UiNode>,
pub save_file_selector: Handle<FileSelector>,
pub load_file_selector: Handle<FileSelector>,
pub configure_message: Handle<MessageBox>,
pub recent_files_container: Handle<MenuItem>,
pub recent_files: Vec<Handle<MenuItem>>,
+2 -2
View File
@@ -615,7 +615,7 @@ impl AbsmCanvasBuilder {
Self { widget_builder }
}
pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
pub fn build(self, ctx: &mut BuildContext) -> Handle<AbsmCanvas> {
let canvas = AbsmCanvas {
widget: self
.widget_builder
@@ -632,7 +632,7 @@ impl AbsmCanvasBuilder {
lmb_released_node: Default::default(),
};
ctx.add_node(UiNode::new(canvas))
ctx.add(canvas)
}
}
+4 -2
View File
@@ -34,7 +34,9 @@ use crate::fyrox::{
};
use crate::plugins::absm::segment::Segment;
use crate::utils::fetch_node_screen_center;
use fyrox::graph::SceneGraph;
use crate::plugins::absm::canvas::AbsmCanvas;
use crate::plugins::absm::socket::Socket;
use fyrox::material::MaterialResource;
@@ -151,8 +153,8 @@ impl ConnectionBuilder {
self
}
pub fn build(self, canvas: Handle<UiNode>, ctx: &mut BuildContext) -> Handle<Connection> {
let canvas_ref = ctx.try_get_node(canvas);
pub fn build(self, canvas: Handle<AbsmCanvas>, ctx: &mut BuildContext) -> Handle<Connection> {
let canvas_ref = ctx.inner().try_get(canvas).ok();
let connection = Connection {
widget: self
+6 -13
View File
@@ -58,7 +58,7 @@ pub struct CanvasContextMenu {
create_state: Handle<MenuItem>,
connect_all_nodes: Handle<MenuItem>,
pub menu: RcUiNodeHandle,
pub canvas: Handle<UiNode>,
pub canvas: Handle<AbsmCanvas>,
pub node_context_menu: Option<RcUiNodeHandle>,
}
@@ -129,7 +129,7 @@ impl CanvasContextMenu {
absm_node_handle,
layer_index,
State {
position: ui.node(self.canvas).screen_to_local(screen_position),
position: ui[self.canvas].screen_to_local(screen_position),
name: "New State".to_string(),
on_enter_actions: Default::default(),
on_leave_actions: Default::default(),
@@ -137,10 +137,7 @@ impl CanvasContextMenu {
},
));
} else if message.destination() == self.connect_all_nodes {
let canvas = ui
.node(self.canvas)
.query_component::<AbsmCanvas>()
.unwrap();
let canvas = &ui[self.canvas];
let state_nodes = canvas.children();
let mut states = Vec::default();
for source in state_nodes {
@@ -178,7 +175,7 @@ pub struct NodeContextMenu {
enter_state: Handle<MenuItem>,
connect_to_all_nodes: Handle<MenuItem>,
pub menu: RcUiNodeHandle,
pub canvas: Handle<UiNode>,
pub canvas: Handle<AbsmCanvas>,
placement_target: Handle<UiNode>,
}
@@ -273,7 +270,7 @@ impl NodeContextMenu {
AbsmCanvasMessage::SwitchMode(Mode::CreateTransition {
source: self.placement_target,
source_pos: ui.node(self.placement_target).center(),
dest_pos: ui.node(self.canvas).screen_to_local(ui.cursor_position()),
dest_pos: ui[self.canvas].screen_to_local(ui.cursor_position()),
}),
)
} else if message.destination == self.remove {
@@ -344,11 +341,7 @@ impl NodeContextMenu {
} else if message.destination == self.enter_state {
ui.post(self.placement_target, AbsmNodeMessage::Enter);
} else if message.destination == self.connect_to_all_nodes {
let canvas = ui
.node(self.canvas)
.cast::<AbsmCanvas>()
.expect("Must be absm canvas");
let canvas = &ui[self.canvas];
let state_nodes = canvas
.children()
.iter()
+8 -16
View File
@@ -57,7 +57,7 @@ mod context;
pub struct StateGraphViewer {
pub window: Handle<Window>,
pub canvas: Handle<UiNode>,
pub canvas: Handle<AbsmCanvas>,
canvas_context_menu: CanvasContextMenu,
node_context_menu: NodeContextMenu,
transition_context_menu: TransitionContextMenu,
@@ -120,7 +120,7 @@ impl StateGraphViewer {
}
pub fn clear(&self, ui: &UserInterface) {
for &child in ui.node(self.canvas).children() {
for &child in ui[self.canvas].children() {
ui.send(child, WidgetMessage::Remove);
}
}
@@ -132,7 +132,7 @@ impl StateGraphViewer {
) where
N: Reflect,
{
if let Some(view_handle) = ui.node(self.canvas).children().iter().cloned().find(|c| {
if let Some(view_handle) = ui[self.canvas].children().iter().cloned().find(|c| {
ui.node(*c)
.query_component::<TransitionView>()
.is_some_and(|transition_view_ref| {
@@ -148,12 +148,8 @@ impl StateGraphViewer {
where
N: Reflect,
{
for (state_view_handle, state_view_ref) in ui
.node(self.canvas)
.children()
.iter()
.cloned()
.filter_map(|c| {
for (state_view_handle, state_view_ref) in
ui[self.canvas].children().iter().cloned().filter_map(|c| {
ui.node(c)
.query_component::<AbsmNode<State<Handle<N>>>>()
.map(|state_view_ref| (c, state_view_ref))
@@ -310,11 +306,7 @@ impl StateGraphViewer {
G: SceneGraph<Node = N, Prefab = P>,
N: SceneGraphNode<SceneGraph = G, ResourceData = P>,
{
let canvas = ui
.node(self.canvas)
.cast::<AbsmCanvas>()
.expect("Must be AbsmCanvas!");
let canvas = &ui[self.canvas];
let current_selection = fetch_selection(editor_selection);
let mut states = Vec::new();
@@ -376,7 +368,7 @@ impl StateGraphViewer {
states.push(state_view_handle.to_base());
ui.send_sync(state_view_handle, WidgetMessage::LinkWith(self.canvas));
ui.send_sync(state_view_handle, WidgetMessage::link_with(self.canvas));
}
}
}
@@ -479,7 +471,7 @@ impl StateGraphViewer {
.with_dest(find_state_view(transition.dest(), &states, ui).to_base())
.build(transition_handle.into(), &mut ui.build_ctx());
ui.send_sync(transition_view, WidgetMessage::LinkWith(self.canvas));
ui.send_sync(transition_view, WidgetMessage::link_with(self.canvas));
ui.send_sync(transition_view, WidgetMessage::Lowermost);
transitions.push(transition_view);
@@ -35,6 +35,7 @@ use crate::fyrox::{
BuildContext, RcUiNodeHandle, UiNode, UserInterface,
},
};
use crate::plugins::absm::canvas::AbsmCanvas;
use crate::plugins::absm::{
command::{
blend::{
@@ -62,7 +63,7 @@ pub struct CanvasContextMenu {
create_blend_by_index: Handle<MenuItem>,
create_blend_space: Handle<MenuItem>,
pub menu: RcUiNodeHandle,
pub canvas: Handle<UiNode>,
pub canvas: Handle<AbsmCanvas>,
pub node_context_menu: Option<RcUiNodeHandle>,
}
@@ -147,9 +148,8 @@ impl CanvasContextMenu {
layer_index: usize,
) {
if let Some(MenuItemMessage::Click) = message.data() {
let position = ui
.node(self.canvas)
.screen_to_local(ui.node(self.menu.handle()).screen_position());
let position =
ui[self.canvas].screen_to_local(ui.node(self.menu.handle()).screen_position());
let pose_node = if message.destination() == self.create_play_animation {
Some(PoseNode::PlayAnimation(PlayAnimation {
@@ -225,7 +225,7 @@ pub struct NodeContextMenu {
remove: Handle<MenuItem>,
set_as_root: Handle<MenuItem>,
pub menu: RcUiNodeHandle,
pub canvas: Handle<UiNode>,
pub canvas: Handle<AbsmCanvas>,
placement_target: Handle<UiNode>,
}
+8 -8
View File
@@ -57,6 +57,7 @@ use crate::plugins::absm::{
};
use crate::scene::{commands::ChangeSelectionCommand, Selection};
use crate::plugins::absm::canvas::AbsmCanvas;
use fyrox::core::reflect::Reflect;
use fyrox::gui::style::resource::StyleResourceExt;
use fyrox::gui::style::Style;
@@ -67,7 +68,7 @@ mod context;
pub struct StateViewer {
pub window: Handle<Window>,
canvas: Handle<UiNode>,
canvas: Handle<AbsmCanvas>,
state: ErasedHandle,
canvas_context_menu: CanvasContextMenu,
node_context_menu: NodeContextMenu,
@@ -253,7 +254,7 @@ impl StateViewer {
pub fn clear(&mut self, ui: &UserInterface) {
self.state = Default::default();
for &child in ui.node(self.canvas).children() {
for &child in ui[self.canvas].children() {
ui.send(child, WidgetMessage::Remove);
}
@@ -431,8 +432,7 @@ impl StateViewer {
self.prev_absm = current_selection.absm_node_handle.into();
self.clear(ui);
} else {
views = ui
.node(self.canvas)
views = ui[self.canvas]
.children()
.iter()
.cloned()
@@ -547,7 +547,7 @@ impl StateViewer {
.with_model_handle(pose_definition)
.build(&mut ui.build_ctx());
ui.send_sync(node_view, WidgetMessage::LinkWith(self.canvas));
ui.send_sync(node_view, WidgetMessage::link_with(self.canvas));
views.push(node_view.to_base());
}
@@ -632,7 +632,7 @@ impl StateViewer {
// Sync connections - remove old ones and create new. Since there is no separate data model
// for connection we can't find which connection has changed and sync only it, instead we
// removing every connection and create new.
for child in ui.node(self.canvas).children().iter().cloned() {
for child in ui[self.canvas].children().iter().cloned() {
if ui.node(child).has_component::<Connection>() {
ui.send_sync(child, WidgetMessage::Remove);
}
@@ -675,7 +675,7 @@ impl StateViewer {
.with_dest_node(dest_handle)
.build(self.canvas, &mut ui.build_ctx());
ui.send_sync(connection, WidgetMessage::LinkWith(self.canvas));
ui.send_sync(connection, WidgetMessage::link_with(self.canvas));
ui.send_sync(connection, WidgetMessage::Lowermost);
}
}
@@ -707,7 +707,7 @@ impl StateViewer {
ui.send_sync(self.canvas, AbsmCanvasMessage::ForceSyncDependentObjects);
} else {
// Clean the canvas.
for child in ui.node(self.canvas).children() {
for child in ui[self.canvas].children() {
ui.send_sync(*child, WidgetMessage::Remove);
}
}
+2 -1
View File
@@ -70,6 +70,7 @@ use crate::{
},
};
use fyrox::gui::check_box::CheckBox;
use fyrox::gui::file_browser::FileSelector;
use fyrox::gui::numeric::NumericUpDown;
use fyrox::gui::popup::Popup;
use fyrox::gui::text::Text;
@@ -97,7 +98,7 @@ pub struct Toolbar {
pub import: Handle<Button>,
pub reimport: Handle<Button>,
pub node_selector: Handle<UiNode>,
pub import_file_selector: Handle<UiNode>,
pub import_file_selector: Handle<FileSelector>,
pub selected_import_root: ErasedHandle,
pub looping: Handle<CheckBox>,
pub enabled: Handle<CheckBox>,
+3 -3
View File
@@ -51,7 +51,7 @@ use crate::{
use fyrox::asset::manager::ResourceManager;
use fyrox::core::some_or_return;
use fyrox::gui::button::Button;
use fyrox::gui::file_browser::{FileSelectorMode, FileType};
use fyrox::gui::file_browser::{FileSelector, FileSelectorMode, FileType};
use fyrox::gui::menu::MenuItem;
use fyrox::gui::messagebox::MessageBox;
use fyrox::gui::style::resource::StyleResourceExt;
@@ -114,8 +114,8 @@ pub struct CurveEditorWindow {
curve_resource: Option<CurveResource>,
command_stack: CommandStack,
menu: Menu,
load_file_selector: Handle<UiNode>,
save_file_selector: Handle<UiNode>,
load_file_selector: Handle<FileSelector>,
save_file_selector: Handle<FileSelector>,
path: PathBuf,
save_changes_message_box: Handle<MessageBox>,
cancel_message_box: Handle<MessageBox>,
@@ -102,7 +102,10 @@ impl Control for SpriteSheetFramesPropertyEditor {
}
impl SpriteSheetFramesPropertyEditor {
pub fn build(ctx: &mut BuildContext, container: SpriteSheetFramesContainer) -> Handle<UiNode> {
pub fn build(
ctx: &mut BuildContext,
container: SpriteSheetFramesContainer,
) -> Handle<SpriteSheetFramesPropertyEditor> {
let edit_button;
let grid = GridBuilder::new(
WidgetBuilder::new()
@@ -132,11 +135,11 @@ impl SpriteSheetFramesPropertyEditor {
.add_column(Column::auto())
.build(ctx);
ctx.add_node(UiNode::new(Self {
ctx.add(Self {
widget: WidgetBuilder::new().with_child(grid).build(ctx),
edit_button,
container,
}))
})
}
}
@@ -155,7 +158,7 @@ impl PropertyEditorDefinition for SpriteSheetFramesContainerEditorDefinition {
let editor = SpriteSheetFramesPropertyEditor::build(ctx.build_context, value.clone());
Ok(PropertyEditorInstance::Simple { editor })
Ok(PropertyEditorInstance::simple(editor))
}
fn create_message(
@@ -246,7 +246,7 @@ impl SpriteSheetFramesEditorWindow {
ctx: &mut BuildContext,
container: SpriteSheetFramesContainer,
editor: Handle<UiNode>,
) -> Handle<UiNode> {
) -> Handle<SpriteSheetFramesEditorWindow> {
let ok;
let cancel;
let width;
@@ -415,6 +415,6 @@ impl SpriteSheetFramesEditorWindow {
preview_image,
};
ctx.add_node(UiNode::new(editor))
ctx.add(editor)
}
}
@@ -284,15 +284,15 @@ impl SurfaceDataPropertyEditor {
image_preview,
};
let handle = ctx.add_node(UiNode::new(editor));
let handle = ctx.add(editor);
Log::verify(icon_request_sender.send(IconRequest {
widget_handle: handle,
widget_handle: handle.to_base(),
resource: surface_resource.into_untyped(),
force_update: false,
}));
handle.to_variant()
handle
}
}
@@ -72,7 +72,7 @@ struct TextureContextMenu {
}
impl TextureContextMenu {
fn new(owner: Handle<UiNode>, ctx: &mut BuildContext) -> Self {
fn new(owner: Handle<TextureEditor>, ctx: &mut BuildContext) -> Self {
let show_in_asset_browser;
let unassign;
let popup = ContextMenuBuilder::new(
@@ -96,7 +96,7 @@ impl TextureContextMenu {
.build(ctx),
)
.with_restrict_picking(false)
.with_owner(owner),
.with_owner(owner.to_base()),
)
.build(ctx);
let popup = RcUiNodeHandle::new(popup, ctx.sender());
@@ -312,13 +312,10 @@ impl TextureEditorBuilder {
texture_context_menu: None,
};
let editor = ctx.add_node(UiNode::new(editor));
let editor = ctx.add(editor);
let texture_context_menu = TextureContextMenu::new(editor, ctx);
let editor_mut = ctx
.inner_mut()
.try_get_mut_of_type::<TextureEditor>(editor)
.unwrap();
let editor_mut = &mut ctx.inner_mut()[editor];
editor_mut.context_menu = Some(texture_context_menu.popup.clone());
editor_mut.texture_context_menu = Some(texture_context_menu);
+2 -2
View File
@@ -38,7 +38,7 @@ use crate::{
};
use fyrox::core::pool::ObjectOrVariant;
use fyrox::gui::button::Button;
use fyrox::gui::file_browser::{FileSelectorMode, FileType};
use fyrox::gui::file_browser::{FileSelector, FileSelectorMode, FileType};
use fyrox::gui::texture::TextureResource;
use fyrox::gui::utils::make_image_button_with_tooltip;
use std::{fs::File, path::Path};
@@ -109,7 +109,7 @@ pub fn create_file_selector(
ctx: &mut BuildContext,
file_type: FileType,
mode: FileSelectorMode,
) -> Handle<UiNode> {
) -> Handle<FileSelector> {
FileSelectorBuilder::new(
WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(400.0)).open(false),
)
+2 -2
View File
@@ -60,7 +60,7 @@ use crate::{
Engine, Message, PasteCommand,
};
use fyrox::core::{uuid, Uuid};
use fyrox::gui::file_browser::FileType;
use fyrox::gui::file_browser::{FileSelector, FileType};
use fyrox::gui::menu::MenuItem;
use fyrox::gui::window::WindowAlignment;
use std::{any::TypeId, path::PathBuf};
@@ -74,7 +74,7 @@ pub struct SceneNodeContextMenu {
replace_with_menu: CreateEntityMenu,
placement_target: Handle<UiNode>,
save_as_prefab: Handle<MenuItem>,
save_as_prefab_dialog: Handle<UiNode>,
save_as_prefab_dialog: Handle<FileSelector>,
paste: Handle<MenuItem>,
make_root: Handle<MenuItem>,
open_asset: Handle<MenuItem>,
+2 -1
View File
@@ -19,6 +19,7 @@
// SOFTWARE.
use crate::button::Button;
use crate::file_browser::FileSelector;
use crate::text_box::TextBox;
use crate::{
button::{ButtonBuilder, ButtonMessage},
@@ -56,7 +57,7 @@ pub struct FileSelectorField {
path: PathBuf,
path_field: Handle<TextBox>,
select: Handle<Button>,
file_selector: Handle<UiNode>,
file_selector: Handle<FileSelector>,
}
impl ConstructorProvider<UiNode, UserInterface> for FileSelectorField {
+7 -8
View File
@@ -133,6 +133,7 @@ impl ConstructorProvider<UiNode, UserInterface> for FileBrowser {
.with_variant("File Browser", |ui| {
FileBrowserBuilder::new(WidgetBuilder::new().with_name("File Browser"))
.build(&mut ui.build_ctx())
.to_base()
.into()
})
.with_group("File System")
@@ -623,7 +624,7 @@ impl FileBrowserBuilder {
self
}
pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
pub fn build(self, ctx: &mut BuildContext) -> Handle<FileBrowser> {
let item_context_menu = RcUiNodeHandle::new(ItemContextMenu::build(ctx), ctx.sender());
let fs_tree::FsTree {
@@ -769,18 +770,16 @@ impl FileBrowserBuilder {
no_items_message,
fs_events: Default::default(),
};
let file_browser_handle = ctx.add_node(UiNode::new(browser));
let file_browser_handle = ctx.add(browser);
let sender = ctx.sender();
ctx[file_browser_handle]
.cast_mut::<FileBrowser>()
.unwrap()
.watcher = setup_file_browser_fs_watcher(sender, file_browser_handle, the_path);
ctx[file_browser_handle].watcher =
setup_file_browser_fs_watcher(sender, file_browser_handle, the_path);
file_browser_handle
}
}
struct EventReceiver {
file_browser_handle: Handle<UiNode>,
file_browser_handle: Handle<FileBrowser>,
sender: Sender<UiMessage>,
}
@@ -820,7 +819,7 @@ impl notify::EventHandler for EventReceiver {
fn setup_file_browser_fs_watcher(
sender: Sender<UiMessage>,
file_browser_handle: Handle<UiNode>,
file_browser_handle: Handle<FileBrowser>,
the_path: PathBuf,
) -> Option<notify::RecommendedWatcher> {
let handler = EventReceiver {
+5 -3
View File
@@ -20,6 +20,7 @@
use crate::button::Button;
use crate::dropdown_list::DropdownList;
use crate::file_browser::FileBrowser;
use crate::messagebox::MessageBox;
use crate::text_box::TextBox;
use crate::{
@@ -79,7 +80,7 @@ impl MessageData for FileSelectorMessage {}
pub struct FileSelector {
#[component(include)]
pub window: Window,
pub browser: Handle<UiNode>,
pub browser: Handle<FileBrowser>,
pub ok: Handle<Button>,
pub cancel: Handle<Button>,
pub selected_folder: PathBuf,
@@ -100,6 +101,7 @@ impl ConstructorProvider<UiNode, UserInterface> for FileSelector {
WidgetBuilder::new().with_name("File Selector"),
))
.build(&mut ui.build_ctx())
.to_base()
.into()
})
.with_group("File System")
@@ -355,7 +357,7 @@ impl FileSelectorBuilder {
self
}
pub fn build(mut self, ctx: &mut BuildContext) -> Handle<UiNode> {
pub fn build(mut self, ctx: &mut BuildContext) -> Handle<FileSelector> {
let browser;
let ok;
let cancel;
@@ -561,7 +563,7 @@ impl FileSelectorBuilder {
overwrite_message_box: Default::default(),
};
ctx.add_node(UiNode::new(file_selector))
ctx.add(file_selector)
}
}
+6 -3
View File
@@ -246,7 +246,7 @@ where
name_column_width: f32,
base_path: String,
has_parent_object: bool,
) -> Result<Handle<UiNode>, InspectorError> {
) -> Result<Handle<ArrayEditor>, InspectorError> {
let definition_container = self
.definition_container
.unwrap_or_else(|| Arc::new(PropertyEditorDefinitionContainer::with_default_editors()));
@@ -279,7 +279,7 @@ where
items,
};
Ok(ctx.add_node(UiNode::new(ce)))
Ok(ctx.add(ce))
}
}
@@ -355,7 +355,10 @@ where
ctx.build_context,
);
Ok(PropertyEditorInstance::Custom { container, editor })
Ok(PropertyEditorInstance::Custom {
container,
editor: editor.to_base(),
})
}
fn create_message(
+6 -3
View File
@@ -376,7 +376,7 @@ where
name_column_width: f32,
base_path: String,
has_parent_object: bool,
) -> Result<Handle<UiNode>, InspectorError> {
) -> Result<Handle<CollectionEditor<T>>, InspectorError> {
let definition_container = self
.definition_container
.unwrap_or_else(|| Arc::new(PropertyEditorDefinitionContainer::with_default_editors()));
@@ -419,7 +419,7 @@ where
phantom: PhantomData,
};
Ok(ctx.add_node(UiNode::new(ce)))
Ok(ctx.add(ce))
}
}
@@ -509,7 +509,10 @@ where
ctx.build_context,
);
Ok(PropertyEditorInstance::Custom { container, editor })
Ok(PropertyEditorInstance::Custom {
container,
editor: editor.to_base(),
})
}
fn create_message(
@@ -262,7 +262,7 @@ impl EnumPropertyEditorBuilder {
name_column_width: f32,
base_path: String,
has_parent_object: bool,
) -> Handle<UiNode> {
) -> Handle<EnumPropertyEditor<T>> {
let definition_container = self
.definition_container
.unwrap_or_else(|| Arc::new(PropertyEditorDefinitionContainer::with_default_editors()));
@@ -303,7 +303,7 @@ impl EnumPropertyEditorBuilder {
has_parent_object,
};
ctx.add_node(UiNode::new(editor))
ctx.add(editor)
}
}
@@ -426,7 +426,10 @@ where
ctx.build_context,
);
Ok(PropertyEditorInstance::Custom { container, editor })
Ok(PropertyEditorInstance::Custom {
container,
editor: editor.to_base(),
})
}
fn create_message(
+5 -4
View File
@@ -142,7 +142,7 @@ impl InheritablePropertyEditorBuilder {
self
}
pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
pub fn build(self, ctx: &mut BuildContext) -> Handle<InheritablePropertyEditor> {
let revert;
let grid = GridBuilder::new(WidgetBuilder::new().with_child(self.container).with_child({
revert = ButtonBuilder::new(
@@ -174,11 +174,11 @@ impl InheritablePropertyEditorBuilder {
.add_column(Column::auto())
.build(ctx);
ctx.add_node(UiNode::new(InheritablePropertyEditor {
ctx.add(InheritablePropertyEditor {
widget: self.widget_builder.with_child(grid).build(ctx),
revert,
inner_editor: self.inner_editor,
}))
})
}
}
@@ -279,7 +279,8 @@ where
.cast_value::<InheritableVariable<T>>()?
.is_modified(),
)
.build(ctx.build_context);
.build(ctx.build_context)
.to_base();
Ok(match instance {
PropertyEditorInstance::Simple { .. } => {
+9 -8
View File
@@ -190,7 +190,7 @@ impl StyledPropertySelectorBuilder {
target_type: TypeId,
style_property_name: ImmutableString,
ctx: &mut BuildContext,
) -> Handle<UiNode> {
) -> Handle<StyledPropertySelector> {
let style_data = target_style.data_ref();
let (items, property_list): (Vec<_>, Vec<_>) = style_data
.all_properties()
@@ -274,7 +274,7 @@ impl StyledPropertySelectorBuilder {
);
}
ctx.add_node(UiNode::new(selector))
ctx.add(selector)
}
pub fn build_and_open_window(
@@ -282,7 +282,7 @@ impl StyledPropertySelectorBuilder {
target_type: TypeId,
style_property_name: ImmutableString,
ctx: &mut BuildContext,
) -> Handle<UiNode> {
) -> Handle<StyledPropertySelector> {
let window = StyledPropertySelectorBuilder::new(
WindowBuilder::new(WidgetBuilder::new().with_width(300.0).with_height(200.0))
.with_title(WindowTitle::text("Select A Style Property"))
@@ -311,7 +311,7 @@ pub struct StyledPropertyEditor {
widget: Widget,
bind: Handle<Button>,
inner_editor: Handle<UiNode>,
selector: Handle<UiNode>,
selector: Handle<StyledPropertySelector>,
target_style: Option<StyleResource>,
style_property_name: ImmutableString,
#[visit(skip)]
@@ -408,7 +408,7 @@ impl StyledPropertyEditorBuilder {
self
}
pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
pub fn build(self, ctx: &mut BuildContext) -> Handle<StyledPropertyEditor> {
let is_bound = !self.style_property_name.is_empty();
let brush = if is_bound {
ctx.style.property(Style::BRUSH_BRIGHT_BLUE)
@@ -452,7 +452,7 @@ impl StyledPropertyEditorBuilder {
.add_column(Column::auto())
.build(ctx);
ctx.add_node(UiNode::new(StyledPropertyEditor {
ctx.add(StyledPropertyEditor {
widget: self
.widget_builder
.with_preview_messages(true)
@@ -464,7 +464,7 @@ impl StyledPropertyEditorBuilder {
target_style: self.target_style,
style_property_name: self.style_property_name,
target_type_id: self.target_type_id,
}))
})
}
}
@@ -565,7 +565,8 @@ where
.flatten()
}))
.with_style_property_name(value.name.clone())
.build(ctx.build_context);
.build(ctx.build_context)
.to_base();
Ok(match instance {
PropertyEditorInstance::Simple { .. } => {
+20 -16
View File
@@ -440,7 +440,7 @@ impl TextureSliceEditorBuilder {
self
}
pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
pub fn build(self, ctx: &mut BuildContext) -> Handle<TextureSliceEditor> {
let region_min_thumb =
make_thumb(self.slice.texture_region.position, self.handle_size, ctx);
let region_max_thumb = make_thumb(
@@ -451,7 +451,7 @@ impl TextureSliceEditorBuilder {
let slice_min_thumb = make_thumb(self.slice.margin_min(), self.handle_size, ctx);
let slice_max_thumb = make_thumb(self.slice.margin_max(), self.handle_size, ctx);
ctx.add_node(UiNode::new(TextureSliceEditor {
ctx.add(TextureSliceEditor {
widget: self
.widget_builder
.with_child(region_min_thumb)
@@ -467,7 +467,7 @@ impl TextureSliceEditorBuilder {
slice_max_thumb,
drag_context: None,
scale: 1.0,
}))
})
}
}
@@ -477,7 +477,7 @@ impl TextureSliceEditorBuilder {
pub struct TextureSliceEditorWindow {
window: Window,
parent_editor: Handle<UiNode>,
slice_editor: Handle<UiNode>,
slice_editor: Handle<TextureSliceEditor>,
texture_slice: TextureSlice,
left_margin: Handle<NumericUpDown<u32>>,
right_margin: Handle<NumericUpDown<u32>>,
@@ -595,7 +595,11 @@ impl TextureSliceEditorWindowBuilder {
self
}
pub fn build(self, parent_editor: Handle<UiNode>, ctx: &mut BuildContext) -> Handle<UiNode> {
pub fn build(
self,
parent_editor: Handle<UiNode>,
ctx: &mut BuildContext,
) -> Handle<TextureSliceEditorWindow> {
let region_text = TextBuilder::new(WidgetBuilder::new())
.with_text("Texture Region")
.build(ctx);
@@ -675,7 +679,7 @@ impl TextureSliceEditorWindowBuilder {
.add_row(Row::stretch())
.build(ctx);
let node = UiNode::new(TextureSliceEditorWindow {
let node = TextureSliceEditorWindow {
window: self.window_builder.with_content(content).build_window(ctx),
parent_editor,
slice_editor,
@@ -685,9 +689,9 @@ impl TextureSliceEditorWindowBuilder {
top_margin,
bottom_margin,
region,
});
};
ctx.add_node(node)
ctx.add(node)
}
}
@@ -698,7 +702,7 @@ pub struct TextureSliceFieldEditor {
widget: Widget,
texture_slice: TextureSlice,
edit: Handle<Button>,
editor: Handle<UiNode>,
editor: Handle<TextureSliceEditorWindow>,
}
define_widget_deref!(TextureSliceFieldEditor);
@@ -759,18 +763,18 @@ impl TextureSliceFieldEditorBuilder {
self
}
pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
pub fn build(self, ctx: &mut BuildContext) -> Handle<TextureSliceFieldEditor> {
let edit = ButtonBuilder::new(WidgetBuilder::new())
.with_text("Edit...")
.build(ctx);
let node = UiNode::new(TextureSliceFieldEditor {
let node = TextureSliceFieldEditor {
widget: self.widget_builder.with_child(edit).build(ctx),
texture_slice: self.texture_slice,
edit,
editor: Default::default(),
});
ctx.add_node(node)
};
ctx.add(node)
}
}
@@ -787,15 +791,15 @@ impl PropertyEditorDefinition for TextureSlicePropertyEditorDefinition {
ctx: PropertyEditorBuildContext,
) -> Result<PropertyEditorInstance, InspectorError> {
let value = ctx.property_info.cast_value::<TextureSlice>()?;
Ok(PropertyEditorInstance::Simple {
editor: TextureSliceFieldEditorBuilder::new(
Ok(PropertyEditorInstance::simple(
TextureSliceFieldEditorBuilder::new(
WidgetBuilder::new()
.with_margin(Thickness::top_bottom(1.0))
.with_vertical_alignment(VerticalAlignment::Center),
)
.with_texture_slice(value.clone())
.build(ctx.build_context),
})
))
}
fn create_message(
+2 -5
View File
@@ -186,15 +186,12 @@ impl UiNode {
/// }
///
/// impl MyWidgetBuilder {
/// pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
/// pub fn build(self, ctx: &mut BuildContext) -> Handle<MyWidget> {
/// let my_widget = MyWidget {
/// widget: self.widget_builder.build(ctx),
/// };
///
/// // Wrap your widget in the type-agnostic wrapper so it can be placed in the UI.
/// let node = UiNode::new(my_widget);
///
/// ctx.add_node(node)
/// ctx.add(my_widget)
/// }
/// }
/// ```
+2 -2
View File
@@ -24,7 +24,7 @@
#![warn(missing_docs)]
use crate::button::Button;
use crate::file_browser::PathFilter;
use crate::file_browser::{FileSelector, PathFilter};
use crate::text_box::TextBox;
use crate::{
button::{ButtonBuilder, ButtonMessage},
@@ -84,7 +84,7 @@ pub struct PathEditor {
/// A button, that opens a file selection.
pub select: InheritableVariable<Handle<Button>>,
/// Current file selector instance, could be [`Handle::NONE`] if the selector is closed.
pub selector: InheritableVariable<Handle<UiNode>>,
pub selector: InheritableVariable<Handle<FileSelector>>,
/// Current path.
pub path: InheritableVariable<PathBuf>,
/// Current filter that will be used in the file browser created by clicking on `...` button.
+2 -2
View File
@@ -28,7 +28,7 @@ use fyrox::core::pool::HandlesVecExtension;
use fyrox::gui::button::Button;
use fyrox::gui::check_box::CheckBox;
use fyrox::gui::decorator::Decorator;
use fyrox::gui::file_browser::{FileSelectorMode, PathFilter};
use fyrox::gui::file_browser::{FileSelector, FileSelectorMode, PathFilter};
use fyrox::gui::grid::Grid;
use fyrox::gui::list_view::ListView;
use fyrox::gui::messagebox::MessageBox;
@@ -147,7 +147,7 @@ pub struct ProjectManager {
pub settings: Settings,
project_wizard: Option<ProjectWizard>,
build_window: Option<BuildWindow>,
import_project_dialog: Handle<UiNode>,
import_project_dialog: Handle<FileSelector>,
pub mode: Mode,
search_text: String,
log: LogPanel,