sorry about monster commit
This commit is contained in:
@@ -766,6 +766,45 @@ impl CustomAttribsInfo<'_> {
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn to_owned(&self) -> CustomAttribsInfoOwned {
|
||||
CustomAttribsInfoOwned {
|
||||
parent_id: self.parent_id,
|
||||
widget_id: self.widget_id,
|
||||
pairs: self
|
||||
.pairs
|
||||
.iter()
|
||||
.map(|p| CustomAttribPairOwned {
|
||||
attrib: p.attrib.to_string(),
|
||||
value: p.value.to_string(),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CustomAttribPairOwned {
|
||||
pub attrib: String, // without _ at the beginning
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
pub struct CustomAttribsInfoOwned {
|
||||
pub parent_id: WidgetID,
|
||||
pub widget_id: WidgetID,
|
||||
pub pairs: Vec<CustomAttribPairOwned>,
|
||||
}
|
||||
|
||||
impl CustomAttribsInfoOwned {
|
||||
pub fn get_value(&self, attrib_name: &str) -> Option<&str> {
|
||||
// O(n) search, these pairs won't be problematically big anyways
|
||||
for pair in self.pairs.iter() {
|
||||
if pair.attrib == attrib_name {
|
||||
return Some(pair.value.as_str());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub type OnCustomAttribsFunc = Box<dyn Fn(CustomAttribsInfo)>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use cosmic_text::{Attrs, Buffer, Metrics, Shaping, Wrap};
|
||||
use cosmic_text::{Attrs, AttrsList, Buffer, Metrics, Shaping, Wrap};
|
||||
use slotmap::Key;
|
||||
use taffy::AvailableSpace;
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
globals::Globals,
|
||||
i18n::{I18n, Translation},
|
||||
layout::WidgetID,
|
||||
renderer_vk::text::{FONT_SYSTEM, TextStyle},
|
||||
renderer_vk::text::{TextStyle, FONT_SYSTEM},
|
||||
};
|
||||
|
||||
use super::{WidgetObj, WidgetState};
|
||||
@@ -84,12 +84,27 @@ impl WidgetLabel {
|
||||
true
|
||||
}
|
||||
|
||||
fn update_attrs(&mut self) {
|
||||
let attrs = Attrs::from(&self.params.style);
|
||||
for line in self.buffer.borrow_mut().lines.iter_mut() {
|
||||
line.set_attrs_list(AttrsList::new(&attrs));
|
||||
}
|
||||
}
|
||||
|
||||
// set text and check if it needs to be re-rendered/re-layouted
|
||||
pub fn set_text(&mut self, common: &mut CallbackDataCommon, translation: Translation) {
|
||||
if self.set_text_simple(&mut common.i18n(), translation) {
|
||||
common.mark_widget_dirty(self.id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_color(&mut self, common: &mut CallbackDataCommon, color: drawing::Color, apply_to_existing_text: bool) {
|
||||
self.params.style.color = Some(color);
|
||||
if apply_to_existing_text {
|
||||
self.update_attrs();
|
||||
common.mark_widget_dirty(self.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetObj for WidgetLabel {
|
||||
|
||||
Reference in New Issue
Block a user