Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Generalizes over render target implementations. All code that
//! depends on the specific render target implementation should
//! live in this module.
//!
//! All implementations should use [`bevy::picking`] for interactions,
//! even [`SourceType::Ui`], for consistency.
//!
//! ## Sprite: [`TextEdit2d`]
//! Requires [`Sprite`] component and requires [`Sprite.custom_size`] to be Some( non-zero )
//!
//! ## UI: [`TextEdit`]
//! Requires [`ImageNode`] for rendering
// TODO: Remove `CosmicWidgetSize`?
mod prelude {
pub(super) use super::error::Result;
pub(super) use super::{RenderTargetError, SourceType};
pub(super) use super::{RenderTypeScan, RenderTypeScanItem};
}
pub use error::*;
mod error {
pub type Error = crate::render_implementations::RenderTargetError;
pub type Result<T> = core::result::Result<T, RenderTargetError>;
#[derive(Debug)]
pub enum RenderTargetError {
/// When no recognized [`SourceType`] could be found
NoTargetsAvailable,
/// When more than one [`SourceType`] was detected.
///
/// This will always be thrown if more than one target type is available,
/// there is no propritisation procedure as this should be considered a
/// logic error.
MoreThanOneTargetAvailable,
/// When a [`RenderTypeScan`] was successfully conducted yet the expected
/// [required component/s](https://docs.rs/bevy/latest/bevy/ecs/prelude/trait.Component.html#required-components)
/// were not found
RequiredComponentNotAvailable {
debug_name: String,
},
/// When using [`SourceType::Sprite`], you must set [`Sprite.custom_size`]
SpriteCustomSizeNotSet,
SpriteUnexpectedNormal,
SpriteExpectedHitdataPosition,
UiExpectedCursorPosition,
}
impl RenderTargetError {
pub fn required_component_missing<C: bevy::prelude::Component>() -> Self {
Self::RequiredComponentNotAvailable {
debug_name: format!("{:?}", core::any::type_name::<C>()),
}
}
}
}
pub(crate) use coords::*;
mod coords;
pub(crate) use output::*;
mod output;
pub(crate) use widget_size::*;
mod widget_size;
pub(crate) use scan::*;
mod scan;
use crate::prelude::*;
/// The top level UI text edit component
///
/// Adding [`TextEdit`] will pull in the required components for setting up
/// a text edit widget, notably [`CosmicEditBuffer`]
///
/// Hopefully this API will eventually mirror [`bevy::prelude::Text`].
/// See [`CosmicEditBuffer`] for more information.
#[derive(Component)]
#[require(ImageNode, Button, bevy::ui::RelativeCursorPosition, CosmicEditBuffer)]
pub struct TextEdit;
/// The top-level 2D text edit component
///
/// Adding [`TextEdit2d`] will pull in the required components for setting up
/// a 2D text editor using a [`Sprite`] with [`Sprite.custom_size`] set,
/// to set the size of the text editor add a [`Sprite`] component with
/// [`Sprite.custom_size`] set.
///
/// Hopefully this API will eventually mirror [`bevy::prelude::Text2d`].
/// See [`CosmicEditBuffer`] for more information.
#[derive(Component)]
#[require(Sprite, CosmicEditBuffer)]
pub struct TextEdit2d;