feat: add JsonSchema to gpui
This commit is contained in:
parent
cfc1856210
commit
b45f5f0489
9 changed files with 90 additions and 35 deletions
|
@ -12,6 +12,11 @@ use crate::{
|
|||
scene::{self, Border, CursorRegion, Quad},
|
||||
AnyElement, Element, LayoutContext, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
use schemars::{
|
||||
gen::SchemaGenerator,
|
||||
schema::{InstanceType, Schema, SchemaObject},
|
||||
JsonSchema,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -332,6 +337,19 @@ impl ToJson for ContainerStyle {
|
|||
}
|
||||
}
|
||||
|
||||
impl JsonSchema for ContainerStyle {
|
||||
fn schema_name() -> String {
|
||||
"ContainerStyle".into()
|
||||
}
|
||||
|
||||
fn json_schema(_: &mut SchemaGenerator) -> Schema {
|
||||
let mut schema = SchemaObject::default();
|
||||
schema.instance_type = Some(InstanceType::Integer.into());
|
||||
schema.format = Some("uint".to_owned());
|
||||
Schema::Object(schema)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Margin {
|
||||
pub top: f32,
|
||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
|||
scene, Border, Element, ImageData, LayoutContext, SceneBuilder, SizeConstraint, View,
|
||||
ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use std::{ops::Range, sync::Arc};
|
||||
|
||||
|
@ -21,7 +22,7 @@ pub struct Image {
|
|||
style: ImageStyle,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Deserialize)]
|
||||
#[derive(Copy, Clone, Default, Deserialize, JsonSchema)]
|
||||
pub struct ImageStyle {
|
||||
#[serde(default)]
|
||||
pub border: Border,
|
||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
|||
text_layout::{Line, RunStyle},
|
||||
Element, LayoutContext, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
@ -20,7 +21,7 @@ pub struct Label {
|
|||
highlight_indices: Vec<usize>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Default)]
|
||||
#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
|
||||
pub struct LabelStyle {
|
||||
pub text: TextStyle,
|
||||
pub highlight_text: Option<TextStyle>,
|
||||
|
|
|
@ -9,6 +9,7 @@ use crate::{
|
|||
Action, Axis, ElementStateHandle, LayoutContext, SceneBuilder, SizeConstraint, Task, View,
|
||||
ViewContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
|
@ -33,7 +34,7 @@ struct TooltipState {
|
|||
debounce: RefCell<Option<Task<()>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Default)]
|
||||
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
||||
pub struct TooltipStyle {
|
||||
#[serde(flatten)]
|
||||
pub container: ContainerStyle,
|
||||
|
@ -42,7 +43,7 @@ pub struct TooltipStyle {
|
|||
pub max_text_width: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Default)]
|
||||
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
||||
pub struct KeystrokeStyle {
|
||||
#[serde(flatten)]
|
||||
container: ContainerStyle,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue