From faab6ccf1ef0cbaa633c612cf8d97256dde4c6b4 Mon Sep 17 00:00:00 2001 From: ogios <2134692955@qq.com> Date: Wed, 31 Jul 2024 12:44:59 +0800 Subject: [PATCH] add box config --- config/config.schema.json | 34 +-------- config/defs.schema.json | 96 ++++++++++++++++++++++++ src/config/widgets/wrapbox.rs | 4 +- src/ui/widgets/wrapbox/outlook/window.rs | 13 ++-- 4 files changed, 108 insertions(+), 39 deletions(-) diff --git a/config/config.schema.json b/config/config.schema.json index 6911d08..a6aa317 100644 --- a/config/config.schema.json +++ b/config/config.schema.json @@ -4,20 +4,8 @@ "numOrPercentage": { "$ref": "https://raw.githubusercontent.com/ogios/way-edges/master/config/defs.schema.json#UtilNumOrPercentage" }, - "BtnWidget": { - "$ref": "https://raw.githubusercontent.com/ogios/way-edges/master/config/defs.schema.json#BtnWidget" - }, - "SlideWidget": { - "$ref": "https://raw.githubusercontent.com/ogios/way-edges/master/config/defs.schema.json#SlideWidget" - }, - "SpeakerWidget": { - "$ref": "https://raw.githubusercontent.com/ogios/way-edges/master/config/defs.schema.json#Speaker" - }, - "MicrophoneWidget": { - "$ref": "https://raw.githubusercontent.com/ogios/way-edges/master/config/defs.schema.json#Microphone" - }, - "BacklightWidget": { - "$ref": "https://raw.githubusercontent.com/ogios/way-edges/master/config/defs.schema.json#Backlight" + "AllWidgets": { + "$ref": "https://raw.githubusercontent.com/ogios/way-edges/master/config/defs.schema.json#AllWidgets" } }, "title": "way-edges config", @@ -88,23 +76,7 @@ }, "widget": { "description": "Select one widget type", - "oneOf": [ - { - "$ref": "#/definitions/BtnWidget" - }, - { - "$ref": "#/definitions/SpeakerWidget" - }, - { - "$ref": "#/definitions/MicrophoneWidget" - }, - { - "$ref": "#/definitions/SlideWidget" - }, - { - "$ref": "#/definitions/BacklightWidget" - } - ] + "$ref": "#/definitions/AllWidgets" } } } diff --git a/config/defs.schema.json b/config/defs.schema.json index e352186..d15b2fa 100644 --- a/config/defs.schema.json +++ b/config/defs.schema.json @@ -69,6 +69,31 @@ } }, + "widgets": { + "$id": "#AllWidgets", + "description": "All widgets in the config file", + "oneOf": [ + { + "$ref": "#BtnWidget" + }, + { + "$ref": "#SpeakerWidget" + }, + { + "$ref": "#MicrophoneWidget" + }, + { + "$ref": "#SlideWidget" + }, + { + "$ref": "#BacklightWidget" + }, + { + "$ref": "#Box" + } + ] + }, + "BtnWidget": { "$id": "#BtnWidget", "description": "Button widget specific properties", @@ -246,6 +271,77 @@ } } ] + }, + + "BoxOutlookWindow": { + "$id": "#BoxOutlookWindow", + "description": "Box Outlook `Window`", + "properties": { + "type": { + "type": "string", + "const": "window" + }, + "margins": { + "type": "array", + "description": "left, top, right, bottom", + "prefixItems": [ + { "type": "number" }, + { "type": "number" }, + { "type": "number" }, + { "type": "number" } + ] + }, + "color": { + "$ref": "#UtilColor" + }, + "border_radius": { + "type": "number", + "minimum": 1 + }, + "border_width": { + "type": "number", + "minimum": 1 + } + } + }, + "Box": { + "$id": "#Box", + "description": "Box widgets with grid layout, only support limited widgets", + "properties": { + "widgets": { + "type": "array", + "items": { + "properties": { + "index": { + "type": "array", + "description": "index of the widget's position in the grid", + "prefixItems": [{ "type": "number" }, { "type": "number" }] + }, + "widget": { + "description": "widget type, only Ring supported for now", + "$ref": "#AllWidgets" + } + } + } + }, + "gap": { + "description": "gap between each widget", + "type": "number", + "minimum": 0 + }, + "frame_rate": { + "$ref": "#UtilCommon/properties/frame_rate" + }, + "extra_trigger_size": { + "$ref": "#UtilCommon/properties/extra_trigger_size" + }, + "transition_duration": { + "$ref": "#UtilCommon/properties/transition_duration" + }, + "outloook": { + "oneOf": [{ "$ref": "#BoxOutlookWindow" }] + } + } } } } diff --git a/src/config/widgets/wrapbox.rs b/src/config/widgets/wrapbox.rs index fed587b..17ec3c5 100644 --- a/src/config/widgets/wrapbox.rs +++ b/src/config/widgets/wrapbox.rs @@ -16,9 +16,9 @@ pub struct OutlookWindowConfig { pub margins: Option<[f64; 4]>, #[serde(default = "dt_color")] #[serde(deserialize_with = "common::color_translate")] - pub border_color: RGBA, + pub color: RGBA, #[serde(default = "dt_radius")] - pub radius: f64, + pub border_radius: f64, #[serde(default = "dt_border_width")] pub border_width: f64, } diff --git a/src/ui/widgets/wrapbox/outlook/window.rs b/src/ui/widgets/wrapbox/outlook/window.rs index 5081a4b..d45bf1d 100644 --- a/src/ui/widgets/wrapbox/outlook/window.rs +++ b/src/ui/widgets/wrapbox/outlook/window.rs @@ -37,8 +37,8 @@ pub struct BoxOutlookWindow { impl BoxOutlookWindow { pub fn redraw(&mut self, content_size: (f64, f64)) { let margins = self.config.margins; - let border_color = self.config.border_color; - let radius = self.config.radius; + let color = self.config.color; + let border_radius = self.config.border_radius; let border_width = self.config.border_width; let ([content_box_size, size, startoff_point], margins) = @@ -47,7 +47,7 @@ impl BoxOutlookWindow { let mut shade = RGBA::BLACK; shade.set_alpha(0.2); let one = shade; - let two = border_color; + let two = color; let a = 1. - (1. - one.alpha()) * (1. - two.alpha()); let r = (one.red() * one.alpha() + two.red() * two.alpha() * (1. - one.alpha())) / a; let g = @@ -60,11 +60,11 @@ impl BoxOutlookWindow { move |s: (i32, i32)| ImageSurface::create(Format::ARgb32, s.0, s.1).unwrap(); let (border_path, border) = { - let path = draw_rect_path(radius, size, [false, true, true, false]).unwrap(); + let path = draw_rect_path(border_radius, size, [false, true, true, false]).unwrap(); let map_size = (size.0.ceil() as i32, size.1.ceil() as i32); let surf = new_surface(map_size); let ctx = cairo::Context::new(&surf).unwrap(); - ctx.set_source_color(&border_color); + ctx.set_source_color(&color); ctx.append_path(&path); ctx.fill().unwrap(); (path, surf) @@ -75,7 +75,8 @@ impl BoxOutlookWindow { content_box_size.0.ceil() as i32, content_box_size.1.ceil() as i32, ); - let path = draw_rect_path(radius, content_box_size, [true, true, true, true]).unwrap(); + let path = + draw_rect_path(border_radius, content_box_size, [true, true, true, true]).unwrap(); let bg_surf = { let surf = new_surface(map_size); let ctx = cairo::Context::new(&surf).unwrap();