📦📎-fixes, typo fixes
This commit is contained in:
@@ -216,10 +216,10 @@ fn register_event_mouse_release<U1, U2>(
|
||||
if state.down {
|
||||
state.down = false;
|
||||
|
||||
if state.hovered {
|
||||
if let Some(on_click) = &state.on_click {
|
||||
on_click(common, ButtonClickEvent {})?;
|
||||
}
|
||||
if state.hovered
|
||||
&& let Some(on_click) = &state.on_click
|
||||
{
|
||||
on_click(common, ButtonClickEvent {})?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -229,10 +229,10 @@ fn register_event_mouse_release<U1, U2>(
|
||||
state.checked = !state.checked;
|
||||
set_box_checked(&common.state.widgets, &data, state.checked);
|
||||
|
||||
if state.hovered {
|
||||
if let Some(on_toggle) = &state.on_toggle {
|
||||
on_toggle(common, CheckboxToggleEvent { checked: state.checked })?;
|
||||
}
|
||||
if state.hovered
|
||||
&& let Some(on_toggle) = &state.on_toggle
|
||||
{
|
||||
on_toggle(common, CheckboxToggleEvent { checked: state.checked })?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ pub struct CallbackDataCommon<'a> {
|
||||
}
|
||||
|
||||
impl CallbackDataCommon<'_> {
|
||||
pub fn i18n(&self) -> RefMut<I18n> {
|
||||
pub fn i18n(&self) -> RefMut<'_, I18n> {
|
||||
self.state.globals.i18n()
|
||||
}
|
||||
|
||||
|
||||
@@ -33,15 +33,15 @@ impl WguiGlobals {
|
||||
Ok(Self(Rc::new(RefCell::new(Globals { assets, i18n, defaults }))))
|
||||
}
|
||||
|
||||
pub fn get(&self) -> RefMut<Globals> {
|
||||
pub fn get(&self) -> RefMut<'_, Globals> {
|
||||
self.0.borrow_mut()
|
||||
}
|
||||
|
||||
pub fn i18n(&self) -> RefMut<I18n> {
|
||||
pub fn i18n(&self) -> RefMut<'_, I18n> {
|
||||
RefMut::map(self.0.borrow_mut(), |x| &mut x.i18n)
|
||||
}
|
||||
|
||||
pub fn assets(&self) -> RefMut<Box<dyn AssetProvider>> {
|
||||
pub fn assets(&self) -> RefMut<'_, Box<dyn AssetProvider>> {
|
||||
RefMut::map(self.0.borrow_mut(), |x| &mut x.assets)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ impl Widget {
|
||||
Self(Rc::new(RefCell::new(widget_state)))
|
||||
}
|
||||
|
||||
pub fn get_as_mut<T: 'static>(&self) -> Option<RefMut<T>> {
|
||||
pub fn get_as_mut<T: 'static>(&self) -> Option<RefMut<'_, T>> {
|
||||
RefMut::filter_map(self.0.borrow_mut(), |w| w.obj.get_as_mut::<T>()).ok()
|
||||
}
|
||||
|
||||
pub fn state(&self) -> RefMut<WidgetState> {
|
||||
pub fn state(&self) -> RefMut<'_, WidgetState> {
|
||||
self.0.borrow_mut()
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ impl WidgetMap {
|
||||
Self(HopSlotMap::with_key())
|
||||
}
|
||||
|
||||
pub fn get_as<T: 'static>(&self, handle: WidgetID) -> Option<RefMut<T>> {
|
||||
pub fn get_as<T: 'static>(&self, handle: WidgetID) -> Option<RefMut<'_, T>> {
|
||||
self.0.get(handle)?.get_as_mut::<T>()
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
clippy::implicit_hasher,
|
||||
clippy::option_if_let_else,
|
||||
clippy::significant_drop_tightening,
|
||||
clippy::float_cmp
|
||||
clippy::float_cmp,
|
||||
clippy::needless_pass_by_ref_mut
|
||||
)]
|
||||
|
||||
pub mod animation;
|
||||
|
||||
@@ -208,20 +208,19 @@ pub fn parse_color_hex(html_hex: &str) -> Option<drawing::Color> {
|
||||
1.,
|
||||
));
|
||||
}
|
||||
} else if html_hex.len() == 9 {
|
||||
if let (Ok(r), Ok(g), Ok(b), Ok(a)) = (
|
||||
} else if html_hex.len() == 9
|
||||
&& let (Ok(r), Ok(g), Ok(b), Ok(a)) = (
|
||||
u8::from_str_radix(&html_hex[1..3], 16),
|
||||
u8::from_str_radix(&html_hex[3..5], 16),
|
||||
u8::from_str_radix(&html_hex[5..7], 16),
|
||||
u8::from_str_radix(&html_hex[7..9], 16),
|
||||
) {
|
||||
return Some(drawing::Color::new(
|
||||
f32::from(r) / 255.,
|
||||
f32::from(g) / 255.,
|
||||
f32::from(b) / 255.,
|
||||
f32::from(a) / 255.,
|
||||
));
|
||||
}
|
||||
return Some(drawing::Color::new(
|
||||
f32::from(r) / 255.,
|
||||
f32::from(g) / 255.,
|
||||
f32::from(b) / 255.,
|
||||
f32::from(a) / 255.,
|
||||
));
|
||||
}
|
||||
log::warn!("failed to parse color \"{html_hex}\"");
|
||||
None
|
||||
@@ -670,32 +669,32 @@ fn parse_child<'a, U1, U2>(
|
||||
}
|
||||
|
||||
// check for custom attributes (if the callback is set)
|
||||
if let Some(widget_id) = new_widget_id {
|
||||
if let Some(on_custom_attribs) = &ctx.doc_params.extra.on_custom_attribs {
|
||||
let mut pairs = SmallVec::<[CustomAttribPair; 4]>::new();
|
||||
if let Some(widget_id) = new_widget_id
|
||||
&& let Some(on_custom_attribs) = &ctx.doc_params.extra.on_custom_attribs
|
||||
{
|
||||
let mut pairs = SmallVec::<[CustomAttribPair; 4]>::new();
|
||||
|
||||
for attrib in child_node.attributes() {
|
||||
let attr_name = attrib.name();
|
||||
if !attr_name.starts_with('_') || attr_name.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let attr_without_prefix = &attr_name[1..]; // safe
|
||||
|
||||
pairs.push(CustomAttribPair {
|
||||
attrib: attr_without_prefix,
|
||||
value: attrib.value(),
|
||||
});
|
||||
for attrib in child_node.attributes() {
|
||||
let attr_name = attrib.name();
|
||||
if !attr_name.starts_with('_') || attr_name.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !pairs.is_empty() {
|
||||
on_custom_attribs(CustomAttribsInfo {
|
||||
widgets: &ctx.layout.state.widgets,
|
||||
parent_id,
|
||||
widget_id,
|
||||
pairs: &pairs,
|
||||
});
|
||||
}
|
||||
let attr_without_prefix = &attr_name[1..]; // safe
|
||||
|
||||
pairs.push(CustomAttribPair {
|
||||
attrib: attr_without_prefix,
|
||||
value: attrib.value(),
|
||||
});
|
||||
}
|
||||
|
||||
if !pairs.is_empty() {
|
||||
on_custom_attribs(CustomAttribsInfo {
|
||||
widgets: &ctx.layout.state.widgets,
|
||||
parent_id,
|
||||
widget_id,
|
||||
pairs: &pairs,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -752,7 +751,7 @@ impl CustomAttribsInfo<'_> {
|
||||
self.widgets.get(self.widget_id)
|
||||
}
|
||||
|
||||
pub fn get_widget_as<T: 'static>(&self) -> Option<RefMut<T>> {
|
||||
pub fn get_widget_as<T: 'static>(&self) -> Option<RefMut<'_, T>> {
|
||||
self.widgets.get(self.widget_id)?.get_as_mut::<T>()
|
||||
}
|
||||
|
||||
@@ -797,7 +796,7 @@ pub struct CustomAttribsInfoOwned {
|
||||
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() {
|
||||
for pair in &self.pairs {
|
||||
if pair.attrib == attrib_name {
|
||||
return Some(pair.value.as_str());
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
globals::Globals,
|
||||
i18n::{I18n, Translation},
|
||||
layout::WidgetID,
|
||||
renderer_vk::text::{TextStyle, FONT_SYSTEM},
|
||||
renderer_vk::text::{FONT_SYSTEM, TextStyle},
|
||||
};
|
||||
|
||||
use super::{WidgetObj, WidgetState};
|
||||
@@ -86,7 +86,7 @@ impl WidgetLabel {
|
||||
|
||||
fn update_attrs(&mut self) {
|
||||
let attrs = Attrs::from(&self.params.style);
|
||||
for line in self.buffer.borrow_mut().lines.iter_mut() {
|
||||
for line in &mut self.buffer.borrow_mut().lines {
|
||||
line.set_attrs_list(AttrsList::new(&attrs));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,41 +331,42 @@ impl WidgetState {
|
||||
|
||||
match &event {
|
||||
Event::MouseDown(e) => {
|
||||
if hovered && self.data.set_device_pressed(e.device, true) {
|
||||
if let Some(listeners) = &listeners {
|
||||
call_event!(
|
||||
self,
|
||||
listeners,
|
||||
widget_id,
|
||||
node_id,
|
||||
params,
|
||||
MousePress,
|
||||
user_data,
|
||||
CallbackMetadata::MouseButton(event::MouseButton {
|
||||
index: e.index,
|
||||
pos: e.pos
|
||||
})
|
||||
);
|
||||
}
|
||||
if hovered
|
||||
&& self.data.set_device_pressed(e.device, true)
|
||||
&& let Some(listeners) = &listeners
|
||||
{
|
||||
call_event!(
|
||||
self,
|
||||
listeners,
|
||||
widget_id,
|
||||
node_id,
|
||||
params,
|
||||
MousePress,
|
||||
user_data,
|
||||
CallbackMetadata::MouseButton(event::MouseButton {
|
||||
index: e.index,
|
||||
pos: e.pos
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Event::MouseUp(e) => {
|
||||
if self.data.set_device_pressed(e.device, false) {
|
||||
if let Some(listeners) = listeners {
|
||||
call_event!(
|
||||
self,
|
||||
listeners,
|
||||
widget_id,
|
||||
node_id,
|
||||
params,
|
||||
MouseRelease,
|
||||
user_data,
|
||||
CallbackMetadata::MouseButton(event::MouseButton {
|
||||
index: e.index,
|
||||
pos: e.pos,
|
||||
})
|
||||
);
|
||||
}
|
||||
if self.data.set_device_pressed(e.device, false)
|
||||
&& let Some(listeners) = listeners
|
||||
{
|
||||
call_event!(
|
||||
self,
|
||||
listeners,
|
||||
widget_id,
|
||||
node_id,
|
||||
params,
|
||||
MouseRelease,
|
||||
user_data,
|
||||
CallbackMetadata::MouseButton(event::MouseButton {
|
||||
index: e.index,
|
||||
pos: e.pos,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Event::MouseMotion(e) => {
|
||||
@@ -416,19 +417,19 @@ impl WidgetState {
|
||||
}
|
||||
}
|
||||
Event::MouseLeave(e) => {
|
||||
if self.data.set_device_hovered(e.device, false) {
|
||||
if let Some(listeners) = &listeners {
|
||||
call_event!(
|
||||
self,
|
||||
listeners,
|
||||
widget_id,
|
||||
node_id,
|
||||
params,
|
||||
MouseLeave,
|
||||
user_data,
|
||||
CallbackMetadata::None
|
||||
);
|
||||
}
|
||||
if self.data.set_device_hovered(e.device, false)
|
||||
&& let Some(listeners) = &listeners
|
||||
{
|
||||
call_event!(
|
||||
self,
|
||||
listeners,
|
||||
widget_id,
|
||||
node_id,
|
||||
params,
|
||||
MouseLeave,
|
||||
user_data,
|
||||
CallbackMetadata::None
|
||||
);
|
||||
}
|
||||
}
|
||||
Event::InternalStateChange(e) => {
|
||||
|
||||
Reference in New Issue
Block a user