Skip to content

Commit

Permalink
Merge pull request #454 from kas-gui/work2
Browse files Browse the repository at this point in the history
Update deps; simpler Rgba8Srgb parse fns
  • Loading branch information
dhardy authored Aug 28, 2024
2 parents 4b97ded + 11358d1 commit 45424b2
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
toolchain: [stable]
include:
- os: ubuntu-latest
toolchain: "1.75.0"
toolchain: "1.79.0"
- os: ubuntu-latest
toolchain: beta

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["gui"]
categories = ["gui"]
repository = "https://github.com/kas-gui/kas"
exclude = ["/examples"]
rust-version = "1.75.0"
rust-version = "1.79.0"

[package.metadata.docs.rs]
features = ["stable"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ KAS GUI
[![Crates.io](https://img.shields.io/crates/v/kas.svg)](https://crates.io/crates/kas)
[![kas-text](https://img.shields.io/badge/GitHub-kas--text-blueviolet)](https://github.com/kas-gui/kas-text/)
[![Docs](https://docs.rs/kas/badge.svg)](https://docs.rs/kas)
![Minimum rustc version](https://img.shields.io/badge/rustc-1.75+-lightgray.svg)
![Minimum rustc version](https://img.shields.io/badge/rustc-1.79+-lightgray.svg)

KAS is a stateful, pure-Rust GUI toolkit supporting:

Expand Down
2 changes: 1 addition & 1 deletion crates/kas-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ version = "0.5.0" # used in doc links

[dependencies.winit]
# Provides translations for several winit types
version = "0.30.0"
version = "0.30.1"
optional = true
default-features = false
features = ["rwh_06"]
4 changes: 2 additions & 2 deletions crates/kas-core/src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ impl<'a> PlatformWrapper<'a> {
{
cfg_if::cfg_if! {
if #[cfg(all(feature = "wayland", feature = "x11"))] {
use winit::platform::wayland::ActiveEventLoopExtWayland;
return if true /*FIXME: self.0.is_wayland()*/ {
use winit::platform::wayland::EventLoopExtWayland;
return if self.0.is_wayland() {
Platform::Wayland
} else {
Platform::X11
Expand Down
22 changes: 12 additions & 10 deletions crates/kas-core/src/draw/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ impl Rgba8Srgb {
}

/// Compile-time parser for sRGB and sRGBA colours
pub const fn try_parse_srgb(s: &[u8]) -> Result<Rgba8Srgb, ParseError> {
pub const fn try_parse(s: &str) -> Result<Rgba8Srgb, ParseError> {
let s = s.as_bytes();
if s.len() != 6 && s.len() != 8 {
return Err(ParseError::Length);
}
Expand Down Expand Up @@ -303,11 +304,11 @@ impl Rgba8Srgb {

/// Compile-time parser for sRGB and sRGBA colours
///
/// This method has worse diagnostics on error due to limited const-
pub const fn parse_srgb(s: &[u8]) -> Rgba8Srgb {
match Self::try_parse_srgb(s) {
/// This method has worse diagnostics on error due to limited error handling in `const fn`.
pub const fn parse(s: &str) -> Rgba8Srgb {
match Self::try_parse(s) {
Ok(result) => result,
Err(ParseError::Length) => panic!("invalid length (expected 6 or 8 bytes"),
Err(ParseError::Length) => panic!("invalid length (expected 6 or 8 bytes)"),
Err(ParseError::InvalidHex) => panic!("invalid hex byte (expected 0-9, a-f or A-F)"),
}
}
Expand Down Expand Up @@ -345,12 +346,13 @@ pub enum ParseError {
impl std::str::FromStr for Rgba8Srgb {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut s = s.as_bytes();
if s[0] == b'#' {
s = &s[1..];
fn from_str(mut s: &str) -> Result<Self, Self::Err> {
if s.starts_with("#") {
let a;
(a, s) = s.split_at(1);
debug_assert_eq!(a, "#");
}
Rgba8Srgb::try_parse_srgb(&s)
Rgba8Srgb::try_parse(s)
}
}

Expand Down
72 changes: 36 additions & 36 deletions crates/kas-core/src/theme/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,52 +226,52 @@ impl ColorsSrgb {
/// Default "light" scheme
pub const LIGHT: ColorsSrgb = Colors {
is_dark: false,
background: Rgba8Srgb::parse_srgb(b"FAFAFA"),
frame: Rgba8Srgb::parse_srgb(b"BCBCBC"),
accent: Rgba8Srgb::parse_srgb(b"8347f2"),
accent_soft: Rgba8Srgb::parse_srgb(b"B38DF9"),
nav_focus: Rgba8Srgb::parse_srgb(b"7E3FF2"),
edit_bg: Rgba8Srgb::parse_srgb(b"FAFAFA"),
edit_bg_disabled: Rgba8Srgb::parse_srgb(b"DCDCDC"),
edit_bg_error: Rgba8Srgb::parse_srgb(b"FFBCBC"),
text: Rgba8Srgb::parse_srgb(b"000000"),
text_invert: Rgba8Srgb::parse_srgb(b"FFFFFF"),
text_disabled: Rgba8Srgb::parse_srgb(b"AAAAAA"),
text_sel_bg: Rgba8Srgb::parse_srgb(b"A172FA"),
background: Rgba8Srgb::parse("FAFAFA"),
frame: Rgba8Srgb::parse("BCBCBC"),
accent: Rgba8Srgb::parse("8347f2"),
accent_soft: Rgba8Srgb::parse("B38DF9"),
nav_focus: Rgba8Srgb::parse("7E3FF2"),
edit_bg: Rgba8Srgb::parse("FAFAFA"),
edit_bg_disabled: Rgba8Srgb::parse("DCDCDC"),
edit_bg_error: Rgba8Srgb::parse("FFBCBC"),
text: Rgba8Srgb::parse("000000"),
text_invert: Rgba8Srgb::parse("FFFFFF"),
text_disabled: Rgba8Srgb::parse("AAAAAA"),
text_sel_bg: Rgba8Srgb::parse("A172FA"),
};

/// Dark scheme
pub const DARK: ColorsSrgb = Colors {
is_dark: true,
background: Rgba8Srgb::parse_srgb(b"404040"),
frame: Rgba8Srgb::parse_srgb(b"AAAAAA"),
accent: Rgba8Srgb::parse_srgb(b"F74C00"),
accent_soft: Rgba8Srgb::parse_srgb(b"E77346"),
nav_focus: Rgba8Srgb::parse_srgb(b"D03E00"),
edit_bg: Rgba8Srgb::parse_srgb(b"303030"),
edit_bg_disabled: Rgba8Srgb::parse_srgb(b"606060"),
edit_bg_error: Rgba8Srgb::parse_srgb(b"a06868"),
text: Rgba8Srgb::parse_srgb(b"FFFFFF"),
text_invert: Rgba8Srgb::parse_srgb(b"000000"),
text_disabled: Rgba8Srgb::parse_srgb(b"CBCBCB"),
text_sel_bg: Rgba8Srgb::parse_srgb(b"E77346"),
background: Rgba8Srgb::parse("404040"),
frame: Rgba8Srgb::parse("AAAAAA"),
accent: Rgba8Srgb::parse("F74C00"),
accent_soft: Rgba8Srgb::parse("E77346"),
nav_focus: Rgba8Srgb::parse("D03E00"),
edit_bg: Rgba8Srgb::parse("303030"),
edit_bg_disabled: Rgba8Srgb::parse("606060"),
edit_bg_error: Rgba8Srgb::parse("a06868"),
text: Rgba8Srgb::parse("FFFFFF"),
text_invert: Rgba8Srgb::parse("000000"),
text_disabled: Rgba8Srgb::parse("CBCBCB"),
text_sel_bg: Rgba8Srgb::parse("E77346"),
};

/// Blue scheme
pub const BLUE: ColorsSrgb = Colors {
is_dark: false,
background: Rgba8Srgb::parse_srgb(b"FFFFFF"),
frame: Rgba8Srgb::parse_srgb(b"DADADA"),
accent: Rgba8Srgb::parse_srgb(b"3fafd7"),
accent_soft: Rgba8Srgb::parse_srgb(b"7CDAFF"),
nav_focus: Rgba8Srgb::parse_srgb(b"3B697A"),
edit_bg: Rgba8Srgb::parse_srgb(b"FFFFFF"),
edit_bg_disabled: Rgba8Srgb::parse_srgb(b"DCDCDC"),
edit_bg_error: Rgba8Srgb::parse_srgb(b"FFBCBC"),
text: Rgba8Srgb::parse_srgb(b"000000"),
text_invert: Rgba8Srgb::parse_srgb(b"FFFFFF"),
text_disabled: Rgba8Srgb::parse_srgb(b"AAAAAA"),
text_sel_bg: Rgba8Srgb::parse_srgb(b"6CC0E1"),
background: Rgba8Srgb::parse("FFFFFF"),
frame: Rgba8Srgb::parse("DADADA"),
accent: Rgba8Srgb::parse("3fafd7"),
accent_soft: Rgba8Srgb::parse("7CDAFF"),
nav_focus: Rgba8Srgb::parse("3B697A"),
edit_bg: Rgba8Srgb::parse("FFFFFF"),
edit_bg_disabled: Rgba8Srgb::parse("DCDCDC"),
edit_bg_error: Rgba8Srgb::parse("FFBCBC"),
text: Rgba8Srgb::parse("000000"),
text_invert: Rgba8Srgb::parse("FFFFFF"),
text_disabled: Rgba8Srgb::parse("AAAAAA"),
text_sel_bg: Rgba8Srgb::parse("6CC0E1"),
};
}

Expand Down
2 changes: 1 addition & 1 deletion crates/kas-core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn load_icon_from_path<P: AsRef<std::path::Path>>(
) -> Result<Icon, Box<dyn std::error::Error>> {
// TODO(opt): image loading could be de-duplicated with
// DrawShared::image_from_path, but this may not be worthwhile.
let im = image::io::Reader::open(path)?
let im = image::ImageReader::open(path)?
.with_guessed_format()?
.decode()?
.into_rgba8();
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-resvg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ svg = ["dep:resvg", "dep:usvg"]

[dependencies]
tiny-skia = { version = "0.11.0" }
resvg = { version = "0.41.0", optional = true }
usvg = { version = "0.41.0", optional = true }
resvg = { version = "0.43.0", optional = true }
usvg = { version = "0.43.0", optional = true }
once_cell = "1.17.0"
thiserror = "1.0.23"

Expand Down
6 changes: 4 additions & 2 deletions crates/kas-resvg/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn load(data: &[u8], resources_dir: Option<&Path>) -> Result<Tree, usvg::Error>
// - default_size: affected by screen scale factor later
// - dpi: according to css-values-3, 1in = 96px
// - font_size: units are (logical) px per em; 16px = 12pt
// - TODO: add option to clone fontdb from kas::text?
let opts = usvg::Options {
resources_dir: resources_dir.map(|path| path.to_owned()),
dpi: 96.0,
Expand All @@ -47,10 +48,11 @@ fn load(data: &[u8], resources_dir: Option<&Path>) -> Result<Tree, usvg::Error>
image_rendering: usvg::ImageRendering::default(),
default_size: usvg::Size::from_wh(100.0, 100.0).unwrap(),
image_href_resolver: Default::default(),
font_resolver: Default::default(),
fontdb: Default::default(),
};

let fonts_db = kas::text::fonts::library().read_db();
let tree = Tree::from_data(data, &opts, fonts_db.db())?;
let tree = Tree::from_data(data, &opts)?;

Ok(tree)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ futures-lite = "2.0"
log = "0.4"
thiserror = "1.0.23"
guillotiere = "0.6.0"
rustc-hash = "1.0"
rustc-hash = "2.0"

[dependencies.kas]
# Rename package purely for convenience:
Expand All @@ -47,7 +47,7 @@ path = "../kas-core"
version = "0.6.0"

[dependencies.wgpu]
version = "0.20.0"
version = "22.1.0"
default-features = false
features = ["spirv"]

Expand Down
1 change: 1 addition & 0 deletions crates/kas-wgpu/src/draw/atlases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl<I: bytemuck::Pod> Pipeline<I> {
multisample: Default::default(),
fragment: Some(fragment),
multiview: None,
cache: None,
});

let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
Expand Down
1 change: 1 addition & 0 deletions crates/kas-wgpu/src/draw/flat_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Pipeline {
})],
}),
multiview: None,
cache: None,
});

Pipeline { render_pipeline }
Expand Down
1 change: 1 addition & 0 deletions crates/kas-wgpu/src/draw/round_2col.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl Pipeline {
})],
}),
multiview: None,
cache: None,
});

Pipeline { render_pipeline }
Expand Down
1 change: 1 addition & 0 deletions crates/kas-wgpu/src/draw/shaded_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl Pipeline {
})],
}),
multiview: None,
cache: None,
});

Pipeline { render_pipeline }
Expand Down
1 change: 1 addition & 0 deletions crates/kas-wgpu/src/draw/shaded_square.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl Pipeline {
})],
}),
multiview: None,
cache: None,
});

Pipeline { render_pipeline }
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-widgets/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl_scope! {
path: P,
draw: &mut dyn DrawShared,
) -> Result<Action> {
let image = image::io::Reader::open(path)?
let image = image::ImageReader::open(path)?
.with_guessed_format()?
.decode()?;

Expand Down
2 changes: 1 addition & 1 deletion examples/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl_scope! {
}

fn draw(&mut self, mut draw: DrawCx) {
let accent: Rgba = Rgba8Srgb::parse_srgb(b"d7916f").into();
let accent: Rgba = Rgba8Srgb::parse("d7916f").into();
let col_back = Rgba::ga(0.0, 0.5);
let col_face = accent.multiply(0.4);
let col_time = Rgba::grey(1.0);
Expand Down
3 changes: 1 addition & 2 deletions examples/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ fn widgets() -> Box<dyn Widget<Data = AppData>> {
row!["ScrollLabel", ScrollLabel::new(text).map_any()],
row![
"EditBox",
EditBox::string(|data: &Data| data.text.clone())
.with_msg(|s| Item::Text(s.to_string())),
EditBox::new(Guard).with_text("length must not be a multiple of 8!"),
],
row![
"Button (text)",
Expand Down
2 changes: 2 additions & 0 deletions examples/mandlebrot/mandlebrot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl CustomPipeBuilder for PipeBuilder {
max_push_constant_size: size_of::<PushConstants>().cast(),
..Default::default()
},
..Default::default()
}
}

Expand Down Expand Up @@ -162,6 +163,7 @@ impl CustomPipeBuilder for PipeBuilder {
})],
}),
multiview: None,
cache: None,
});

Pipe { render_pipeline }
Expand Down

0 comments on commit 45424b2

Please sign in to comment.