Compare commits
2 Commits
buf_action
...
add-theme-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
994729080a | ||
|
|
39be9e5949 |
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
@@ -65,13 +65,13 @@ jobs:
|
||||
echo "BUF_BASE_BRANCH=$GITHUB_BASE_REF" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Protobuf checks
|
||||
uses: bufbuild/buf-action@v1
|
||||
- uses: bufbuild/buf-setup-action@v1
|
||||
with:
|
||||
version: v1.29.0
|
||||
- uses: bufbuild/buf-breaking-action@v1
|
||||
with:
|
||||
version: 1.35.0
|
||||
input: "crates/proto/proto/"
|
||||
breaking_against: "https://github.com/${GITHUB_REPOSITORY}.git#branch=${GITHUB_BASE_REF},subdir=crates/proto/proto/"
|
||||
lint: false
|
||||
against: "https://github.com/${GITHUB_REPOSITORY}.git#branch=${BUF_BASE_BRANCH},subdir=crates/proto/proto/"
|
||||
|
||||
macos_tests:
|
||||
timeout-minutes: 60
|
||||
|
||||
@@ -36,9 +36,6 @@
|
||||
"RUST_DEFAULT_PACKAGE_RUN": "zed"
|
||||
}
|
||||
}
|
||||
},
|
||||
"proto": {
|
||||
"tab_size": 2
|
||||
}
|
||||
},
|
||||
"file_types": {
|
||||
|
||||
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -11488,6 +11488,7 @@ dependencies = [
|
||||
"palette",
|
||||
"parking_lot",
|
||||
"refineable",
|
||||
"regex",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
|
||||
168
crates/gpui/examples/window.rs
Normal file
168
crates/gpui/examples/window.rs
Normal file
@@ -0,0 +1,168 @@
|
||||
use gpui::*;
|
||||
use prelude::FluentBuilder as _;
|
||||
|
||||
struct SubWindow {
|
||||
custom_titlebar: bool,
|
||||
}
|
||||
|
||||
fn button(text: &str, on_click: impl Fn(&mut WindowContext) + 'static) -> impl IntoElement {
|
||||
div()
|
||||
.id(SharedString::from(text.to_string()))
|
||||
.flex_none()
|
||||
.px_2()
|
||||
.bg(rgb(0xf7f7f7))
|
||||
.active(|this| this.opacity(0.85))
|
||||
.border_1()
|
||||
.border_color(rgb(0xe0e0e0))
|
||||
.rounded_md()
|
||||
.cursor_pointer()
|
||||
.child(text.to_string())
|
||||
.on_click(move |_, cx| on_click(cx))
|
||||
}
|
||||
|
||||
impl Render for SubWindow {
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.bg(rgb(0xffffff))
|
||||
.size_full()
|
||||
.gap_2()
|
||||
.when(self.custom_titlebar, |cx| {
|
||||
cx.child(
|
||||
div()
|
||||
.flex()
|
||||
.h(px(32.))
|
||||
.px_4()
|
||||
.bg(gpui::blue())
|
||||
.text_color(gpui::white())
|
||||
.w_full()
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.size_full()
|
||||
.child("Custom Titlebar"),
|
||||
),
|
||||
)
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
.p_8()
|
||||
.gap_2()
|
||||
.child("SubWindow")
|
||||
.child(button("Close", |cx| {
|
||||
cx.remove_window();
|
||||
})),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct WindowDemo {}
|
||||
|
||||
impl Render for WindowDemo {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let window_bounds =
|
||||
WindowBounds::Windowed(Bounds::centered(None, size(px(300.0), px(300.0)), cx));
|
||||
|
||||
div()
|
||||
.p_4()
|
||||
.flex()
|
||||
.flex_wrap()
|
||||
.bg(rgb(0xffffff))
|
||||
.size_full()
|
||||
.justify_center()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.child(button("Normal", move |cx| {
|
||||
cx.open_window(
|
||||
WindowOptions {
|
||||
window_bounds: Some(window_bounds),
|
||||
..Default::default()
|
||||
},
|
||||
|cx| {
|
||||
cx.new_view(|_cx| SubWindow {
|
||||
custom_titlebar: false,
|
||||
})
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}))
|
||||
.child(button("Popup", move |cx| {
|
||||
cx.open_window(
|
||||
WindowOptions {
|
||||
window_bounds: Some(window_bounds),
|
||||
kind: WindowKind::PopUp,
|
||||
..Default::default()
|
||||
},
|
||||
|cx| {
|
||||
cx.new_view(|_cx| SubWindow {
|
||||
custom_titlebar: false,
|
||||
})
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}))
|
||||
.child(button("Custom Titlebar", move |cx| {
|
||||
cx.open_window(
|
||||
WindowOptions {
|
||||
titlebar: None,
|
||||
window_bounds: Some(window_bounds),
|
||||
..Default::default()
|
||||
},
|
||||
|cx| {
|
||||
cx.new_view(|_cx| SubWindow {
|
||||
custom_titlebar: true,
|
||||
})
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}))
|
||||
.child(button("Invisible", move |cx| {
|
||||
cx.open_window(
|
||||
WindowOptions {
|
||||
show: false,
|
||||
window_bounds: Some(window_bounds),
|
||||
..Default::default()
|
||||
},
|
||||
|cx| {
|
||||
cx.new_view(|_cx| SubWindow {
|
||||
custom_titlebar: false,
|
||||
})
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}))
|
||||
.child(button("Unmovable", move |cx| {
|
||||
cx.open_window(
|
||||
WindowOptions {
|
||||
is_movable: false,
|
||||
titlebar: None,
|
||||
window_bounds: Some(window_bounds),
|
||||
..Default::default()
|
||||
},
|
||||
|cx| {
|
||||
cx.new_view(|_cx| SubWindow {
|
||||
custom_titlebar: false,
|
||||
})
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new().run(|cx: &mut AppContext| {
|
||||
let bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx);
|
||||
cx.open_window(
|
||||
WindowOptions {
|
||||
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||
..Default::default()
|
||||
},
|
||||
|cx| cx.new_view(|_cx| WindowDemo {}),
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
@@ -707,7 +707,7 @@ impl MacWindow {
|
||||
}
|
||||
}
|
||||
|
||||
if focus {
|
||||
if focus && show {
|
||||
native_window.makeKeyAndOrderFront_(nil);
|
||||
} else if show {
|
||||
native_window.orderFront_(nil);
|
||||
|
||||
@@ -287,7 +287,7 @@ impl WindowsWindow {
|
||||
.map(|title| title.as_ref())
|
||||
.unwrap_or(""),
|
||||
);
|
||||
let (dwexstyle, dwstyle) = if params.kind == WindowKind::PopUp {
|
||||
let (dwexstyle, mut dwstyle) = if params.kind == WindowKind::PopUp {
|
||||
(WS_EX_TOOLWINDOW, WINDOW_STYLE(0x0))
|
||||
} else {
|
||||
(
|
||||
@@ -295,6 +295,10 @@ impl WindowsWindow {
|
||||
WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
|
||||
)
|
||||
};
|
||||
if !params.show {
|
||||
dwstyle |= WS_MINIMIZE;
|
||||
}
|
||||
|
||||
let hinstance = get_module_handle();
|
||||
let display = if let Some(display_id) = params.display_id {
|
||||
// if we obtain a display_id, then this ID must be valid.
|
||||
@@ -357,7 +361,12 @@ impl WindowsWindow {
|
||||
drop(lock);
|
||||
SetWindowPlacement(raw_hwnd, &placement)?;
|
||||
}
|
||||
unsafe { ShowWindow(raw_hwnd, SW_SHOW).ok()? };
|
||||
|
||||
if params.show {
|
||||
unsafe { ShowWindow(raw_hwnd, SW_SHOW).ok()? };
|
||||
} else {
|
||||
unsafe { ShowWindow(raw_hwnd, SW_HIDE).ok()? };
|
||||
}
|
||||
|
||||
Ok(Self(state_ptr))
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,7 @@ settings.workspace = true
|
||||
story = { workspace = true, optional = true }
|
||||
util.workspace = true
|
||||
uuid.workspace = true
|
||||
regex.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
fs = { workspace = true, features = ["test-support"] }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use gpui::{FontStyle, FontWeight, HighlightStyle, Hsla, WindowBackgroundAppearance};
|
||||
use anyhow::{anyhow, Result};
|
||||
use gpui::{FontStyle, FontWeight, HighlightStyle, Hsla, Rgba, WindowBackgroundAppearance};
|
||||
use indexmap::IndexMap;
|
||||
use palette::FromColor;
|
||||
use regex::Regex;
|
||||
use schemars::gen::SchemaGenerator;
|
||||
use schemars::schema::{Schema, SchemaObject};
|
||||
use schemars::JsonSchema;
|
||||
@@ -11,19 +11,34 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
|
||||
use crate::{StatusColorsRefinement, ThemeColorsRefinement};
|
||||
|
||||
fn parse_hsl(color: &str) -> Result<Hsla> {
|
||||
let re = Regex::new(r"hsla?\((\d+),\s*(\d+)%,\s*(\d+)%(?:,\s*([\d.]+))?\)")?;
|
||||
let caps = re
|
||||
.captures(color)
|
||||
.ok_or_else(|| anyhow!("Invalid HSL(A) format"))?;
|
||||
|
||||
let h = caps.get(1).unwrap().as_str().parse::<f32>()? / 360.0;
|
||||
let s = caps.get(2).unwrap().as_str().parse::<f32>()? / 100.0;
|
||||
let l = caps.get(3).unwrap().as_str().parse::<f32>()? / 100.0;
|
||||
let a = caps.get(4).map_or(Ok(1.0), |m| m.as_str().parse::<f32>())?;
|
||||
|
||||
Ok(Hsla { h, s, l, a })
|
||||
}
|
||||
|
||||
pub(crate) fn try_parse_color(color: &str) -> Result<Hsla> {
|
||||
let rgba = gpui::Rgba::try_from(color)?;
|
||||
let rgba = palette::rgb::Srgba::from_components((rgba.r, rgba.g, rgba.b, rgba.a));
|
||||
let hsla = palette::Hsla::from_color(rgba);
|
||||
let color = color.trim();
|
||||
|
||||
let hsla = gpui::hsla(
|
||||
hsla.hue.into_positive_degrees() / 360.,
|
||||
hsla.saturation,
|
||||
hsla.lightness,
|
||||
hsla.alpha,
|
||||
);
|
||||
if color.starts_with('#') {
|
||||
let rgba = Rgba::try_from(color)?;
|
||||
return Ok(Hsla::from(rgba));
|
||||
}
|
||||
|
||||
Ok(hsla)
|
||||
if color.starts_with("hsl") {
|
||||
return parse_hsl(color);
|
||||
}
|
||||
|
||||
let rgba = Rgba::try_from(color)?;
|
||||
Ok(Hsla::from(rgba))
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
|
||||
|
||||
Reference in New Issue
Block a user