mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
property editor for char + editors for mask char in formatted text
This commit is contained in:
@@ -75,6 +75,7 @@ uuid_provider!(isize = "0a06591a-1c66-4299-ba6f-2b205b795575");
|
||||
uuid_provider!(bool = "3b104074-9d39-4a2b-b974-da8cc1759fe8");
|
||||
uuid_provider!(PathBuf = "3b104074-9d39-4a2b-b974-da8cc1759666");
|
||||
uuid_provider!(String = "3b104074-9d39-4a2b-b974-da8cc1759999");
|
||||
uuid_provider!(char = "9b5050ef-b3e5-41d2-90f8-8273bcdf7bfb");
|
||||
|
||||
uuid_provider!(Vector2<f32> = "79d4fae7-27f7-4d28-ac3e-6a569b025a82");
|
||||
uuid_provider!(Vector3<f32> = "85e32efb-1784-46f7-8ec0-8ee038661ed4");
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
use crate::{
|
||||
core::algebra::Vector2,
|
||||
formatted_text::WrapMode,
|
||||
inspector::{
|
||||
editors::{
|
||||
PropertyEditorBuildContext, PropertyEditorDefinition, PropertyEditorInstance,
|
||||
PropertyEditorMessageContext, PropertyEditorTranslationContext,
|
||||
},
|
||||
FieldKind, InspectorError, PropertyChanged,
|
||||
},
|
||||
message::{MessageDirection, UiMessage},
|
||||
text::TextMessage,
|
||||
text_box::{TextBoxBuilder, TextCommitMode},
|
||||
widget::WidgetBuilder,
|
||||
Thickness, VerticalAlignment,
|
||||
};
|
||||
use std::any::TypeId;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CharPropertyEditorDefinition;
|
||||
|
||||
impl PropertyEditorDefinition for CharPropertyEditorDefinition {
|
||||
fn value_type_id(&self) -> TypeId {
|
||||
TypeId::of::<char>()
|
||||
}
|
||||
|
||||
fn create_instance(
|
||||
&self,
|
||||
ctx: PropertyEditorBuildContext,
|
||||
) -> Result<PropertyEditorInstance, InspectorError> {
|
||||
let value = ctx.property_info.cast_value::<char>()?;
|
||||
Ok(PropertyEditorInstance::Simple {
|
||||
editor: TextBoxBuilder::new(
|
||||
WidgetBuilder::new()
|
||||
.with_min_size(Vector2::new(0.0, 17.0))
|
||||
.with_margin(Thickness::uniform(1.0)),
|
||||
)
|
||||
.with_wrap(WrapMode::Word)
|
||||
.with_text_commit_mode(TextCommitMode::Changed)
|
||||
.with_text(value.to_string())
|
||||
.with_vertical_text_alignment(VerticalAlignment::Center)
|
||||
.build(ctx.build_context),
|
||||
})
|
||||
}
|
||||
|
||||
fn create_message(
|
||||
&self,
|
||||
ctx: PropertyEditorMessageContext,
|
||||
) -> Result<Option<UiMessage>, InspectorError> {
|
||||
let value = ctx.property_info.cast_value::<char>()?;
|
||||
Ok(Some(TextMessage::text(
|
||||
ctx.instance,
|
||||
MessageDirection::ToWidget,
|
||||
value.clone().to_string(),
|
||||
)))
|
||||
}
|
||||
|
||||
fn translate_message(&self, ctx: PropertyEditorTranslationContext) -> Option<PropertyChanged> {
|
||||
if ctx.message.direction() == MessageDirection::FromWidget {
|
||||
if let Some(TextMessage::Text(value)) = ctx.message.data::<TextMessage>() {
|
||||
if let Some(first_char) = value.chars().next() {
|
||||
return Some(PropertyChanged {
|
||||
name: ctx.name.to_string(),
|
||||
value: FieldKind::object(first_char),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,6 @@
|
||||
//! A collection of [PropertyEditorDefinition] objects for a wide variety of types,
|
||||
//! including standard Rust types and Fyrox core types.
|
||||
|
||||
use crate::font::FontResource;
|
||||
use crate::formatted_text::{Run, RunSet};
|
||||
use crate::inspector::editors::cell::CellPropertyEditorDefinition;
|
||||
use crate::inspector::editors::texture_slice::TextureSlicePropertyEditorDefinition;
|
||||
use crate::{
|
||||
absm::{EventAction, EventKind},
|
||||
bit::BitField,
|
||||
@@ -47,13 +43,16 @@ use crate::{
|
||||
decorator::Decorator,
|
||||
dropdown_list::DropdownList,
|
||||
expander::Expander,
|
||||
formatted_text::{FormattedText, WrapMode},
|
||||
font::FontResource,
|
||||
formatted_text::{FormattedText, Run, RunSet, WrapMode},
|
||||
grid::{Grid, GridDimension, SizeMode},
|
||||
image::Image,
|
||||
inspector::{
|
||||
editors::{
|
||||
array::ArrayPropertyEditorDefinition,
|
||||
bool::BoolPropertyEditorDefinition,
|
||||
cell::CellPropertyEditorDefinition,
|
||||
char::CharPropertyEditorDefinition,
|
||||
collection::{CollectionItem, VecCollectionPropertyEditorDefinition},
|
||||
color::{ColorGradientPropertyEditorDefinition, ColorPropertyEditorDefinition},
|
||||
curve::CurvePropertyEditorDefinition,
|
||||
@@ -71,6 +70,7 @@ use crate::{
|
||||
refcell::RefCellPropertyEditorDefinition,
|
||||
string::StringPropertyEditorDefinition,
|
||||
style::StyledPropertyEditorDefinition,
|
||||
texture_slice::TextureSlicePropertyEditorDefinition,
|
||||
utf32::Utf32StringPropertyEditorDefinition,
|
||||
uuid::UuidPropertyEditorDefinition,
|
||||
vec::{
|
||||
@@ -129,6 +129,7 @@ pub mod array;
|
||||
pub mod bit;
|
||||
pub mod bool;
|
||||
pub mod cell;
|
||||
pub mod char;
|
||||
pub mod collection;
|
||||
pub mod color;
|
||||
pub mod curve;
|
||||
@@ -145,7 +146,7 @@ pub mod range;
|
||||
pub mod rect;
|
||||
pub mod refcell;
|
||||
pub mod string;
|
||||
mod style;
|
||||
pub mod style;
|
||||
pub mod texture_slice;
|
||||
pub mod utf32;
|
||||
pub mod uuid;
|
||||
@@ -616,6 +617,10 @@ impl PropertyEditorDefinitionContainer {
|
||||
container.insert(EnumPropertyEditorDefinition::<Brush>::new_optional());
|
||||
container.insert(EnumPropertyEditorDefinition::<Vector2<f32>>::new_optional());
|
||||
|
||||
container.insert(InheritablePropertyEditorDefinition::<Option<char>>::new());
|
||||
container.insert(EnumPropertyEditorDefinition::<char>::new_optional());
|
||||
container.insert(CharPropertyEditorDefinition);
|
||||
|
||||
// Styled.
|
||||
container.insert(InheritablePropertyEditorDefinition::<StyledProperty<f32>>::new());
|
||||
container.insert(StyledPropertyEditorDefinition::<f32>::new());
|
||||
|
||||
Reference in New Issue
Block a user