GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
refactor: rename Window widget to Backplate to avoid OS window naming collision
src/backend/window_runner.rs | 6 ++---
src/color.rs | 33 ++++++++++++-----------
src/context.rs | 12 ++++-----
src/widget/container/{window.rs => backplate.rs} | 34 ++++++++++++------------
src/widget/container/mod.rs | 4 +--
src/widget/mod.rs | 6 ++---
6 files changed, 48 insertions(+), 47 deletions(-)
diff --git a/src/backend/window_runner.rs b/src/backend/window_runner.rs
index e39096f..49ca225 100644
--- a/src/backend/window_runner.rs
+++ b/src/backend/window_runner.rs
@@ -946,9 +946,9 @@ pub trait Application: Sized + 'static {
None
}
- fn is_movable_window_at(&self, px: f32, py: f32) -> bool {
+ fn is_movable_backplate_at(&self, px: f32, py: f32) -> bool {
if let Some(ctx) = self.ui_context() {
- ctx.is_movable_window_at(px, py)
+ ctx.is_movable_backplate_at(px, py)
} else {
false
}
@@ -1770,7 +1770,7 @@ impl<A: Application> PointerHandler for EngineState<A> {
let mut should_move = false;
if ly >= border && ly < 32.0 && lx < self.logical_width - 70.0 {
should_move = true;
- } else if self.inner.is_movable_window_at(lx, ly) {
+ } else if self.inner.is_movable_backplate_at(lx, ly) {
should_move = true;
}
diff --git a/src/color.rs b/src/color.rs
index 9c7a35e..6976b4e 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -33,7 +33,7 @@ static SIDEBAR_BG_COLOR: RwLock<[f32; 4]> = RwLock::new(SIDEBAR_BG);
static HIGHLIGHT_PRIMARY_COLOR: RwLock<[f32; 4]> = RwLock::new(HIGHLIGHT_PRIMARY);
static MENUBAR_TAB_LABEL_COLOR: RwLock<[f32; 4]> = RwLock::new([0.90196, 0.90196, 0.94902, 1.0]); // sRGB [230, 230, 242] linear
static OPACITY: RwLock<Option<f32>> = RwLock::new(None);
-static WINDOW_OPACITY: RwLock<Option<f32>> = RwLock::new(None);
+static BACKPLATE_OPACITY: RwLock<Option<f32>> = RwLock::new(None);
static TOGGLE_ON_COLOR: RwLock<[f32; 4]> = RwLock::new(TOGGLE_ON);
static TOGGLE_OFF_COLOR: RwLock<[f32; 4]> = RwLock::new(TOGGLE_OFF);
static SCROLLINGLIST_BG_COLOR: RwLock<[f32; 4]> = RwLock::new([0.08, 0.08, 0.12, 0.3]);
@@ -43,7 +43,7 @@ static BREADCRUMB_BG_COLOR: RwLock<[f32; 4]> = RwLock::new([0.08, 0.08, 0.12, 1.
static POPOVER_BG_COLOR: RwLock<[f32; 4]> = RwLock::new([0.08, 0.08, 0.12, 1.0]);
static PAGE_COLOR: RwLock<[f32; 4]> = RwLock::new([0.0, 0.0, 0.0, 0.0]);
static LAYER_COLOR: RwLock<[f32; 4]> = RwLock::new([0.0, 0.0, 0.0, 0.0]);
-static WINDOW_CORNER_RADIUS: RwLock<f32> = RwLock::new(12.0);
+static BACKPLATE_CORNER_RADIUS: RwLock<f32> = RwLock::new(12.0);
@@ -104,14 +104,14 @@ fn parse_and_set_colors(content: &str) {
}
}
- if let Some(w_opacity) = val.pointer("/surfaces/window_opacity").and_then(|v| v.as_f64()) {
- if let Ok(mut lock) = WINDOW_OPACITY.write() {
+ if let Some(w_opacity) = val.pointer("/surfaces/backplate_opacity").or_else(|| val.pointer("/surfaces/window_opacity")).and_then(|v| v.as_f64()) {
+ if let Ok(mut lock) = BACKPLATE_OPACITY.write() {
*lock = Some(w_opacity as f32);
}
}
- if let Some(radius) = val.pointer("/surfaces/window_corner_radius").and_then(|v| v.as_f64()) {
- if let Ok(mut lock) = WINDOW_CORNER_RADIUS.write() {
+ if let Some(radius) = val.pointer("/surfaces/backplate_corner_radius").or_else(|| val.pointer("/surfaces/window_corner_radius")).and_then(|v| v.as_f64()) {
+ if let Ok(mut lock) = BACKPLATE_CORNER_RADIUS.write() {
*lock = radius as f32;
}
}
@@ -151,7 +151,7 @@ fn parse_and_set_colors(content: &str) {
val.pointer(pointer).and_then(|v| v.as_str()).and_then(parse_hex)
};
- if let Some(c) = get_color("/surfaces/window_color").or_else(|| get_color("/layout/page_low_color")) {
+ if let Some(c) = get_color("/surfaces/backplate_color").or_else(|| get_color("/surfaces/window_color")).or_else(|| get_color("/layout/page_low_color")) {
if let Ok(mut lock) = PAGE_LOW_COLOR.write() { *lock = c; }
}
if let Some(c) = get_color("/layout/color_borders_color") {
@@ -242,7 +242,7 @@ pub fn reload_colors(content: &str) {
pub fn page_low_color() -> [f32; 4] {
load_colors_once();
let mut color = *PAGE_LOW_COLOR.read().unwrap();
- if let Some(opacity) = read_window_opacity_if_configured() {
+ if let Some(opacity) = read_backplate_opacity_if_configured() {
color[3] = opacity;
}
color
@@ -397,9 +397,9 @@ pub fn read_opacity_if_configured() -> Option<f32> {
*OPACITY.read().unwrap()
}
-pub fn read_window_opacity_if_configured() -> Option<f32> {
+pub fn read_backplate_opacity_if_configured() -> Option<f32> {
load_colors_once();
- *WINDOW_OPACITY.read().unwrap()
+ *BACKPLATE_OPACITY.read().unwrap()
}
pub fn toggle_on_color() -> [f32; 4] {
@@ -479,13 +479,13 @@ pub fn set_popover_bg_color(color: [f32; 4]) {
}
}
-pub fn window_corner_radius() -> f32 {
+pub fn backplate_corner_radius() -> f32 {
load_colors_once();
- *WINDOW_CORNER_RADIUS.read().unwrap()
+ *BACKPLATE_CORNER_RADIUS.read().unwrap()
}
-pub fn set_window_corner_radius(radius: f32) {
- if let Ok(mut lock) = WINDOW_CORNER_RADIUS.write() {
+pub fn set_backplate_corner_radius(radius: f32) {
+ if let Ok(mut lock) = BACKPLATE_CORNER_RADIUS.write() {
*lock = radius;
}
}
@@ -556,7 +556,7 @@ pub fn active_window_mode() -> String {
"floating".to_string()
}
-pub fn active_window_opacity() -> f32 {
+pub fn active_backplate_opacity() -> f32 {
let mode = active_window_mode();
let config_path = "/home/lsgalante/.config/cce/config.json";
let content = match std::fs::read_to_string(config_path) {
@@ -591,7 +591,8 @@ pub fn active_window_opacity() -> f32 {
"pinned_opacity" => 0.05,
"popup_opacity" => 0.20,
_ => {
- val.pointer("/surfaces/window_opacity")
+ val.pointer("/surfaces/backplate_opacity")
+ .or_else(|| val.pointer("/surfaces/window_opacity"))
.and_then(|v| v.as_f64())
.map(|v| v as f32)
.unwrap_or(0.9)
diff --git a/src/context.rs b/src/context.rs
index 0465fe1..d8e6337 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -478,16 +478,16 @@ impl UiContext {
crate::widget::context_menu::text_labels()
}
- pub fn is_movable_window_at(&self, px: f32, py: f32) -> bool {
- let mut hit_window = false;
+ pub fn is_movable_backplate_at(&self, px: f32, py: f32) -> bool {
+ let mut hit_backplate = false;
for &ptr in self.widget_registry.values() {
unsafe {
if !ptr.is_null() {
let w = &*ptr;
if w.hit_test(px, py, self) {
- if w.is_window() {
- if w.is_movable_window() {
- hit_window = true;
+ if w.is_backplate() {
+ if w.is_movable_backplate() {
+ hit_backplate = true;
}
} else {
return false;
@@ -496,6 +496,6 @@ impl UiContext {
}
}
}
- hit_window
+ hit_backplate
}
}
diff --git a/src/widget/container/window.rs b/src/widget/container/backplate.rs
similarity index 93%
rename from src/widget/container/window.rs
rename to src/widget/container/backplate.rs
index 4ee641c..9ef6943 100644
--- a/src/widget/container/window.rs
+++ b/src/widget/container/backplate.rs
@@ -3,7 +3,7 @@ use crate::context::UiContext;
use crate::widget::display::TextLabel;
#[derive(Debug, Clone)]
-pub struct Window {
+pub struct Backplate {
pub base: Widget,
pub children: Vec<*mut (dyn Element + 'static)>,
pub parent: Option<*mut (dyn Element + 'static)>,
@@ -15,7 +15,7 @@ pub struct Window {
pub movable: bool,
}
-impl Window {
+impl Backplate {
pub fn new(x: f32, y: f32, w: f32, h: f32) -> Self {
Self {
base: Widget::new_rect(x, y, w, h),
@@ -23,7 +23,7 @@ impl Window {
parent: None,
border_color: None,
border_thickness: 1.0,
- radius: crate::color::window_corner_radius(),
+ radius: crate::color::backplate_corner_radius(),
background_color: None,
visible: true,
movable: true,
@@ -52,7 +52,7 @@ impl Window {
}
}
-impl Element for Window {
+impl Element for Backplate {
fn base(&self) -> Option<&Widget> {
Some(&self.base)
}
@@ -91,7 +91,7 @@ impl Element for Window {
fn color(&self) -> [f32; 4] {
let mut base_color = self.background_color.unwrap_or([0.0, 0.0, 0.0, 0.0]);
if base_color[3] > 0.001 {
- base_color[3] = crate::color::active_window_opacity();
+ base_color[3] = crate::color::active_backplate_opacity();
}
base_color
}
@@ -307,16 +307,16 @@ impl Element for Window {
true
}
- fn is_window(&self) -> bool {
+ fn is_backplate(&self) -> bool {
true
}
- fn is_movable_window(&self) -> bool {
+ fn is_movable_backplate(&self) -> bool {
self.movable
}
}
-impl Drop for Window {
+impl Drop for Backplate {
fn drop(&mut self) {
clear_widget_references(self);
}
@@ -327,8 +327,8 @@ mod tests {
use super::*;
#[test]
- fn test_window_creation_and_builders() {
- let win = Window::new(10.0, 20.0, 100.0, 200.0)
+ fn test_backplate_creation_and_builders() {
+ let win = Backplate::new(10.0, 20.0, 100.0, 200.0)
.with_background([0.1, 0.2, 0.3, 0.4])
.with_border([1.0, 0.0, 0.0, 1.0], 2.5)
.with_radius(8.0);
@@ -338,15 +338,15 @@ mod tests {
assert_eq!(win.solid_border(), Some(([1.0, 0.0, 0.0, 1.0], 2.5)));
assert_eq!(win.corner_radius(), 8.0);
assert_eq!(win.rounded_corners(), (true, true, true, true));
- assert!(win.is_movable_window());
+ assert!(win.is_movable_backplate());
let non_movable_win = win.with_movable(false);
- assert!(!non_movable_win.is_movable_window());
+ assert!(!non_movable_win.is_movable_backplate());
}
#[test]
- fn test_window_visibility() {
- let mut win = Window::new(0.0, 0.0, 100.0, 100.0);
+ fn test_backplate_visibility() {
+ let mut win = Backplate::new(0.0, 0.0, 100.0, 100.0);
assert!(win.visible());
assert!(win.visible);
@@ -356,9 +356,9 @@ mod tests {
}
#[test]
- fn test_window_children_and_parent() {
+ fn test_backplate_children_and_parent() {
let mut ctx = UiContext::new();
- let mut win = Window::new(0.0, 0.0, 100.0, 100.0);
+ let mut win = Backplate::new(0.0, 0.0, 100.0, 100.0);
let child = Layer::new(10.0, 10.0, 50.0, 50.0);
assert_eq!(win.children(&ctx).len(), 0);
@@ -367,7 +367,7 @@ mod tests {
assert_eq!(win.children(&ctx).len(), 1);
assert_eq!(unsafe { (*win.children(&ctx)[0]).rect() }, (10.0, 10.0, 50.0, 50.0));
- // Child's parent should point to Window
+ // Child's parent should point to Backplate
assert_eq!(unsafe { (*child.as_ptr()).parent(&ctx) }, Some(win.as_ptr()));
win.clear_children(&mut ctx);
diff --git a/src/widget/container/mod.rs b/src/widget/container/mod.rs
index 9ec6200..abbff2b 100644
--- a/src/widget/container/mod.rs
+++ b/src/widget/container/mod.rs
@@ -12,7 +12,7 @@ pub mod plate;
pub mod switcher;
pub mod layer;
pub mod page;
-pub mod window;
+pub mod backplate;
pub mod paginator;
pub use container::Container;
@@ -29,5 +29,5 @@ pub use plate::Plate;
pub use switcher::Switcher;
pub use layer::Layer;
pub use page::Page;
-pub use window::Window;
+pub use backplate::Backplate;
pub use paginator::Paginator;
diff --git a/src/widget/mod.rs b/src/widget/mod.rs
index 3770534..95d1d67 100644
--- a/src/widget/mod.rs
+++ b/src/widget/mod.rs
@@ -516,8 +516,8 @@ pub trait Element {
fn is_plate(&self) -> bool { false }
fn is_page(&self) -> bool { false }
fn is_layer(&self) -> bool { false }
- fn is_window(&self) -> bool { false }
- fn is_movable_window(&self) -> bool { false }
+ fn is_backplate(&self) -> bool { false }
+ fn is_movable_backplate(&self) -> bool { false }
fn rounded_corners(&self) -> (bool, bool, bool, bool) { (false, false, false, false) }
fn corner_radius(&self) -> f32 { 12.0 }
@@ -573,7 +573,7 @@ pub use self::input::{
pub use self::container::{
Container, Header, ContentBg, ViewportBg, ParametersBg, ScrollingList,
ScrollBox, Menu, MenuBar, Spreadsheet, Breadcrumb, Plate,
- Switcher, Layer, Page, Window, Paginator
+ Switcher, Layer, Page, Backplate, Paginator
};
pub use self::display::{
TextLabel, Label, SectionHeader, StyledLabel, TextItem, Svg, UsageBar,