Allow color to be squared
This commit is contained in:
parent
ed3c470716
commit
be011c467e
8 changed files with 72 additions and 52 deletions
|
@ -179,10 +179,10 @@ impl ButtonInfo {
|
|||
|
||||
if let Some(background_type) = &mut button_info.normal {
|
||||
match background_type {
|
||||
FillTypeInfo::Image(_, fill_type) => {
|
||||
FillTypeInfo::Image(_) => {}
|
||||
FillTypeInfo::Color(_, fill_type) => {
|
||||
*fill_type = button_info.background_fill_type;
|
||||
}
|
||||
FillTypeInfo::Color(_) => (),
|
||||
FillTypeInfo::Element(_, fill_type) => {
|
||||
*fill_type = button_info.background_fill_type;
|
||||
}
|
||||
|
@ -191,10 +191,10 @@ impl ButtonInfo {
|
|||
|
||||
if let Some(background_type) = &mut button_info.selected {
|
||||
match background_type {
|
||||
FillTypeInfo::Image(_, fill_type) => {
|
||||
FillTypeInfo::Image(_) => {}
|
||||
FillTypeInfo::Color(_, fill_type) => {
|
||||
*fill_type = button_info.background_fill_type;
|
||||
}
|
||||
FillTypeInfo::Color(_) => (),
|
||||
FillTypeInfo::Element(_, fill_type) => {
|
||||
*fill_type = button_info.background_fill_type;
|
||||
}
|
||||
|
|
|
@ -99,10 +99,10 @@ impl IconInfo {
|
|||
|
||||
if let Some(background_type) = &mut icon_info.background_type {
|
||||
match background_type {
|
||||
FillTypeInfo::Image(_, fill_type) => {
|
||||
FillTypeInfo::Image(_) => {}
|
||||
FillTypeInfo::Color(_, fill_type) => {
|
||||
*fill_type = icon_info.background_fill_type;
|
||||
}
|
||||
FillTypeInfo::Color(_) => (),
|
||||
FillTypeInfo::Element(_, fill_type) => {
|
||||
*fill_type = icon_info.background_fill_type;
|
||||
}
|
||||
|
|
|
@ -93,10 +93,10 @@ impl TextFieldInfo {
|
|||
|
||||
if let Some(background_type) = &mut text_field_info.background_type {
|
||||
match background_type {
|
||||
FillTypeInfo::Image(_, fill_type) => {
|
||||
FillTypeInfo::Image(_) => {}
|
||||
FillTypeInfo::Color(_, fill_type) => {
|
||||
*fill_type = text_field_info.background_fill_type;
|
||||
}
|
||||
FillTypeInfo::Color(_) => (),
|
||||
FillTypeInfo::Element(_, fill_type) => {
|
||||
*fill_type = text_field_info.background_fill_type;
|
||||
}
|
||||
|
|
|
@ -527,10 +527,10 @@ pub fn cow_to_fill_type_info<'a>(cow: Cow<'a, [u8]>) -> FillTypeInfo {
|
|||
let text = cow_to_str(cow);
|
||||
|
||||
match Color::try_from(text.as_str()) {
|
||||
Ok(color) => FillTypeInfo::Color(color),
|
||||
Ok(color) => FillTypeInfo::Color(color, DisplayableFillType::Expand),
|
||||
Err(_) => match from_str(text.as_str()) {
|
||||
Ok(descriptor) => FillTypeInfo::Element(descriptor, DisplayableFillType::Expand),
|
||||
Err(_) => FillTypeInfo::Image(AssetPath::from(text), DisplayableFillType::Expand),
|
||||
Err(_) => FillTypeInfo::Image(AssetPath::from(text)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{
|
||||
builder::validator::buttoninfo::ButtonInfo,
|
||||
guihandler::gui::{displayable::DisplayableFillType, iconizable::IconizablePositioning},
|
||||
builder::validator::buttoninfo::ButtonInfo, guihandler::gui::iconizable::IconizablePositioning,
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
|
@ -113,10 +112,7 @@ impl ButtonBuilder {
|
|||
framable.clone(),
|
||||
match self.normal {
|
||||
Some(info) => info,
|
||||
None => FillTypeInfo::from((
|
||||
gui_handler.menu_button().clone(),
|
||||
DisplayableFillType::Expand,
|
||||
)),
|
||||
None => FillTypeInfo::from(gui_handler.menu_button().clone()),
|
||||
},
|
||||
)?;
|
||||
|
||||
|
@ -124,10 +120,7 @@ impl ButtonBuilder {
|
|||
framable.clone(),
|
||||
match self.selected {
|
||||
Some(info) => info,
|
||||
None => FillTypeInfo::from((
|
||||
gui_handler.menu_button_selected().clone(),
|
||||
DisplayableFillType::Expand,
|
||||
)),
|
||||
None => FillTypeInfo::from(gui_handler.menu_button_selected().clone()),
|
||||
},
|
||||
)?;
|
||||
|
||||
|
|
|
@ -13,38 +13,38 @@ use std::sync::{
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum FillTypeInfo {
|
||||
Image(AssetPath, DisplayableFillType),
|
||||
Color(Color),
|
||||
Image(AssetPath),
|
||||
Color(Color, DisplayableFillType),
|
||||
Element(ElementDescriptor, DisplayableFillType),
|
||||
}
|
||||
|
||||
impl From<Color> for FillTypeInfo {
|
||||
fn from(color: Color) -> Self {
|
||||
Self::Color(color)
|
||||
impl From<(Color, DisplayableFillType)> for FillTypeInfo {
|
||||
fn from((color, fill_type): (Color, DisplayableFillType)) -> Self {
|
||||
Self::Color(color, fill_type)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(String, DisplayableFillType)> for FillTypeInfo {
|
||||
fn from((s, fill_type): (String, DisplayableFillType)) -> Self {
|
||||
Self::Image(AssetPath::from(s), fill_type)
|
||||
impl From<String> for FillTypeInfo {
|
||||
fn from(s: String) -> Self {
|
||||
Self::Image(AssetPath::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(&str, DisplayableFillType)> for FillTypeInfo {
|
||||
fn from((s, fill_type): (&str, DisplayableFillType)) -> Self {
|
||||
Self::Image(AssetPath::from(s), fill_type)
|
||||
impl From<&str> for FillTypeInfo {
|
||||
fn from(s: &str) -> Self {
|
||||
Self::Image(AssetPath::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(&String, DisplayableFillType)> for FillTypeInfo {
|
||||
fn from((s, fill_type): (&String, DisplayableFillType)) -> Self {
|
||||
Self::Image(AssetPath::from(s.as_str()), fill_type)
|
||||
impl From<&String> for FillTypeInfo {
|
||||
fn from(s: &String) -> Self {
|
||||
Self::Image(AssetPath::from(s.as_str()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(AssetPath, DisplayableFillType)> for FillTypeInfo {
|
||||
fn from((assetpath, fill_type): (AssetPath, DisplayableFillType)) -> Self {
|
||||
Self::Image(assetpath, fill_type)
|
||||
impl From<AssetPath> for FillTypeInfo {
|
||||
fn from(assetpath: AssetPath) -> Self {
|
||||
Self::Image(assetpath)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,12 +59,14 @@ impl InnerFillType {
|
|||
FillTypeInfo::Element(descriptor, fill_type) => Ok(InnerFillType::Image(
|
||||
Displayable::new(framable, descriptor, fill_type)?,
|
||||
)),
|
||||
FillTypeInfo::Image(path, fill_type) => Ok(InnerFillType::Image(Displayable::new(
|
||||
framable, path, fill_type,
|
||||
FillTypeInfo::Image(path) => Ok(InnerFillType::Image(Displayable::new(
|
||||
framable,
|
||||
path,
|
||||
DisplayableFillType::Expand,
|
||||
)?)),
|
||||
FillTypeInfo::Color(color, fill_type) => Ok(InnerFillType::Color(Colorable::new(
|
||||
framable, color, fill_type,
|
||||
)?)),
|
||||
FillTypeInfo::Color(color) => {
|
||||
Ok(InnerFillType::Color(Colorable::new(framable, color)?))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +157,7 @@ impl FillType {
|
|||
impl PartialEq<FillTypeInfo> for FillType {
|
||||
fn eq(&self, info: &FillTypeInfo) -> bool {
|
||||
match (&self.inner, info) {
|
||||
(InnerFillType::Image(inner_image), FillTypeInfo::Image(info_image, _)) => {
|
||||
(InnerFillType::Image(inner_image), FillTypeInfo::Image(info_image)) => {
|
||||
match inner_image.inner_type() {
|
||||
DisplayableType::Path(path) => path == *info_image,
|
||||
DisplayableType::Descriptor(_) => false,
|
||||
|
@ -167,7 +169,7 @@ impl PartialEq<FillTypeInfo> for FillType {
|
|||
DisplayableType::Descriptor(descriptor) => descriptor == *info_descriptor,
|
||||
}
|
||||
}
|
||||
(InnerFillType::Color(inner_color), FillTypeInfo::Color(info_color)) => {
|
||||
(InnerFillType::Color(inner_color), FillTypeInfo::Color(info_color, _)) => {
|
||||
inner_color.color() == *info_color
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{
|
||||
builder::validator::multi_line_text_field_info::MultiLineTextFieldInfo,
|
||||
guihandler::gui::writeable::ModifyText, prelude::*,
|
||||
guihandler::gui::{displayable::DisplayableFillType, writeable::ModifyText},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use std::sync::{
|
||||
|
@ -247,9 +248,11 @@ impl MultiLineTextField {
|
|||
self.writeable.set_activation_changed(move |active| {
|
||||
if let Some(me) = weak_self.upgrade() {
|
||||
if active {
|
||||
me.grid.set_background(focus_color)?;
|
||||
me.grid
|
||||
.set_background((focus_color, DisplayableFillType::Expand))?;
|
||||
} else {
|
||||
me.grid.set_background(normal_color)?;
|
||||
me.grid
|
||||
.set_background((normal_color, DisplayableFillType::Expand))?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ use cgmath::{vec4, Vector4};
|
|||
use std::sync::atomic::{AtomicI32, Ordering::SeqCst};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use super::displayable::DisplayableFillType;
|
||||
|
||||
/// `Colorable` gives the ability to fill an area with a color
|
||||
pub struct Colorable {
|
||||
framable: Arc<Framable>,
|
||||
|
@ -18,6 +20,7 @@ pub struct Colorable {
|
|||
buffer: Arc<Buffer<ColorableVertex>>,
|
||||
|
||||
color: RwLock<Color>,
|
||||
fill_type: DisplayableFillType,
|
||||
|
||||
ui_layer: AtomicI32,
|
||||
|
||||
|
@ -29,7 +32,11 @@ pub struct Colorable {
|
|||
|
||||
impl Colorable {
|
||||
/// Factory method for `Colorable`, returns `Arc<Colorable>`.
|
||||
pub fn new(framable: Arc<Framable>, color: Color) -> Result<Arc<Self>> {
|
||||
pub fn new(
|
||||
framable: Arc<Framable>,
|
||||
color: Color,
|
||||
fill_type: DisplayableFillType,
|
||||
) -> Result<Arc<Self>> {
|
||||
let set = framable.gui_handler().color_descriptor(color)?;
|
||||
|
||||
let buffer = Buffer::builder()
|
||||
|
@ -45,6 +52,7 @@ impl Colorable {
|
|||
buffer,
|
||||
|
||||
color: RwLock::new(color),
|
||||
fill_type,
|
||||
|
||||
ui_layer: AtomicI32::new(0),
|
||||
|
||||
|
@ -144,11 +152,25 @@ impl Colorable {
|
|||
pub fn update_frame(&self) -> Result<()> {
|
||||
let mut frame = self.buffer.map_complete()?;
|
||||
|
||||
let x_start = self.framable.left() as f32;
|
||||
let y_start = self.framable.top() as f32;
|
||||
let mut x_start = self.framable.left() as f32;
|
||||
let mut y_start = self.framable.top() as f32;
|
||||
|
||||
let width = (self.framable.right() - self.framable.left()) as f32;
|
||||
let height = (self.framable.bottom() - self.framable.top()) as f32;
|
||||
let mut width = (self.framable.right() - self.framable.left()) as f32;
|
||||
let mut height = (self.framable.bottom() - self.framable.top()) as f32;
|
||||
|
||||
if let DisplayableFillType::Square = self.fill_type {
|
||||
if width > height {
|
||||
let diff = width - height;
|
||||
|
||||
x_start += diff * 0.5;
|
||||
width = height;
|
||||
} else if height > width {
|
||||
let diff = height - width;
|
||||
|
||||
y_start += diff * 0.5;
|
||||
height = width;
|
||||
}
|
||||
}
|
||||
|
||||
let left = x_start + width * *self.left_factor.read().unwrap();
|
||||
let right = x_start + width * *self.right_factor.read().unwrap();
|
||||
|
|
Loading…
Reference in a new issue