Struct fyrox_ui::window::Window

source ·
pub struct Window {
Show 21 fields pub widget: Widget, pub mouse_click_pos: Vector2<f32>, pub initial_position: Vector2<f32>, pub initial_size: Vector2<f32>, pub is_dragging: bool, pub minimized: bool, pub can_minimize: bool, pub can_maximize: bool, pub can_close: bool, pub can_resize: bool, pub header: Handle<UiNode>, pub minimize_button: Handle<UiNode>, pub maximize_button: Handle<UiNode>, pub close_button: Handle<UiNode>, pub drag_delta: Vector2<f32>, pub content: Handle<UiNode>, pub grips: RefCell<[Grip; 8]>, pub title: Handle<UiNode>, pub title_grid: Handle<UiNode>, pub safe_border_size: Option<Vector2<f32>>, pub prev_bounds: Option<Rect<f32>>,
}
Expand description

The Window widget provides a standard window that can contain another widget. Based on setting windows can be configured so users can do any of the following:

  • Movable by the user. Not configurable.
  • Have title text on the title bar. Set by the with_title function.
  • Able to be exited by the user. Set by the can_close function.
  • Able to be minimized to just the Title bar, and of course maximized again. Set by the can_minimize function.
  • Able to resize the window. Set by the can_resize function.

As with other UI elements, you create and configure the window using the WindowBuilder.

fn create_window(ui: &mut UserInterface) {
    WindowBuilder::new(
        WidgetBuilder::new()
            .with_desired_position(Vector2::new(300.0, 0.0))
            .with_width(300.0),
    )
    .with_content(
        TextBuilder::new(WidgetBuilder::new())
            .with_text("Example Window content.")
            .build(&mut ui.build_ctx())
    )
    .with_title(WindowTitle::text("Window"))
    .can_close(true)
    .can_minimize(true)
    .open(true)
    .can_resize(false)
    .build(&mut ui.build_ctx());
}

You will likely want to constrain the initial size of the window to something as shown in the example by providing a set width and/or height to the base WidgetBuilder. Otherwise it will expand to fit it’s content.

You may also want to set an initial position with the with_desired_position function called on the base WidgetBuilder which sets the position of the window’s top-left corner. Otherwise all your windows will start with it’s top-left corner at 0,0 and be stacked on top of each other.

Windows can only contain a single direct child widget, set by using the with_content function. Additional calls to with_content replaces the widgets given in previous calls, and the old widgets exist outside the window, so you should delete old widgets before changing a window’s widget. If you want multiple widgets, you need to use one of the layout container widgets like the Grid, Stack Panel, etc then add the additional widgets to that widget as needed.

The Window is a user editable object, but can only be affected by UI Messages they trigger if the message’s corresponding variable has been set to true aka what is set by the can_close, can_minimize, and can_resize functions.

Initial Open State

By default, the window will be created in the open, or maximized, state. You can manually set this state via the open function providing a true or false as desired.

Styling the Buttons

The window close and minimise buttons can be configured with the with_close_button and with_minimize_button functions. You will want to pass them a button widget, but can do anything else you like past that.

A Modal in UI design terms indicates a window or box that has forced focus. The user is not able to interact with anything else until the modal is dismissed.

Any window can be set and unset as a modal via the modal function.

Fields§

§widget: Widget

Base widget of the window.

§mouse_click_pos: Vector2<f32>

Mouse click position.

§initial_position: Vector2<f32>

Initial mouse position.

§initial_size: Vector2<f32>

Initial size of the window.

§is_dragging: bool

Whether the window is being dragged or not.

§minimized: bool

Whether the window is minimized or not.

§can_minimize: bool

Whether the window can be minimized or not.

§can_maximize: bool

Whether the window can be maximized or not.

§can_close: bool

Whether the window can be closed or not.

§can_resize: bool

Whether the window can be resized or not.

§header: Handle<UiNode>

Handle of a header widget.

§minimize_button: Handle<UiNode>

Handle of a minimize button.

§maximize_button: Handle<UiNode>

Handle of a maximize button.

§close_button: Handle<UiNode>

Handle of a close button.

§drag_delta: Vector2<f32>

A distance per each axis when the dragging starts.

§content: Handle<UiNode>

Handle of a current content.

§grips: RefCell<[Grip; 8]>

Eight grips of the window that are used to resize the window.

§title: Handle<UiNode>

Handle of a title widget of the window.

§title_grid: Handle<UiNode>

Handle of a container widget of the title.

§safe_border_size: Option<Vector2<f32>>

Optional size of the border around the screen in which the window will be forced to stay.

§prev_bounds: Option<Rect<f32>>

Bounds of the window before maximization, it is used to return the window to previous size when it is either “unmaximized” or dragged.

Implementations§

source§

impl Window

source

pub fn has_active_grip(&self) -> bool

Checks whether any resizing grip is active or not.

Methods from Deref<Target = Widget>§

source

pub fn handle(&self) -> Handle<UiNode>

Returns self handle of the widget.

source

pub fn name(&self) -> &str

Returns the name of the widget.

source

pub fn set_name<P: AsRef<str>>(&mut self, name: P) -> &mut Self

Sets the new name of the widget.

source

pub fn actual_local_size(&self) -> Vector2<f32>

Returns the actual size of the widget after the full layout cycle.

source

pub fn actual_initial_size(&self) -> Vector2<f32>

Returns size of the widget without any layout or rendering transform applied.

source

pub fn actual_global_size(&self) -> Vector2<f32>

Returns the actual global size of the widget after the full layout cycle.

source

pub fn set_min_size(&mut self, value: Vector2<f32>) -> &mut Self

Sets the new minimum size of the widget.

source

pub fn set_min_width(&mut self, value: f32) -> &mut Self

Sets the new minimum width of the widget.

source

pub fn set_min_height(&mut self, value: f32) -> &mut Self

Sets the new minimum height of the widget.

source

pub fn min_size(&self) -> Vector2<f32>

Sets the new minimum size of the widget.

source

pub fn min_width(&self) -> f32

Returns the minimum width of the widget.

source

pub fn min_height(&self) -> f32

Returns the minimum height of the widget.

source

pub fn is_drag_allowed(&self) -> bool

Return true if the dragging of the widget is allowed, false - otherwise.

source

pub fn is_drop_allowed(&self) -> bool

Return true if the dropping of other widgets is allowed on this widget, false - otherwise.

source

pub fn screen_to_local(&self, point: Vector2<f32>) -> Vector2<f32>

Maps the given point from screen to local widget’s coordinates.

source

pub fn invalidate_layout(&self)

Invalidates layout of the widget. WARNING: Do not use this method, unless you understand what you’re doing, it will cause new layout pass for this widget which could be quite heavy and doing so on every frame for multiple widgets will cause severe performance issues.

source

pub fn invalidate_measure(&self)

Invalidates measurement results of the widget. WARNING: Do not use this method, unless you understand what you’re doing, it will cause new measurement pass for this widget which could be quite heavy and doing so on every frame for multiple widgets will cause severe performance issues.

source

pub fn invalidate_arrange(&self)

Invalidates arrangement results of the widget. WARNING: Do not use this method, unless you understand what you’re doing, it will cause new arrangement pass for this widget which could be quite heavy and doing so on every frame for multiple widgets will cause severe performance issues.

source

pub fn is_hit_test_visible(&self) -> bool

Returns true if the widget is able to participate in hit testing, false - otherwise.

source

pub fn set_max_size(&mut self, value: Vector2<f32>) -> &mut Self

Sets the new maximum size of the widget.

source

pub fn max_size(&self) -> Vector2<f32>

Returns current maximum size of the widget.

source

pub fn max_width(&self) -> f32

Returns maximum width of the widget.

source

pub fn max_height(&self) -> f32

Return maximum height of the widget.

source

pub fn set_z_index(&mut self, z_index: usize) -> &mut Self

Sets new Z index for the widget. Z index defines the sorting (stable) index which will be used to “arrange” widgets in the correct order.

source

pub fn z_index(&self) -> usize

Returns current Z index of the widget.

source

pub fn set_background(&mut self, brush: Brush) -> &mut Self

Sets the new background of the widget.

source

pub fn background(&self) -> Brush

Returns current background of the widget.

source

pub fn set_foreground(&mut self, brush: Brush) -> &mut Self

Sets new foreground of the widget.

source

pub fn foreground(&self) -> Brush

Returns current foreground of the widget.

source

pub fn set_width(&mut self, width: f32) -> &mut Self

Sets new width of the widget.

source

pub fn width(&self) -> f32

Returns current width of the widget.

source

pub fn is_draw_on_top(&self) -> bool

Return true if the widget is set to be drawn on top of every other, normally drawn, widgets, false - otherwise.

source

pub fn set_height(&mut self, height: f32) -> &mut Self

Sets new height of the widget.

source

pub fn height(&self) -> f32

Returns current height of the widget.

source

pub fn set_desired_local_position(&mut self, pos: Vector2<f32>) -> &mut Self

Sets the desired local position of the widget.

source

pub fn screen_position(&self) -> Vector2<f32>

Returns current screen-space position of the widget.

source

pub fn children(&self) -> &[Handle<UiNode>]

Returns a reference to the slice with the children widgets of this widget.

source

pub fn parent(&self) -> Handle<UiNode>

Returns current parent handle of the widget.

source

pub fn set_column(&mut self, column: usize) -> &mut Self

Sets new column of the widget. Columns are used only by crate::grid::Grid widget.

source

pub fn column(&self) -> usize

Returns current column of the widget. Columns are used only by crate::grid::Grid widget.

source

pub fn set_row(&mut self, row: usize) -> &mut Self

Sets new row of the widget. Rows are used only by crate::grid::Grid widget.

source

pub fn row(&self) -> usize

Returns current row of the widget. Rows are used only by crate::grid::Grid widget.

source

pub fn desired_size(&self) -> Vector2<f32>

Returns the desired size of the widget.

source

pub fn desired_local_position(&self) -> Vector2<f32>

Returns current desired local position of the widget.

source

pub fn screen_bounds(&self) -> Rect<f32>

Returns current screen-space bounds of the widget.

source

pub fn bounding_rect(&self) -> Rect<f32>

Returns local-space bounding rect of the widget.

source

pub fn visual_transform(&self) -> &Matrix3<f32>

Returns current visual transform of the widget.

source

pub fn render_transform(&self) -> &Matrix3<f32>

Returns current render transform of the widget.

source

pub fn layout_transform(&self) -> &Matrix3<f32>

Returns current layout transform of the widget.

source

pub fn has_descendant( &self, node_handle: Handle<UiNode>, ui: &UserInterface ) -> bool

Returns true, if the widget has a descendant widget with the specified handle, false - otherwise.

source

pub fn find_by_criteria_up<Func: Fn(&UiNode) -> bool>( &self, ui: &UserInterface, func: Func ) -> Handle<UiNode>

Searches a node up on tree starting from the given root that matches a criteria defined by the given func.

source

pub fn handle_routed_message( &mut self, _ui: &mut UserInterface, msg: &mut UiMessage )

Handles incoming WidgetMessages. This method must be called in crate::control::Control::handle_routed_message of any derived widgets!

source

pub fn set_vertical_alignment( &mut self, vertical_alignment: VerticalAlignment ) -> &mut Self

Sets new vertical alignment of the widget.

source

pub fn vertical_alignment(&self) -> VerticalAlignment

Returns current vertical alignment of the widget.

source

pub fn set_horizontal_alignment( &mut self, horizontal_alignment: HorizontalAlignment ) -> &mut Self

Sets new horizontal alignment of the widget.

source

pub fn horizontal_alignment(&self) -> HorizontalAlignment

Returns current horizontal alignment of the widget.

source

pub fn set_margin(&mut self, margin: Thickness) -> &mut Self

Sets new margin of the widget.

source

pub fn margin(&self) -> Thickness

Returns current margin of the widget.

source

pub fn measure_override( &self, ui: &UserInterface, available_size: Vector2<f32> ) -> Vector2<f32>

Performs standard measurement of children nodes. It provides available size as a constraint and returns the maximum desired size across all children. As a result, this widget will have this size as its desired size to fit all the children nodes.

source

pub fn arrange_override( &self, ui: &UserInterface, final_size: Vector2<f32> ) -> Vector2<f32>

Performs standard arrangement of the children nodes of the widget. It uses input final size to make a final bounding rectangle to arrange children. As a result, all the children nodes will be located at the top-left corner of this widget and stretched to fit its bounds.

source

pub fn is_arrange_valid(&self) -> bool

Returns true if the current results of arrangement of the widget are valid, false - otherwise.

source

pub fn is_measure_valid(&self) -> bool

Returns true if the current results of measurement of the widget are valid, false - otherwise.

source

pub fn actual_local_position(&self) -> Vector2<f32>

Returns current actual local position of the widget. It is valid only after layout pass!

source

pub fn center(&self) -> Vector2<f32>

Returns center point of the widget. It is valid only after layout pass!

source

pub fn is_globally_visible(&self) -> bool

Returns true of the widget is globally visible, which means that all its parents are visible as well as this widget. It is valid only after the first update of the layout, otherwise if will be always false.

source

pub fn set_visibility(&mut self, visibility: bool) -> &mut Self

Sets new visibility of the widget.

source

pub fn request_update_visibility(&self)

Requests (via event queue, so the request is deferred) the update of the visibility of the widget.

source

pub fn visibility(&self) -> bool

Returns current visibility of the widget.

source

pub fn set_enabled(&mut self, enabled: bool) -> &mut Self

Enables or disables the widget. Disabled widgets does not interact with user and usually greyed out.

source

pub fn enabled(&self) -> bool

Returns true if the widget if enabled, false - otherwise.

source

pub fn set_cursor(&mut self, cursor: Option<CursorIcon>)

Sets new cursor of the widget.

source

pub fn cursor(&self) -> Option<CursorIcon>

Returns current cursor of the widget.

source

pub fn user_data_ref<T: 'static>(&self) -> Option<&T>

Tries to fetch user-defined data of the specified type T.

source

pub fn clip_bounds(&self) -> Rect<f32>

Returns current clipping bounds of the widget. It is valid only after at least one layout pass.

source

pub fn set_opacity(&mut self, opacity: Option<f32>) -> &mut Self

Set new opacity of the widget. Opacity should be in [0.0..1.0] range.

source

pub fn opacity(&self) -> Option<f32>

Returns current opacity of the widget.

source

pub fn tooltip(&self) -> Option<RcUiNodeHandle>

Returns current tooltip handle of the widget.

source

pub fn set_tooltip(&mut self, tooltip: Option<RcUiNodeHandle>) -> &mut Self

Sets new tooltip handle of the widget (if any).

source

pub fn tooltip_time(&self) -> f32

Returns maximum available time to show the tooltip after the cursor was moved away from the widget.

source

pub fn set_tooltip_time(&mut self, tooltip_time: f32) -> &mut Self

Set the maximum available time to show the tooltip after the cursor was moved away from the widget.

source

pub fn context_menu(&self) -> Option<RcUiNodeHandle>

Returns current context menu of the widget.

source

pub fn set_context_menu( &mut self, context_menu: Option<RcUiNodeHandle> ) -> &mut Self

The context menu receives PopupMessages for being displayed, and so should support those.

Trait Implementations§

source§

impl Clone for Window

source§

fn clone(&self) -> Window

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Control for Window

source§

fn query_component(&self, type_id: TypeId) -> Option<&dyn Any>

Allows a widget to provide access to inner components. For example you can build your custom MyTree widget using engine’s Tree widget as a base. The engine needs to know whether the custom widget is actually extends functionality of some existing widget. Read more
source§

fn resolve(&mut self, node_map: &NodeHandleMapping)

This method will be called right after the widget was cloned. It is used remap handles in the widgets to their respective copies from the copied hierarchy.
source§

fn arrange_override( &self, ui: &UserInterface, final_size: Vector2<f32> ) -> Vector2<f32>

This method is used to override arrangement step of the layout system. Arrangement step is used to commit the final location and size of the widget in local coordinates. It is done after the measurement step; when all desired sizes of every widget is known. This fact allows you to calculate final location and size of every child widget, based in their desired size. Usually this method is used in some panel widgets, that takes their children and arranges them in some specific way. For example, it may stack widgets on top of each other, or put them in a line with wrapping, etc. Read more
source§

fn handle_routed_message( &mut self, ui: &mut UserInterface, message: &mut UiMessage )

Performs event-specific actions. Must call widget.handle_message()! Read more
source§

fn on_remove(&self, sender: &Sender<UiMessage>)

This method will be called before the widget is destroyed (dropped). At the moment, when this method is called, the widget is still in the widget graph and can be accessed via handles. It is guaranteed to be called once, and only if the widget is deleted via crate::widget::WidgetMessage::remove.
source§

fn measure_override( &self, ui: &UserInterface, available_size: Vector2<f32> ) -> Vector2<f32>

This method is used to override measurement step of the layout system. It should return desired size of the widget (how many space it wants to occupy). Read more
source§

fn draw(&self, drawing_context: &mut DrawingContext)

This method is used to emit drawing commands that will be used later to draw your widget on screen. Keep in mind that any emitted geometry (quads, lines, text, etc), will be used to perform hit test. In other words, all the emitted geometry will make your widget “clickable”. Widgets with no geometry emitted by this method are mouse input transparent. Read more
source§

fn update(&mut self, dt: f32, sender: &Sender<UiMessage>)

This method is called every frame and can be used to update internal variables of the widget, that can be used to animated your widget. Its main difference from other methods, is that it does not provide access to any other widget in the UI. Instead, you can only send messages to widgets to force them to change their state.
source§

fn preview_message(&self, ui: &UserInterface, message: &mut UiMessage)

Used to react to a message (by producing another message) that was posted outside of current hierarchy. In other words this method is used when you need to “peek” a message before it’ll be passed into bubbling router. Most common use case is to catch messages from popups: popup in 99.9% cases is a child of root canvas and it won’t receive a message from a its logical parent during bubbling message routing. For example preview_message used in a dropdown list: dropdown list has two separate parts - a field with selected value and a popup for all possible options. Visual parent of the popup in this case is the root canvas, but logical parent is the dropdown list. Because of this fact, the field won’t receive any messages from popup, to solve this we use preview_message. This method is much more restrictive - it does not allow you to modify a node and ui, you can either request changes by sending a message or use internal mutability (Cell, RefCell, etc). Read more
source§

fn handle_os_event( &mut self, self_handle: Handle<UiNode>, ui: &mut UserInterface, event: &OsEvent )

Provides a way to respond to OS specific events. Can be useful to detect if a key or mouse button was pressed. This method significantly differs from handle_message because os events are not dispatched - they’ll be passed to this method in any case. Read more
source§

impl Deref for Window

§

type Target = Widget

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Window

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Window

§

impl !Send for Window

§

impl !Sync for Window

§

impl Unpin for Window

§

impl !UnwindSafe for Window

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> BaseControl for Twhere T: Any + Clone + 'static + Control,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns self as &dyn Any.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns self as &mut dyn Any.
source§

fn clone_boxed(&self) -> Box<dyn Control<Target = Widget>, Global>

Returns the exact copy of the widget in “type-erased” form.
source§

fn type_name(&self) -> &'static str

Returns type name of the widget.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> FieldValue for Twhere T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V