mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 21:04:47 +00:00
Move datastructures::Color into graphics
This commit is contained in:
parent
fa87363dc5
commit
1b270f42d0
7 changed files with 94 additions and 94 deletions
|
@ -1,7 +1,7 @@
|
|||
use cgmath::{Matrix4, SquareMatrix, Vector3};
|
||||
use sixtyfps_corelib::abi::datastructures::{Color, PathData, PathElement, PathLineTo};
|
||||
use sixtyfps_corelib::abi::datastructures::{PathData, PathElement, PathLineTo};
|
||||
use sixtyfps_corelib::graphics::{
|
||||
Frame, GraphicsBackend, HighLevelRenderingPrimitive, RenderingCache,
|
||||
Color, Frame, GraphicsBackend, HighLevelRenderingPrimitive, RenderingCache,
|
||||
RenderingPrimitivesBuilder, Resource,
|
||||
};
|
||||
use sixtyfps_corelib::SharedArray;
|
||||
|
|
|
@ -132,90 +132,6 @@ impl Default for LayoutInfo {
|
|||
}
|
||||
}
|
||||
|
||||
/// RGBA color
|
||||
#[derive(Copy, Clone, PartialEq, Debug, Default)]
|
||||
#[repr(C)]
|
||||
pub struct Color {
|
||||
red: u8,
|
||||
green: u8,
|
||||
blue: u8,
|
||||
alpha: u8,
|
||||
}
|
||||
|
||||
impl Color {
|
||||
/// Construct a color from an integer encoded as `0xAARRGGBB`
|
||||
pub const fn from_argb_encoded(encoded: u32) -> Color {
|
||||
Color {
|
||||
red: (encoded >> 16) as u8,
|
||||
green: (encoded >> 8) as u8,
|
||||
blue: encoded as u8,
|
||||
alpha: (encoded >> 24) as u8,
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a color from its RGBA components as u8
|
||||
pub const fn from_rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Color {
|
||||
Color { red, green, blue, alpha }
|
||||
}
|
||||
/// Construct a color from its RGB components as u8
|
||||
pub const fn from_rgb(red: u8, green: u8, blue: u8) -> Color {
|
||||
Color::from_rgba(red, green, blue, 0xff)
|
||||
}
|
||||
|
||||
/// Returns `(red, green, blue, alpha)` encoded as f32
|
||||
pub fn as_rgba_f32(&self) -> (f32, f32, f32, f32) {
|
||||
(
|
||||
(self.red as f32) / 255.0,
|
||||
(self.green as f32) / 255.0,
|
||||
(self.blue as f32) / 255.0,
|
||||
(self.alpha as f32) / 255.0,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns `(red, green, blue, alpha)` encoded as u8
|
||||
pub fn as_rgba_u8(&self) -> (u8, u8, u8, u8) {
|
||||
(self.red, self.green, self.blue, self.alpha)
|
||||
}
|
||||
|
||||
/// Returns `(alpha, red, green, blue)` encoded as u32
|
||||
pub fn as_argb_encoded(&self) -> u32 {
|
||||
((self.red as u32) << 16)
|
||||
| ((self.green as u32) << 8)
|
||||
| (self.blue as u32)
|
||||
| ((self.alpha as u32) << 24)
|
||||
}
|
||||
|
||||
/// A constant for the black color
|
||||
pub const BLACK: Color = Color::from_rgb(0, 0, 0);
|
||||
/// A constant for the white color
|
||||
pub const WHITE: Color = Color::from_rgb(255, 255, 255);
|
||||
/// A constant for the transparent color
|
||||
pub const TRANSPARENT: Color = Color::from_rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
impl From<u32> for Color {
|
||||
fn from(encoded: u32) -> Self {
|
||||
Color::from_argb_encoded(encoded)
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::abi::properties::InterpolatedPropertyValue for Color {
|
||||
fn interpolate(self, target_value: Self, t: f32) -> Self {
|
||||
Self {
|
||||
red: self.red.interpolate(target_value.red, t),
|
||||
green: self.green.interpolate(target_value.green, t),
|
||||
blue: self.blue.interpolate(target_value.blue, t),
|
||||
alpha: self.alpha.interpolate(target_value.alpha, t),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Color {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "argb({}, {}, {}, {})", self.alpha, self.red, self.green, self.blue)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(FieldOffsets, Default, BuiltinItem, Clone, Debug, PartialEq)]
|
||||
#[pin]
|
||||
|
|
|
@ -64,7 +64,7 @@ mod single_linked_list_pin {
|
|||
use core::cell::{Cell, RefCell, UnsafeCell};
|
||||
use core::{marker::PhantomPinned, pin::Pin};
|
||||
|
||||
use crate::abi::datastructures::Color;
|
||||
use crate::graphics::Color;
|
||||
use crate::items::PropertyAnimation;
|
||||
|
||||
/// The return value of a binding
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
extern crate alloc;
|
||||
use crate::abi::datastructures::Color;
|
||||
use cgmath::Matrix4;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
@ -31,6 +30,90 @@ mod ffi {
|
|||
}
|
||||
}
|
||||
|
||||
/// RGBA color
|
||||
#[derive(Copy, Clone, PartialEq, Debug, Default)]
|
||||
#[repr(C)]
|
||||
pub struct Color {
|
||||
red: u8,
|
||||
green: u8,
|
||||
blue: u8,
|
||||
alpha: u8,
|
||||
}
|
||||
|
||||
impl Color {
|
||||
/// Construct a color from an integer encoded as `0xAARRGGBB`
|
||||
pub const fn from_argb_encoded(encoded: u32) -> Color {
|
||||
Color {
|
||||
red: (encoded >> 16) as u8,
|
||||
green: (encoded >> 8) as u8,
|
||||
blue: encoded as u8,
|
||||
alpha: (encoded >> 24) as u8,
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a color from its RGBA components as u8
|
||||
pub const fn from_rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Color {
|
||||
Color { red, green, blue, alpha }
|
||||
}
|
||||
/// Construct a color from its RGB components as u8
|
||||
pub const fn from_rgb(red: u8, green: u8, blue: u8) -> Color {
|
||||
Color::from_rgba(red, green, blue, 0xff)
|
||||
}
|
||||
|
||||
/// Returns `(red, green, blue, alpha)` encoded as f32
|
||||
pub fn as_rgba_f32(&self) -> (f32, f32, f32, f32) {
|
||||
(
|
||||
(self.red as f32) / 255.0,
|
||||
(self.green as f32) / 255.0,
|
||||
(self.blue as f32) / 255.0,
|
||||
(self.alpha as f32) / 255.0,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns `(red, green, blue, alpha)` encoded as u8
|
||||
pub fn as_rgba_u8(&self) -> (u8, u8, u8, u8) {
|
||||
(self.red, self.green, self.blue, self.alpha)
|
||||
}
|
||||
|
||||
/// Returns `(alpha, red, green, blue)` encoded as u32
|
||||
pub fn as_argb_encoded(&self) -> u32 {
|
||||
((self.red as u32) << 16)
|
||||
| ((self.green as u32) << 8)
|
||||
| (self.blue as u32)
|
||||
| ((self.alpha as u32) << 24)
|
||||
}
|
||||
|
||||
/// A constant for the black color
|
||||
pub const BLACK: Color = Color::from_rgb(0, 0, 0);
|
||||
/// A constant for the white color
|
||||
pub const WHITE: Color = Color::from_rgb(255, 255, 255);
|
||||
/// A constant for the transparent color
|
||||
pub const TRANSPARENT: Color = Color::from_rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
impl From<u32> for Color {
|
||||
fn from(encoded: u32) -> Self {
|
||||
Color::from_argb_encoded(encoded)
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::abi::properties::InterpolatedPropertyValue for Color {
|
||||
fn interpolate(self, target_value: Self, t: f32) -> Self {
|
||||
Self {
|
||||
red: self.red.interpolate(target_value.red, t),
|
||||
green: self.green.interpolate(target_value.green, t),
|
||||
blue: self.blue.interpolate(target_value.blue, t),
|
||||
alpha: self.alpha.interpolate(target_value.alpha, t),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Color {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "argb({}, {}, {}, {})", self.alpha, self.red, self.green, self.blue)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum FillStyle {
|
||||
SolidColor(Color),
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ When adding an item or a property, it needs to be kept in sync with different pl
|
|||
#![allow(missing_docs)] // because documenting each property of items is redundent
|
||||
|
||||
use super::abi::datastructures::{
|
||||
CachedRenderingData, Color, Item, ItemConsts, LayoutInfo, MouseEvent, PathData,
|
||||
CachedRenderingData, Item, ItemConsts, LayoutInfo, MouseEvent, PathData,
|
||||
};
|
||||
use super::graphics::{HighLevelRenderingPrimitive, Rect, Resource};
|
||||
use super::graphics::{Color, HighLevelRenderingPrimitive, Rect, Resource};
|
||||
#[cfg(feature = "rtti")]
|
||||
use crate::rtti::*;
|
||||
use crate::{Property, SharedString, Signal};
|
||||
|
|
|
@ -54,7 +54,7 @@ pub use abi::properties::Property;
|
|||
pub use abi::signals::Signal;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use abi::datastructures::Color;
|
||||
pub use graphics::Color;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use abi::datastructures::PathData;
|
||||
|
|
|
@ -7,10 +7,11 @@ use lyon::tessellation::{
|
|||
FillAttributes, FillOptions, FillTessellator, StrokeAttributes, StrokeOptions,
|
||||
StrokeTessellator,
|
||||
};
|
||||
use sixtyfps_corelib::abi::datastructures::{Color, ComponentWindow, ComponentWindowOpaque};
|
||||
use sixtyfps_corelib::abi::datastructures::{ComponentWindow, ComponentWindowOpaque};
|
||||
use sixtyfps_corelib::graphics::{
|
||||
FillStyle, Frame as GraphicsFrame, GraphicsBackend, GraphicsWindow, HasRenderingPrimitive,
|
||||
HighLevelRenderingPrimitive, Point, Rect, RenderingPrimitivesBuilder, Resource, Size,
|
||||
Color, FillStyle, Frame as GraphicsFrame, GraphicsBackend, GraphicsWindow,
|
||||
HasRenderingPrimitive, HighLevelRenderingPrimitive, Point, Rect, RenderingPrimitivesBuilder,
|
||||
Resource, Size,
|
||||
};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::cell::RefCell;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue