Skip to content

Commit 3af7b07

Browse files
committed
typed handles for TabControl widget + fixes
1 parent f2ea086 commit 3af7b07

File tree

5 files changed

+39
-45
lines changed

5 files changed

+39
-45
lines changed

editor/src/plugins/tilemap/tileset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub struct TileSetEditor {
8888
cell_position: Handle<Text>,
8989
/// The control that allows the editor to switch between the tiles tab,
9090
/// the properties tab, and the colliders tabl.
91-
tab_control: Handle<UiNode>,
91+
tab_control: Handle<TabControl>,
9292
/// The palette widget for the page icons. It is used to select which page to edit.
9393
pages_palette: Handle<UiNode>,
9494
/// The palette widget for the actual tiles. This is the main work area of the editor.
@@ -522,7 +522,7 @@ impl TileSetEditor {
522522
}
523523

524524
fn send_tabs_visible(&self, is_tile_set: bool, ui: &mut UserInterface) {
525-
let tab_control = ui.node(self.tab_control).cast::<TabControl>().unwrap();
525+
let tab_control = &ui[self.tab_control];
526526
let tabs = tab_control.headers_container;
527527
let children = ui[tabs].children();
528528
for &tab in &children[1..3] {

editor/src/scene_viewer/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub struct SceneViewer {
277277
interaction_mode_panel: Handle<UiNode>,
278278
contextual_actions: Handle<UiNode>,
279279
no_scene_reminder: Handle<Text>,
280-
tab_control: Handle<UiNode>,
280+
tab_control: Handle<TabControl>,
281281
scene_gizmo: SceneGizmo,
282282
scene_gizmo_image: Handle<Image>,
283283
debug_switches: Handle<UiNode>,
@@ -885,12 +885,7 @@ impl SceneViewer {
885885
pub fn sync_to_model(&self, scenes: &SceneContainer, engine: &mut Engine) {
886886
// Sync tabs first.
887887

888-
let tabs = engine
889-
.user_interfaces
890-
.first_mut()
891-
.node(self.tab_control)
892-
.query_component::<TabControl>()
893-
.expect("Must be TabControl!")
888+
let tabs = engine.user_interfaces.first_mut()[self.tab_control]
894889
.tabs
895890
.clone();
896891
// Remove any excess tabs.

fyrox-ui/src/dock/tile.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub struct Tile {
271271
pub top_anchor: Handle<Border>,
272272
pub bottom_anchor: Handle<Border>,
273273
pub center_anchor: Handle<Border>,
274-
pub tabs: Handle<UiNode>,
274+
pub tabs: Handle<TabControl>,
275275
pub content: TileContent,
276276
pub splitter: Handle<Border>,
277277
pub dragging_splitter: bool,
@@ -304,7 +304,7 @@ impl Control for Tile {
304304
return self.measure_vertical_with_minimized(ui, available_size);
305305
}
306306
ui.measure_node(self.tabs, Vector2::new(available_size.x, f32::INFINITY));
307-
available_size.y -= ui.node(self.tabs).desired_size().y;
307+
available_size.y -= ui[self.tabs].desired_size().y;
308308
for &child_handle in self.children() {
309309
if child_handle == self.tabs {
310310
continue;
@@ -347,7 +347,7 @@ impl Control for Tile {
347347
TileContent::Empty => Vector2::default(),
348348
TileContent::Window(handle) => ui[*handle].desired_size(),
349349
TileContent::MultiWindow { index, windows } => {
350-
let tabs = ui.node(self.tabs).desired_size();
350+
let tabs = ui[self.tabs].desired_size();
351351
let body = windows
352352
.get(*index as usize)
353353
.map(|w| ui[*w].desired_size())
@@ -387,7 +387,7 @@ impl Control for Tile {
387387
return self.arrange_vertical_with_minimized(ui, final_size);
388388
}
389389

390-
let tabs_height = ui.node(self.tabs).desired_size().y;
390+
let tabs_height = ui[self.tabs].desired_size().y;
391391
ui.arrange_node(self.tabs, &Rect::new(0.0, 0.0, final_size.x, tabs_height));
392392
let full_bounds = Rect::new(0.0, tabs_height, final_size.x, final_size.y - tabs_height);
393393
for &child_handle in self.children() {
@@ -494,7 +494,7 @@ impl Control for Tile {
494494
}
495495
TileContent::MultiWindow { index, windows } => {
496496
send_visibility(ui, self.splitter, false);
497-
let tabs = ui.node(self.tabs).cast::<TabControl>().unwrap();
497+
let tabs = &ui[self.tabs];
498498
for tab in tabs.tabs.iter() {
499499
let uuid = tab.uuid;
500500
if !windows.iter().any(|&h| ui[h].id == uuid) {
@@ -507,7 +507,7 @@ impl Control for Tile {
507507
for (i, &w) in windows.iter().enumerate() {
508508
let is_active = i as u32 == *index;
509509
let uuid = ui[w].id;
510-
let tabs = ui.node(self.tabs).cast::<TabControl>().unwrap();
510+
let tabs = &ui[self.tabs];
511511
if tabs.get_tab_by_uuid(uuid).is_none() {
512512
self.add_tab(w, ui);
513513
}

fyrox-ui/src/tab_control.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ impl ConstructorProvider<UiNode, UserInterface> for TabControl {
257257
.with_variant("Tab Control", |ui| {
258258
TabControlBuilder::new(WidgetBuilder::new().with_name("Tab Control"))
259259
.build(&mut ui.build_ctx())
260+
.to_base()
260261
.into()
261262
})
262263
.with_group("Layout")
@@ -657,7 +658,7 @@ impl TabControlBuilder {
657658
}
658659

659660
/// Finishes [`TabControl`] building and adds it to the user interface and returns its handle.
660-
pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
661+
pub fn build(self, ctx: &mut BuildContext) -> Handle<TabControl> {
661662
let tab_count = self.tabs.len();
662663
// Hide everything but initial tab content.
663664
for (i, (_, tab)) in self.tabs.iter().enumerate() {
@@ -745,7 +746,7 @@ impl TabControlBuilder {
745746
active_tab_brush: active_tab_brush.into(),
746747
};
747748

748-
ctx.add_node(UiNode::new(tc))
749+
ctx.add_node(UiNode::new(tc)).to_variant()
749750
}
750751
}
751752

fyrox-ui/src/thumb.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ impl MessageData for ThumbMessage {}
4848
/// splitter in a docking manager's tile, etc.
4949
///
5050
/// ```rust
51-
/// use fyrox_ui::{
52-
/// border::BorderBuilder,
53-
/// brush::Brush,
54-
/// core::{color::Color, pool::Handle},
55-
/// decorator::DecoratorBuilder,
56-
/// message::{CursorIcon, MessageDirection, UiMessage},
57-
/// thumb::{ThumbBuilder, ThumbMessage},
58-
/// widget::WidgetBuilder,
59-
/// BuildContext, UiNode,
60-
/// };
61-
///
62-
/// fn create_thumb(ctx: &mut BuildContext) -> Handle<UiNode> {
51+
/// # use fyrox_ui::{
52+
/// # border::BorderBuilder,
53+
/// # brush::Brush,
54+
/// # core::{color::Color, pool::Handle},
55+
/// # decorator::DecoratorBuilder,
56+
/// # message::{CursorIcon, MessageDirection, UiMessage},
57+
/// # thumb::{ThumbBuilder, ThumbMessage},
58+
/// # widget::WidgetBuilder,
59+
/// # BuildContext, UiNode,
60+
/// # };
61+
/// # use fyrox_ui::thumb::Thumb;
62+
/// #
63+
/// fn create_thumb(ctx: &mut BuildContext) -> Handle<Thumb> {
6364
/// ThumbBuilder::new(
6465
/// WidgetBuilder::new().with_child(
6566
/// DecoratorBuilder::new(BorderBuilder::new(
@@ -79,22 +80,19 @@ impl MessageData for ThumbMessage {}
7980
/// }
8081
///
8182
/// fn process_thumb_messages(my_thumb: Handle<UiNode>, message: &UiMessage) {
82-
/// if message.destination() == my_thumb && message.direction() == MessageDirection::FromWidget
83-
/// {
84-
/// if let Some(msg) = message.data::<ThumbMessage>() {
85-
/// match msg {
86-
/// ThumbMessage::DragStarted { position } => {
87-
/// // Sent by a thumb when it just started dragging. The provided position
88-
/// // expressed in local coordinates of the thumb.
89-
/// }
90-
/// ThumbMessage::DragDelta { offset } => {
91-
/// // Sent by a thumb when it is being dragged. The provided offset
92-
/// // expressed in local coordinates of the thumb.
93-
/// }
94-
/// ThumbMessage::DragCompleted { position } => {
95-
/// // Sent by a thumb when it just stopped dragging. The provided position
96-
/// // expressed in local coordinates of the thumb.
97-
/// }
83+
/// if let Some(msg) = message.data_from::<ThumbMessage>(my_thumb) {
84+
/// match msg {
85+
/// ThumbMessage::DragStarted { position } => {
86+
/// // Sent by a thumb when it just started dragging. The provided position
87+
/// // expressed in local coordinates of the thumb.
88+
/// }
89+
/// ThumbMessage::DragDelta { offset } => {
90+
/// // Sent by a thumb when it is being dragged. The provided offset
91+
/// // expressed in local coordinates of the thumb.
92+
/// }
93+
/// ThumbMessage::DragCompleted { position } => {
94+
/// // Sent by a thumb when it just stopped dragging. The provided position
95+
/// // expressed in local coordinates of the thumb.
9896
/// }
9997
/// }
10098
/// }

0 commit comments

Comments
 (0)