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
See 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
impl Cx
pub fn event_loop<F>(&mut self, event_handler: F)
Source§impl Cx
impl Cx
pub fn set_down_mouse_cursor(&mut self, mouse_cursor: MouseCursor)
pub fn set_hover_mouse_cursor(&mut self, mouse_cursor: MouseCursor)
Source§impl Cx
impl Cx
pub const STATUS_HTTP_SEND_OK: StatusId
pub const STATUS_HTTP_SEND_FAIL: StatusId
pub fn new(app_type_id: TypeId) -> Self
pub fn get_dpi_factor_of(&mut self, area: &Area) -> f32
Sourcepub fn request_draw(&mut self)
pub fn request_draw(&mut self)
Request a new redraw of the application.
Sourcepub fn set_key_focus(&mut self, focus_component_base: Option<&ComponentBase>)
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.
Sourcepub fn keep_key_focus(&mut self)
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
.
Sourcepub fn revert_key_focus(&mut self)
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.
Sourcepub fn has_key_focus(&self, component_base: Option<&ComponentBase>) -> bool
pub fn has_key_focus(&self, component_base: Option<&ComponentBase>) -> bool
Check if an ComponentBase
currently has keyboard focus.
Sourcepub fn request_next_frame(&mut self)
pub fn request_next_frame(&mut self)
Request an Event::NextFrame
.
Sourcepub fn new_signal(&mut self) -> Signal
pub fn new_signal(&mut self) -> Signal
Create a new Signal
, which is used to send and capture custom
events.
See also SignalEvent
.
Sourcepub fn send_signal(&mut self, signal: Signal, status: StatusId)
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
.
Sourcepub fn debug_flags_mut(&mut self) -> &mut CxDebugFlags
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§impl Cx
impl Cx
Sourcepub fn add_instances<T: Sized>(
&mut self,
shader: &'static Shader,
data: &[T],
) -> Area
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 DrawCall
s. For more information about DrawCall
batching, see Shader
.
Uses Cx::create_draw_call
under the hood to find the DrawCall
to add to.
Sourcepub fn add_mesh_instances<T: Sized>(
&mut self,
shader: &'static Shader,
data: &[T],
gpu_geometry: GpuGeometry,
) -> Area
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
Sourcepub fn add_instances_with_scroll_sticky<T: Sized>(
&mut self,
shader: &'static Shader,
data: &[T],
horizontal: bool,
vertical: bool,
) -> Area
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 DrawCall
s inside View
s,
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.
Sourcepub fn begin_shader_group(&mut self, shaders_ordered: &[&'static Shader])
pub fn begin_shader_group(&mut self, shaders_ordered: &[&'static Shader])
Start a “shader group”, which is a group of Shader
s that will always be drawn in
the same order.
When drawing the same “shader group” multiple times in a row, the existing DrawCall
s
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 DrawCall
s will be created, with FOO_SHADER
being always drawn first.
Sourcepub fn end_shader_group(&mut self)
pub fn end_shader_group(&mut self)
End a “shader group”. See Cx::begin_shader_group
.
Sourcepub fn set_view_scroll_x(&mut self, view_id: usize, scroll_pos: f32)
pub fn set_view_scroll_x(&mut self, view_id: usize, scroll_pos: f32)
Source§impl Cx
impl Cx
pub fn reset_font_atlas_and_redraw(&mut self)
Source§impl Cx
impl Cx
Sourcepub fn begin_row(&mut self, width: Width, height: Height)
pub fn begin_row(&mut self, width: Width, height: Height)
Starts the box that has it elements layed out horizontally (as a row)
Sourcepub fn end_row(&mut self) -> Rect
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
Sourcepub fn begin_column(&mut self, width: Width, height: Height)
pub fn begin_column(&mut self, width: Width, height: Height)
Starts the box that has it elements layed out vertically (as a column)
Sourcepub fn end_column(&mut self) -> Rect
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
Sourcepub fn begin_center_y_align(&mut self)
pub fn begin_center_y_align(&mut self)
Starts alignment element that fills all remaining space by y axis and centers content by it
pub fn end_center_y_align(&mut self)
Sourcepub fn begin_center_x_and_y_align(&mut self)
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
pub fn end_center_x_and_y_align(&mut self)
pub fn begin_bottom_box(&mut self)
pub fn end_bottom_box(&mut self)
Sourcepub fn begin_center_x_align(&mut self)
pub fn begin_center_x_align(&mut self)
Starts alignment element that fills all remaining space by x axis and centers content by it
pub fn end_center_x_align(&mut self)
Sourcepub fn begin_right_box(&mut self)
pub fn begin_right_box(&mut self)
Start new box that will be on the right by x axis
pub fn end_right_box(&mut self)
Sourcepub fn begin_padding_box(&mut self, padding: Padding)
pub fn begin_padding_box(&mut self, padding: Padding)
Starts a new box that adds padding to current box context
Sourcepub fn end_padding_box(&mut self) -> Rect
pub fn end_padding_box(&mut self) -> Rect
Ends the current box that was opened by Cx::begin_padding_box
Sourcepub fn begin_absolute_box(&mut self)
pub fn begin_absolute_box(&mut self)
Starts new box that is absolutely positioned at (0, 0) coordinate
Sourcepub fn end_absolute_box(&mut self)
pub fn end_absolute_box(&mut self)
Ends the current box that was opened by Cx::begin_absolute_box
Sourcepub fn begin_wrapping_box(&mut self)
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
.
Sourcepub fn end_wrapping_box(&mut self)
pub fn end_wrapping_box(&mut self)
Ends the current box that was opened by Cx::begin_wrapping_box
Sourcepub fn get_box_rect(&self) -> Rect
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.
Sourcepub fn get_width_left(&self) -> f32
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
.
Sourcepub fn get_width_total(&self) -> f32
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.
Sourcepub fn get_height_left(&self) -> f32
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
.
Sourcepub fn get_height_total(&self) -> f32
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.
Sourcepub fn get_box_bounds(&self) -> Vec2
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.
Sourcepub fn get_box_origin(&self) -> Vec2
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?
Sourcepub fn get_draw_pos(&self) -> Vec2
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?
Sourcepub fn add_box(&mut self, layout_size: LayoutSize) -> Rect
pub fn add_box(&mut self, layout_size: LayoutSize) -> Rect
Adds Box to current [CxLayoutBox
], returning a Rect
of its size
Sourcepub fn move_draw_pos(&mut self, dx: f32, dy: f32)
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?
Sourcepub fn set_draw_pos(&mut self, pos: Vec2)
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?
Sourcepub fn draw_new_line(&mut self)
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?
Sourcepub fn draw_new_line_min_height(&mut self, min_height: f32)
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
impl Cx
pub fn profile_start(&mut self, id: u64)
pub fn profile_end(&self, id: u64)
Source§impl Cx
impl Cx
pub const COMMAND_QUIT: CommandId
pub const COMMAND_UNDO: CommandId
pub const COMMAND_REDO: CommandId
pub const COMMAND_CUT: CommandId
pub const COMMAND_COPY: CommandId
pub const COMMAND_PASTE: CommandId
pub const COMMAND_ZOOM_IN: CommandId
pub const COMMAND_ZOOM_OUT: CommandId
pub const COMMAND_MINIMIZE: CommandId
pub const COMMAND_ZOOM: CommandId
pub const COMMAND_SELECT_ALL: CommandId
pub fn command_default_keymap(&mut self)
Source§impl Cx
impl Cx
Sourcepub const STD_SHADER: CodeFragment
pub const STD_SHADER: CodeFragment
Collection of standard Shader
functions.
Trait Implementations§
Source§impl CxDesktopVsWasmCommon for Cx
impl CxDesktopVsWasmCommon for Cx
Source§fn get_default_window_size(&self) -> Vec2
fn get_default_window_size(&self) -> Vec2
See CxDesktopVsWasmCommon::get_default_window_size
for documentation.
Source§fn file_write(&mut self, path: &str, data: &[u8])
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])
fn websocket_send(&mut self, _url: &str, _data: &[u8])
See CxDesktopVsWasmCommon::websocket_send
for documentation.
Source§impl CxPlatformCommon for Cx
impl CxPlatformCommon for Cx
Source§fn show_text_ime(&mut self, x: f32, y: f32)
fn show_text_ime(&mut self, x: f32, y: f32)
See CxPlatformCommon::show_text_ime
for documentation.
Source§fn hide_text_ime(&mut self)
fn hide_text_ime(&mut self)
See CxPlatformCommon::hide_text_ime
for documentation.
Source§fn start_timer(&mut self, interval: f64, repeats: bool) -> Timer
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)
fn stop_timer(&mut self, timer: &mut Timer)
See CxPlatformCommon::stop_timer
for documentation.
Source§fn post_signal(signal: Signal, status: StatusId)
fn post_signal(signal: Signal, status: StatusId)
See CxPlatformCommon::post_signal
for documentation.
See CxPlatformCommon::update_menu
for documentation.
Source§fn copy_text_to_clipboard(&mut self, text: &str)
fn copy_text_to_clipboard(&mut self, text: &str)
See CxPlatformCommon::update_menu
for documentation.