Skip to content

Commit

Permalink
Merge pull request #237 from kas-gui/work
Browse files Browse the repository at this point in the history
Improve flat theme, colours
  • Loading branch information
dhardy authored Aug 12, 2021
2 parents 76b1815 + 778acb5 commit 7180d87
Show file tree
Hide file tree
Showing 33 changed files with 419 additions and 276 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ Installation and dependencies

#### Rust

KAS requires [Rust] version 1.52 or greater (currently in **beta**: *usually*
we maintain compatibility with the latest stable release).
Using the **nightly** channel does have a couple of advantages:
KAS requires a recent [Rust] compiler. Currently, version 1.52 or greater is
required. Using the **nightly** channel does have a few advantages:

- Proceedural macros emit better diagnostics. In some cases, diagnostics are
missed without nightly rustc, hence **nightly is recommended for development**.
- Documentation generated via `cargo doc` requires nightly for links
- A few minor option things: see [Feature flags](#feature-flags) below.
- The `nightly` (`min_spec`) feature allows some visual improvements (see below).
- The `doc_cfg` feature may be used for API docs.

### Quick-start

Expand Down Expand Up @@ -137,8 +136,9 @@ The `kas` crate has the following feature flags:
Additionally, the following flags require a nightly compiler:

- `nightly`: enables "more stable" unstable features
- `min_spec` (enabled by `nightly`): use `min_specialization` to draw
underlines in `AccelLabel`
- `min_spec` (enabled by `nightly`): use `min_specialization` for some visual
improvements: scrolled regions are drawn under scrollbars,
underlines on checkbox accelerator keys show with the <kbd>Alt</kbd> key.
- `spec`: use `specialization` to enable `TryFormat`
- `gat`: compatibility with `kas-text/gat`

Expand Down
14 changes: 12 additions & 2 deletions crates/kas-core/src/draw/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ impl Rgba {
Self::rgba(s, s, s, a)
}

/// Get the sum of the three colour components
pub fn sum(self) -> f32 {
self.r + self.g + self.b
}

/// Average three colour components (desaturate)
pub fn average(self) -> Self {
Self::ga((self.r + self.g + self.b) * (1.0 / 3.0), self.a)
Self::ga(self.sum() * (1.0 / 3.0), self.a)
}

/// Multiply and clamp three colour components
Expand Down Expand Up @@ -131,9 +136,14 @@ impl Rgb {
Self::rgb(s, s, s)
}

/// Get the sum of the three colour components
pub fn sum(self) -> f32 {
self.r + self.g + self.b
}

/// Average three colour components (desaturate)
pub fn average(self) -> Self {
Self::grey((self.r + self.g + self.b) * (1.0 / 3.0))
Self::grey(self.sum() * (1.0 / 3.0))
}

/// Multiply and clamp three colour components
Expand Down
8 changes: 8 additions & 0 deletions crates/kas-core/src/draw/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ pub trait SizeHandle {
fn pixels_from_em(&self, em: f32) -> f32;

/// Size of a frame around child widget(s)
///
/// This already includes the margins specified by [`Self::frame_margins`].
fn frame(&self, vert: bool) -> FrameRules;

/// Frame/margin around a menu entry
Expand All @@ -160,6 +162,9 @@ pub trait SizeHandle {
/// Widgets must not draw in outer margins.
fn outer_margins(&self) -> Margins;

/// The margin around frames and separators
fn frame_margins(&self) -> Margins;

/// The margin around text elements
///
/// Similar to [`Self::outer_margins`], but intended for things like text
Expand Down Expand Up @@ -467,6 +472,9 @@ impl<S: SizeHandle + ?Sized, R: Deref<Target = S>> SizeHandle for R {
fn outer_margins(&self) -> Margins {
self.deref().outer_margins()
}
fn frame_margins(&self) -> Margins {
self.deref().frame_margins()
}
fn text_margins(&self) -> Margins {
self.deref().text_margins()
}
Expand Down
11 changes: 11 additions & 0 deletions crates/kas-core/src/geom/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ macro_rules! impl_vec2 {
/// Zero
pub const ZERO: $T = $T::splat(0.0);

/// One
pub const ONE: $T = $T::splat(1.0);

/// Positive infinity
pub const INFINITY: $T = $T::splat(<$f>::INFINITY);

Expand Down Expand Up @@ -335,6 +338,14 @@ macro_rules! impl_vec2 {
}
}

impl Div<$T> for $f {
type Output = $T;
#[inline]
fn div(self, rhs: $T) -> Self::Output {
$T(self / rhs.0, self / rhs.1)
}
}

impl From<($f, $f)> for $T {
#[inline]
fn from(arg: ($f, $f)) -> Self {
Expand Down
Loading

0 comments on commit 7180d87

Please sign in to comment.