We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 9d8562f + 9193d6d commit 996c7a1Copy full SHA for 996c7a1
12 files changed
Cargo.toml
@@ -50,6 +50,7 @@ windows-sys = { version = "0.60", features = [
50
] }
51
windows = { version = "0.61", features = [
52
"Foundation_Numerics",
53
+ "UI_ViewManagement",
54
"Win32_Foundation",
55
"Win32_Graphics_Direct2D",
56
"Win32_Graphics_Direct2D_Common",
examples/widgets.rs
@@ -5,7 +5,7 @@ use winio::{
5
LinearGradientBrush, Margin, MessageBox, MessageBoxButton, ObservableVec, ObservableVecEvent,
6
Orient, Point, Progress, RadialGradientBrush, RadioButton, RadioButtonGroup, Rect,
7
RelativePoint, RelativeSize, Size, SolidColorBrush, StackPanel, TextBox, VAlign, Visible,
8
- Window, WindowEvent, init, start,
+ Window, WindowEvent, accent_color, init, start,
9
};
10
11
fn main() {
@@ -382,7 +382,10 @@ impl Component for MainModel {
382
let brush3 = RadialGradientBrush::new(
383
[
384
GradientStop::new(Color::new(0xF5, 0xF5, 0xF5, 0xFF), 0.0),
385
- GradientStop::new(Color::new(0xFF, 0xC0, 0xCB, 0xFF), 1.0),
+ GradientStop::new(
386
+ accent_color().unwrap_or(Color::new(0xFF, 0xC0, 0xCB, 0xFF)),
387
+ 1.0,
388
+ ),
389
],
390
RelativePoint::new(0.5, 0.5),
391
RelativePoint::new(0.2, 0.5),
src/ui/gtk/accent.rs
@@ -0,0 +1,6 @@
1
+use crate::Color;
2
+
3
+/// Get the accent color.
4
+pub fn accent_color() -> Option<Color> {
+ None
+}
src/ui/gtk/mod.rs
@@ -37,6 +37,9 @@ pub use combo_box::*;
37
mod check_box;
38
pub use check_box::*;
39
40
+mod accent;
41
+pub use accent::*;
42
43
/// GTK [`Window`].
44
///
45
/// [`Window`]: gtk4::Window
src/ui/mac/accent.rs
@@ -0,0 +1,25 @@
+use objc2_app_kit::{NSColor, NSColorSpace};
+ unsafe {
+ let accent = NSColor::controlAccentColor();
+ let color_space = NSColorSpace::genericRGBColorSpace();
+ let accent = accent.colorUsingColorSpace(&color_space);
+ accent.map(|accent| {
12
+ let mut r: f64 = 0.0;
13
+ let mut g: f64 = 0.0;
14
+ let mut b: f64 = 0.0;
15
+ let mut a: f64 = 0.0;
16
+ accent.getRed_green_blue_alpha(&mut r, &mut g, &mut b, &mut a);
17
+ Color::new(
18
+ (r * 255.0) as u8,
19
+ (g * 255.0) as u8,
20
+ (b * 255.0) as u8,
21
+ (a * 255.0) as u8,
22
+ )
23
+ })
24
+ }
25
src/ui/mac/mod.rs
@@ -31,6 +31,9 @@ pub use progress::*;
31
mod combo_box;
32
pub use combo_box::*;
33
34
35
36
/// [`NSWindow`].
pub type RawWindow = Retained<NSWindow>;
src/ui/mod.rs
@@ -37,7 +37,7 @@ pub mod export {
filebox::*,
monitor::*,
msgbox::*,
- sys::{Brush, Pen, RawWindow},
+ sys::{Brush, Pen, RawWindow, accent_color},
window_handle::*,
}
src/ui/qt/canvas.cpp
@@ -1,4 +1,5 @@
#include "canvas.hpp"
+#include <QApplication>
#include <QBrush>
#include <QFont>
#include <QLinearGradient>
@@ -92,6 +93,16 @@ void painter_draw_text(QPainter &p, QRectF rect, rust::Str text) {
92
93
94
void color_transparent(QColor &c) { new (&c) QColor{Qt::transparent}; }
95
96
+bool color_accent(QColor &c) {
97
+#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
98
+ auto accent = QApplication::palette().color(QPalette::Accent);
99
+ new (&c) QColor{accent};
100
+ return true;
101
+#else
102
+ return false;
103
+#endif
104
105
106
std::unique_ptr<QBrush> new_brush(QColor const &c) {
107
return std::make_unique<QBrush>(c);
108
src/ui/qt/canvas.hpp
@@ -51,6 +51,7 @@ QSizeF painter_measure_text(QPainter &p, QRectF rect, rust::Str text);
void painter_draw_text(QPainter &p, QRectF rect, rust::Str text);
void color_transparent(QColor &c);
+bool color_accent(QColor &c);
std::unique_ptr<QBrush> new_brush(QColor const &c);
std::unique_ptr<QPen> new_pen(QBrush const &b, double width);
57
src/ui/qt/canvas.rs
@@ -468,6 +468,11 @@ impl DrawingImage {
468
469
470
471
472
473
+ QColor::accent().map(From::from)
474
475
476
#[repr(i32)]
477
#[non_exhaustive]
478
#[allow(clippy::enum_variant_names)]
@@ -564,6 +569,18 @@ impl QColor {
564
569
ffi::color_transparent(Pin::new(&mut c));
565
570
c
566
571
572
573
+ pub fn accent() -> Option<Self> {
574
+ let mut c = Self {
575
+ cspec: Spec::Invalid,
576
+ ct: [0; 5],
577
+ };
578
+ if ffi::color_accent(Pin::new(&mut c)) {
579
+ Some(c)
580
+ } else {
581
582
583
567
584
568
585
586
impl From<Color> for QColor {
@@ -695,6 +712,7 @@ mod ffi {
695
712
fn setPen(self: Pin<&mut QPainter>, color: &QColor);
696
713
697
714
fn color_transparent(c: Pin<&mut QColor>);
715
+ fn color_accent(c: Pin<&mut QColor>) -> bool;
698
716
fn new_brush(c: &QColor) -> UniquePtr<QBrush>;
699
717
fn new_pen(b: &QBrush, width: f64) -> UniquePtr<QPen>;
700
718
0 commit comments