Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
add box config
Browse files Browse the repository at this point in the history
  • Loading branch information
ogios committed Jul 31, 2024
1 parent ed496e8 commit faab6cc
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 39 deletions.
34 changes: 3 additions & 31 deletions config/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
}
Expand Down
96 changes: 96 additions & 0 deletions config/defs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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" }]
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/config/widgets/wrapbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
13 changes: 7 additions & 6 deletions src/ui/widgets/wrapbox/outlook/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand All @@ -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 =
Expand All @@ -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)
Expand All @@ -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();
Expand Down

0 comments on commit faab6cc

Please sign in to comment.