mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-25 08:28:42 -06:00
remove deprecated BackgroundColor
struct
This commit is contained in:
parent
4574cb8862
commit
b5f3fc192e
|
@ -1,115 +0,0 @@
|
|||
//! (deprecated) background color, gradient and texturing
|
||||
#![allow(deprecated)]
|
||||
|
||||
use glam::{vec4, Vec3, Vec4};
|
||||
use crate::rect::Corners;
|
||||
|
||||
//TODO: use this
|
||||
// pub struct Background {
|
||||
// pub color: BackgroundColor,
|
||||
// pub texture: Option<TextureH>
|
||||
// }
|
||||
|
||||
//TODO: move this into the color module?
|
||||
/// Represents the background color of an element
|
||||
///
|
||||
/// Can be either a solid color, a gradient or transparent
|
||||
#[deprecated(note = "Use `CornersColors` instead")]
|
||||
#[derive(Clone, Copy, Default, Debug, PartialEq)]
|
||||
pub enum BackgroundColor {
|
||||
/// Transparent background (alpha = 0)
|
||||
#[default]
|
||||
Transparent,
|
||||
|
||||
/// Solid, RGBA color
|
||||
Solid(Vec4),
|
||||
|
||||
/// Simple gradient color, with different colors for each corner
|
||||
Gradient(Corners<Vec4>),
|
||||
}
|
||||
|
||||
impl From<(f32, f32, f32, f32)> for BackgroundColor {
|
||||
fn from(color: (f32, f32, f32, f32)) -> Self {
|
||||
Self::Solid(vec4(color.0, color.1, color.2, color.3))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Corners<Vec4>> for BackgroundColor {
|
||||
fn from(corners: Corners<Vec4>) -> Self {
|
||||
Self::Gradient(corners)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Option<Vec4>> for BackgroundColor {
|
||||
fn from(color: Option<Vec4>) -> Self {
|
||||
match color {
|
||||
Some(color) => Self::Solid(color),
|
||||
None => Self::Transparent,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec4> for BackgroundColor {
|
||||
fn from(color: Vec4) -> Self {
|
||||
Self::Solid(color)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(f32, f32, f32)> for BackgroundColor {
|
||||
fn from(color: (f32, f32, f32)) -> Self {
|
||||
Self::Solid(vec4(color.0, color.1, color.2, 1.))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Corners<Vec3>> for BackgroundColor {
|
||||
fn from(corners: Corners<Vec3>) -> Self {
|
||||
Self::Gradient(Corners {
|
||||
top_left: corners.top_left.extend(1.),
|
||||
top_right: corners.top_right.extend(1.),
|
||||
bottom_left: corners.bottom_left.extend(1.),
|
||||
bottom_right: corners.bottom_right.extend(1.),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Option<Vec3>> for BackgroundColor {
|
||||
fn from(color: Option<Vec3>) -> Self {
|
||||
match color {
|
||||
Some(color) => Self::Solid(color.extend(1.)),
|
||||
None => Self::Transparent,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec3> for BackgroundColor {
|
||||
fn from(color: Vec3) -> Self {
|
||||
Self::Solid(color.extend(1.))
|
||||
}
|
||||
}
|
||||
|
||||
impl BackgroundColor {
|
||||
/// Returns the colors of individual corners
|
||||
pub fn corners(&self) -> Corners<Vec4> {
|
||||
match *self {
|
||||
Self::Transparent => Corners::all(Vec4::ZERO),
|
||||
Self::Solid(color) => Corners::all(color),
|
||||
Self::Gradient(corners) => corners,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the background is `Transparent` or all corners have an alpha value of `0`.
|
||||
pub fn is_transparent(&self) -> bool {
|
||||
match *self {
|
||||
Self::Transparent => true,
|
||||
Self::Solid(color) => color.w == 0.,
|
||||
Self::Gradient(corners) => {
|
||||
let max_alpha =
|
||||
corners.top_left.w
|
||||
.max(corners.top_right.w)
|
||||
.max(corners.bottom_left.w)
|
||||
.max(corners.bottom_right.w);
|
||||
max_alpha == 0.
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,12 +3,11 @@
|
|||
use derive_setters::Setters;
|
||||
use glam::{Vec2, vec2};
|
||||
use crate::{
|
||||
background::BackgroundColor,
|
||||
draw::{ImageHandle, RoundedCorners, UiDrawCommand},
|
||||
element::{ElementList, MeasureContext, ProcessContext, UiElement},
|
||||
layout::{Alignment, Alignment2d, Direction, LayoutInfo, Size, Size2d},
|
||||
measure::{Hints, Response},
|
||||
rect::{Corners, Sides},
|
||||
rect::{Corners, FillColor, Sides},
|
||||
};
|
||||
|
||||
// pub struct Border {
|
||||
|
@ -59,7 +58,7 @@ pub struct Container {
|
|||
///
|
||||
/// If the container has a background texture, it will be multiplied by this color
|
||||
#[setters(into)]
|
||||
pub background: BackgroundColor,
|
||||
pub background: FillColor,
|
||||
|
||||
/// Background texture of the container
|
||||
///
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
use derive_setters::Setters;
|
||||
use glam::{vec2, Vec4};
|
||||
use crate::{
|
||||
background::BackgroundColor,
|
||||
draw::{UiDrawCommand, RoundedCorners},
|
||||
element::{UiElement, MeasureContext, ProcessContext},
|
||||
draw::{RoundedCorners, UiDrawCommand},
|
||||
element::{MeasureContext, ProcessContext, UiElement},
|
||||
layout::{Size, Size2d},
|
||||
measure::Response,
|
||||
rect::Corners,
|
||||
rect::{Corners, FillColor},
|
||||
size,
|
||||
};
|
||||
|
||||
|
@ -22,7 +21,7 @@ pub struct FillRect {
|
|||
|
||||
/// Background color of the rectangle
|
||||
#[setters(into)]
|
||||
pub background: BackgroundColor,
|
||||
pub background: FillColor,
|
||||
|
||||
/// Corner radius of the rectangle
|
||||
#[setters(into)]
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
use derive_setters::Setters;
|
||||
use glam::vec2;
|
||||
use crate::{
|
||||
background::BackgroundColor,
|
||||
draw::{ImageHandle, RoundedCorners, UiDrawCommand},
|
||||
element::{MeasureContext, ProcessContext, UiElement},
|
||||
layout::{compute_size, Size, Size2d},
|
||||
measure::Response,
|
||||
rect::Corners,
|
||||
rect::{Corners, FillColor},
|
||||
};
|
||||
|
||||
#[derive(Setters)]
|
||||
|
@ -29,7 +28,7 @@ pub struct Image {
|
|||
///
|
||||
/// Image will get multiplied/tinted by this color or gradient
|
||||
#[setters(into)]
|
||||
pub color: BackgroundColor,
|
||||
pub color: FillColor,
|
||||
|
||||
/// Corner radius of the image
|
||||
#[setters(into)]
|
||||
|
@ -44,7 +43,7 @@ impl Image {
|
|||
width: Size::Auto,
|
||||
height: Size::Auto,
|
||||
},
|
||||
color: BackgroundColor::from((1., 1., 1., 1.)),
|
||||
color: (1., 1., 1.).into(),
|
||||
corner_radius: Corners::all(0.),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
use derive_setters::Setters;
|
||||
use glam::{vec2, vec4};
|
||||
use crate::{
|
||||
background::BackgroundColor,
|
||||
draw::{RoundedCorners, UiDrawCommand},
|
||||
element::{MeasureContext, ProcessContext, UiElement},
|
||||
layout::{compute_size, Size, Size2d},
|
||||
measure::Response,
|
||||
rect::Corners
|
||||
rect::{Corners, FillColor}
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Setters)]
|
||||
|
@ -21,11 +20,11 @@ pub struct ProgressBar {
|
|||
|
||||
/// Foreground (bar) color
|
||||
#[setters(into)]
|
||||
pub foreground: BackgroundColor,
|
||||
pub foreground: FillColor,
|
||||
|
||||
/// Background color
|
||||
#[setters(into)]
|
||||
pub background: BackgroundColor,
|
||||
pub background: FillColor,
|
||||
|
||||
/// Corner radius of the progress bar
|
||||
#[setters(into)]
|
||||
|
|
|
@ -13,7 +13,6 @@ mod instance;
|
|||
mod macros;
|
||||
pub mod layout;
|
||||
pub mod rect;
|
||||
pub mod background;
|
||||
pub mod element;
|
||||
pub mod event;
|
||||
pub mod input;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! contains types which represent the sides and corners of a rectangular shape.
|
||||
|
||||
//XXX: this is kinda a mess, either move the rect struct here or come up with a better name for this module
|
||||
#[allow(clippy::module_inception)]
|
||||
mod rect;
|
||||
pub use rect::Rect;
|
||||
|
||||
|
|
|
@ -50,9 +50,14 @@ impl FillColor {
|
|||
})
|
||||
}
|
||||
|
||||
/// Construct a simple gradient fill from four colors representing the corners of the rectangle
|
||||
pub const fn corners(top_left: Vec4, top_right: Vec4, bottom_left: Vec4, bottom_right: Vec4) -> Self {
|
||||
Self(Corners { top_left, top_right, bottom_left, bottom_right })
|
||||
/// Construct a solid color fill from colors for each corner
|
||||
pub const fn from_corners(corners: Corners<Vec4>) -> Self {
|
||||
Self(corners)
|
||||
}
|
||||
|
||||
/// Get a list of the colors for each corner
|
||||
pub const fn corners(&self) -> Corners<Vec4> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue