Cx

Struct Cx 

Source
pub struct Cx {
    pub platform_type: PlatformType,
    pub current_dpi_factor: f32,
    pub last_event_time: f64,
    pub fonts_data: Arc<RwLock<CxFontsData>>,
    pub call_rust_fn: Option<usize>,
    pub app_type_id: TypeId,
    /* private fields */
}
Expand description

The main “context” object which contains pretty much everything we need within the framework.

Fields§

§platform_type: PlatformType§current_dpi_factor: f32

The dpi_factor used during the current Pass (since you can override the system default). See also [PassUniforms::dpi_factor].

More commonly known as the “device pixel ratio”. TODO(JP): Rename?

§last_event_time: f64

Last timestamp from when an event was fired, in seconds since the application was started. Typically you want to use this instead of making a system call.

§fonts_data: Arc<RwLock<CxFontsData>>

Fonts specific data It might be possible for fonts data to be shared between different threads, so we need to make use of locks.

§call_rust_fn: Option<usize>

Function registered through Cx::on_call_rust

§app_type_id: TypeId

Reference to the main_app type

Implementations§

Source§

impl Cx

Source

pub fn event_loop<F>(&mut self, event_handler: F)
where F: FnMut(&mut Cx, &mut Event),

Source§

impl Cx

Source

pub fn set_down_mouse_cursor(&mut self, mouse_cursor: MouseCursor)

Source

pub fn set_hover_mouse_cursor(&mut self, mouse_cursor: MouseCursor)

Source§

impl Cx

Source

pub const STATUS_HTTP_SEND_OK: StatusId

Source

pub const STATUS_HTTP_SEND_FAIL: StatusId

Source

pub fn new(app_type_id: TypeId) -> Self

Source

pub fn get_dpi_factor_of(&mut self, area: &Area) -> f32

Source

pub fn request_draw(&mut self)

Request a new redraw of the application.

Source

pub fn set_key_focus(&mut self, focus_component_base: Option<&ComponentBase>)

Sets a ComponentBase that will become Cx::key_focus when the current events are handled.

TODO(JP): It’s possible to set this during the draw cycle instead of during an event handler, and then it won’t update Cx::key_focus until the next event is handled. We should probably guard against that.

Source

pub fn keep_key_focus(&mut self)

Keep the existing key focus during an Event::FingerDown, because otherwise we’ll reset it back to Area::Empty.

Source

pub fn revert_key_focus(&mut self)

Reverts back to the previous Cx::key_focus value.

TODO(JP): It’s possible to set this during the draw cycle instead of during an event handler, and then it won’t update Cx::key_focus until the next event is handled. We should probably guard against that.

Source

pub fn has_key_focus(&self, component_base: Option<&ComponentBase>) -> bool

Check if an ComponentBase currently has keyboard focus.

Source

pub fn request_next_frame(&mut self)

Request an Event::NextFrame.

Source

pub fn new_signal(&mut self) -> Signal

Create a new Signal, which is used to send and capture custom events.

See also SignalEvent.

Source

pub fn send_signal(&mut self, signal: Signal, status: StatusId)

Triggers a new SignalEvent with the same ID as Signal. You can post custom data with it using status.

If you want to fire a SignalEvent from a thread, use Cx::post_signal instead.

See also SignalEvent.

Source

pub fn debug_flags_mut(&mut self) -> &mut CxDebugFlags

Change the debug flags, which control various debug functionality. See CxDebugFlags for more information on the individual flags.

Example:

let flags = cx.debug_flags_mut();
flags.draw_tree = CxDebugDrawTree::Instances;
flags.disable_draw_call_batching = true;
Source

pub fn on_call_rust<T: 'static>( &mut self, func: fn(this: &mut T, cx: &mut Cx, name: String, params: Vec<WrfParam>) -> Vec<WrfParam>, )

Register function to handle callRust from JavaScript. Registered function must be a method on the main app.

Source§

impl Cx

Source

pub fn add_instances<T: Sized>( &mut self, shader: &'static Shader, data: &[T], ) -> Area

Add a slice of instances to DrawCall::instances.

Supports appending any data that has the correct size.

You should assume that any call to this creates a new DrawCall, even though in reality we might batch certain DrawCalls. For more information about DrawCall batching, see Shader.

Uses Cx::create_draw_call under the hood to find the DrawCall to add to.

Source

pub fn add_mesh_instances<T: Sized>( &mut self, shader: &'static Shader, data: &[T], gpu_geometry: GpuGeometry, ) -> Area

Add a slice of instances while specifying a custom Geometry

Source

pub fn add_instances_with_scroll_sticky<T: Sized>( &mut self, shader: &'static Shader, data: &[T], horizontal: bool, vertical: bool, ) -> Area

By default, DrawCall gets horizontal and vertical scrolling applied to its uniforms, but you can disable that by calling this method. This only applies to scrolling from its direct parent View.

This always creates a new DrawCall; no batching ever happens when using sticky scrolling.

TODO(JP): The fact that this only applies to the direct parent View makes it so you can’t just arbitrarily wrap DrawCalls inside Views, which is somewhat unexpected. It might be better to have this apply to the nearest wrflib_widget::ScrollView instead?

TODO(JP): Do we need to track as fields on DrawCall? The same behavior can also be accomplished by overriding the Shader’s scroll function, by doing draw_scroll - draw_local_scroll. It’s not as convenient, but then again, it might not be used very often, and it would encourage people to do more stuff in shaders.

Source

pub fn begin_shader_group(&mut self, shaders_ordered: &[&'static Shader])

Start a “shader group”, which is a group of Shaders that will always be drawn in the same order.

When drawing the same “shader group” multiple times in a row, the existing DrawCalls will be reused (batched) instead of new ones being created.

For example, calling cx.begin_shader_group(&[&FOO_SHADER, &BAR_SHADER]); will guarantee that for that shader group exactly two DrawCalls will be created, with FOO_SHADER being always drawn first.

Source

pub fn end_shader_group(&mut self)

End a “shader group”. See Cx::begin_shader_group.

Source

pub fn set_view_scroll_x(&mut self, view_id: usize, scroll_pos: f32)

Sets the horizontal scroll position for a View/CxView.

Source

pub fn set_view_scroll_y(&mut self, view_id: usize, scroll_pos: f32)

Sets the vertical scroll position for a View/CxView.

Source§

impl Cx

Source§

impl Cx

Source

pub fn begin_row(&mut self, width: Width, height: Height)

Starts the box that has it elements layed out horizontally (as a row)

Source

pub fn end_row(&mut self) -> Rect

Ends the current block that was opened by Cx::begin_row. Returns a Rect representing the overall area of that row

Source

pub fn begin_column(&mut self, width: Width, height: Height)

Starts the box that has it elements layed out vertically (as a column)

Source

pub fn end_column(&mut self) -> Rect

Ends the current block that was opened by Cx::begin_column. Returns a Rect representing the overall area of that column

Source

pub fn begin_center_y_align(&mut self)

Starts alignment element that fills all remaining space by y axis and centers content by it

Source

pub fn end_center_y_align(&mut self)

Source

pub fn begin_center_x_and_y_align(&mut self)

Starts alignment element that fills all remaining space in box and centers content by x and y

Source

pub fn end_center_x_and_y_align(&mut self)

Source

pub fn begin_bottom_box(&mut self)

Source

pub fn end_bottom_box(&mut self)

Source

pub fn begin_center_x_align(&mut self)

Starts alignment element that fills all remaining space by x axis and centers content by it

Source

pub fn end_center_x_align(&mut self)

Source

pub fn begin_right_box(&mut self)

Start new box that will be on the right by x axis

Source

pub fn end_right_box(&mut self)

Source

pub fn begin_padding_box(&mut self, padding: Padding)

Starts a new box that adds padding to current box context

Source

pub fn end_padding_box(&mut self) -> Rect

Ends the current box that was opened by Cx::begin_padding_box

Source

pub fn begin_absolute_box(&mut self)

Starts new box that is absolutely positioned at (0, 0) coordinate

Source

pub fn end_absolute_box(&mut self)

Ends the current box that was opened by Cx::begin_absolute_box

Source

pub fn begin_wrapping_box(&mut self)

Starts new box that is wrapping its content inside. This is defined in terms of child boxes (e.g. if any of the immediately nested boxes goes beyond the bounds, it would be wrapped to new line). This is only supported for horizontal direction. Note: text has its own wrapping mechanism via TextInsProps::wrapping.

Source

pub fn end_wrapping_box(&mut self)

Ends the current box that was opened by Cx::begin_wrapping_box

Source

pub fn get_box_rect(&self) -> Rect

Returns the full rect corresponding to current box. It uses all available_width/height plus padding. Note that these are the inherent dimensions of the [CxLayoutBox], not what the [CxLayoutBox] has walked so far. See Cx::get_box_bounds for that.

Source

pub fn get_width_left(&self) -> f32

Get some notion of the width that is “left” for the current [CxLayoutBox].

See also Cx::get_width_total.

Source

pub fn get_width_total(&self) -> f32

Get some notion of the total width of the current box. If the width is well defined, then we return it. If it’s computed, then we return the bound (including padding) of how much we’ve drawn so far. And if we haven’t drawn anything, we return 0.

Source

pub fn get_height_left(&self) -> f32

Get some notion of the height that is “left” for the current [CxLayoutBox].

See also Cx::get_height_total.

Source

pub fn get_height_total(&self) -> f32

Get some notion of the total height of the current box. If the height is well defined, then we return it. If it’s computed, then we return the bound (including padding) of how much we’ve drawn so far. And if we haven’t drawn anything, we return 0.

Source

pub fn get_box_bounds(&self) -> Vec2

Get the bounds of what the box has actually moved (not just its inherent width/height as given by Cx::get_box_rect), including any padding that the layout of the current box specifies.

Source

pub fn get_box_origin(&self) -> Vec2

Same as [Cx::get_box_rect().pos].

TODO(JP): Do we really need two different methods to get to the same data?

Source

pub fn get_draw_pos(&self) -> Vec2

Get the current [CxLayoutBox::pos] in absolute coordinates.

TODO(JP): Only used in two places currently; do we really need this?

Source

pub fn add_box(&mut self, layout_size: LayoutSize) -> Rect

Adds Box to current [CxLayoutBox], returning a Rect of its size

Source

pub fn move_draw_pos(&mut self, dx: f32, dy: f32)

Manually change [CxLayoutBox::pos]. Warning! Does not update [CxLayoutBox::bound_right_bottom], like Cx::add_box does; might result in unexpected behavior.

TODO(JP): Should we delete this and just always use Cx::add_box instead?

Source

pub fn set_draw_pos(&mut self, pos: Vec2)

Manually change [CxLayoutBox::pos]. Warning! Does not update [CxLayoutBox::bound_right_bottom], like Cx::add_box does; might result in unexpected behavior.

TODO(JP): Should we delete this and just always use Cx::add_box instead?

Source

pub fn draw_new_line(&mut self)

Explicitly move the current [CxLayoutBox] to a new line.

TODO(JP): Mostly relevant for Direction::Right, should we just disable this for Direction::Down to avoid confusion?

Source

pub fn draw_new_line_min_height(&mut self, min_height: f32)

Cx::draw_new_line but allows setting a minimum height for the line.

TODO(JP): Should we instead include min_height in [Layout]?

Source§

impl Cx

Source

pub fn profile_start(&mut self, id: u64)

Source

pub fn profile_end(&self, id: u64)

Source§

impl Cx

Source§

impl Cx

Source

pub const STD_SHADER: CodeFragment

Collection of standard Shader functions.

Trait Implementations§

Source§

impl CxDesktopVsWasmCommon for Cx

Source§

fn get_default_window_size(&self) -> Vec2

Source§

fn file_write(&mut self, path: &str, data: &[u8])

See CxDesktopVsWasmCommon::file_write for documentation.

Source§

fn websocket_send(&mut self, _url: &str, _data: &[u8])

Source§

fn http_send( &mut self, verb: &str, path: &str, _proto: &str, domain: &str, port: u16, content_type: &str, body: &[u8], signal: Signal, )

See CxDesktopVsWasmCommon::http_send for documentation.

Source§

fn return_to_js(&mut self, _callback_id: u32, _params: Vec<WrfParam>)

This never gets called if cef is not enabled, but we need it to pass compilation.

Source§

impl CxPlatformCommon for Cx

Source§

fn show_text_ime(&mut self, x: f32, y: f32)

See CxPlatformCommon::show_text_ime for documentation.

Source§

fn hide_text_ime(&mut self)

See CxPlatformCommon::hide_text_ime for documentation.

Source§

fn start_timer(&mut self, interval: f64, repeats: bool) -> Timer

See CxPlatformCommon::start_timer for documentation.

Source§

fn stop_timer(&mut self, timer: &mut Timer)

See CxPlatformCommon::stop_timer for documentation.

Source§

fn post_signal(signal: Signal, status: StatusId)

See CxPlatformCommon::post_signal for documentation.

Source§

fn update_menu(&mut self, _menu: &Menu)

See CxPlatformCommon::update_menu for documentation.

Source§

fn copy_text_to_clipboard(&mut self, text: &str)

See CxPlatformCommon::update_menu for documentation.

Source§

fn send_event_from_any_thread(_event: Event)

Send wrflib Event for processing from any thread

Auto Trait Implementations§

§

impl Freeze for Cx

§

impl !RefUnwindSafe for Cx

§

impl !Send for Cx

§

impl !Sync for Cx

§

impl Unpin for Cx

§

impl !UnwindSafe for Cx

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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.

Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,