One big cleanup pass of clippy lints
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
e7540d2833
commit
8ba2f77148
138 changed files with 1328 additions and 1366 deletions
|
@ -432,7 +432,7 @@ impl TestAppContext {
|
|||
first_entity_id: usize,
|
||||
) -> Self {
|
||||
let mut cx = MutableAppContext::new(
|
||||
foreground.clone(),
|
||||
foreground,
|
||||
background,
|
||||
platform,
|
||||
foreground_platform.clone(),
|
||||
|
@ -964,6 +964,7 @@ pub struct MutableAppContext {
|
|||
release_observations: Arc<Mutex<HashMap<usize, BTreeMap<usize, ReleaseObservationCallback>>>>,
|
||||
action_dispatch_observations: Arc<Mutex<BTreeMap<usize, ActionObservationCallback>>>,
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
presenters_and_platform_windows:
|
||||
HashMap<usize, (Rc<RefCell<Presenter>>, Box<dyn platform::Window>)>,
|
||||
foreground: Rc<executor::Foreground>,
|
||||
|
@ -1172,7 +1173,9 @@ impl MutableAppContext {
|
|||
F: 'static + FnMut(&mut V, &A, &mut ViewContext<V>) -> Option<Task<Result<()>>>,
|
||||
{
|
||||
self.add_action(move |view, action, cx| {
|
||||
handler(view, action, cx).map(|task| task.detach_and_log_err(cx));
|
||||
if let Some(task) = handler(view, action, cx) {
|
||||
task.detach_and_log_err(cx);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1240,7 +1243,7 @@ impl MutableAppContext {
|
|||
.cx
|
||||
.views
|
||||
.remove(&(window_id, view_id))
|
||||
.ok_or(anyhow!("view not found"))?;
|
||||
.ok_or_else(|| anyhow!("view not found"))?;
|
||||
let element = view.render(params, self);
|
||||
self.cx.views.insert((window_id, view_id), view);
|
||||
Ok(element)
|
||||
|
@ -1252,6 +1255,7 @@ impl MutableAppContext {
|
|||
titlebar_height: f32,
|
||||
) -> HashMap<usize, ElementBox> {
|
||||
self.start_frame();
|
||||
#[allow(clippy::needless_collect)]
|
||||
let view_ids = self
|
||||
.views
|
||||
.keys()
|
||||
|
@ -1263,6 +1267,7 @@ impl MutableAppContext {
|
|||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
view_ids
|
||||
.into_iter()
|
||||
.map(|view_id| {
|
||||
|
@ -2401,7 +2406,7 @@ impl MutableAppContext {
|
|||
let mut invalidation = self
|
||||
.cx
|
||||
.windows
|
||||
.get_mut(&window_id)
|
||||
.get_mut(window_id)
|
||||
.unwrap()
|
||||
.invalidation
|
||||
.take();
|
||||
|
@ -2626,7 +2631,7 @@ impl MutableAppContext {
|
|||
|
||||
fn handle_action_dispatch_notification_effect(&mut self, action_id: TypeId) {
|
||||
let mut callbacks = mem::take(&mut *self.action_dispatch_observations.lock());
|
||||
for (_, callback) in &mut callbacks {
|
||||
for callback in callbacks.values_mut() {
|
||||
callback(action_id, self);
|
||||
}
|
||||
self.action_dispatch_observations.lock().extend(callbacks);
|
||||
|
@ -3228,7 +3233,7 @@ pub trait AnyView {
|
|||
cx: &mut MutableAppContext,
|
||||
) -> Option<Pin<Box<dyn 'static + Future<Output = ()>>>>;
|
||||
fn ui_name(&self) -> &'static str;
|
||||
fn render<'a>(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox;
|
||||
fn render(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox;
|
||||
fn on_focus_in(
|
||||
&mut self,
|
||||
cx: &mut MutableAppContext,
|
||||
|
@ -3304,7 +3309,7 @@ where
|
|||
T::ui_name()
|
||||
}
|
||||
|
||||
fn render<'a>(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox {
|
||||
fn render(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox {
|
||||
View::render(self, &mut RenderContext::new(params, cx))
|
||||
}
|
||||
|
||||
|
@ -3611,7 +3616,7 @@ impl<M> Deref for ModelContext<'_, M> {
|
|||
type Target = MutableAppContext;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.app
|
||||
self.app
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4140,7 +4145,7 @@ impl<M> Deref for ViewContext<'_, M> {
|
|||
type Target = MutableAppContext;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.app
|
||||
self.app
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4290,7 +4295,7 @@ impl<T: Entity> ModelHandle<T> {
|
|||
cx.read_model(self)
|
||||
}
|
||||
|
||||
pub fn read_with<'a, C, F, S>(&self, cx: &C, read: F) -> S
|
||||
pub fn read_with<C, F, S>(&self, cx: &C, read: F) -> S
|
||||
where
|
||||
C: ReadModelWith,
|
||||
F: FnOnce(&T, &AppContext) -> S,
|
||||
|
@ -4381,7 +4386,6 @@ impl<T: Entity> ModelHandle<T> {
|
|||
}
|
||||
}),
|
||||
cx.subscribe(self, {
|
||||
let tx = tx.clone();
|
||||
move |_, _, _| {
|
||||
tx.unbounded_send(()).ok();
|
||||
}
|
||||
|
@ -5258,6 +5262,7 @@ pub enum Subscription {
|
|||
ReleaseObservation {
|
||||
id: usize,
|
||||
entity_id: usize,
|
||||
#[allow(clippy::type_complexity)]
|
||||
observations:
|
||||
Option<Weak<Mutex<HashMap<usize, BTreeMap<usize, ReleaseObservationCallback>>>>>,
|
||||
},
|
||||
|
@ -5407,7 +5412,7 @@ impl Drop for Subscription {
|
|||
}
|
||||
Subscription::ActionObservation { id, observations } => {
|
||||
if let Some(observations) = observations.as_ref().and_then(Weak::upgrade) {
|
||||
observations.lock().remove(&id);
|
||||
observations.lock().remove(id);
|
||||
}
|
||||
}
|
||||
Subscription::WindowActivationObservation {
|
||||
|
@ -5465,6 +5470,7 @@ lazy_static! {
|
|||
#[derive(Default)]
|
||||
pub struct LeakDetector {
|
||||
next_handle_id: usize,
|
||||
#[allow(clippy::type_complexity)]
|
||||
handle_backtraces: HashMap<
|
||||
usize,
|
||||
(
|
||||
|
@ -5502,11 +5508,9 @@ impl LeakDetector {
|
|||
|
||||
pub fn assert_dropped(&mut self, entity_id: usize) {
|
||||
if let Some((type_name, backtraces)) = self.handle_backtraces.get_mut(&entity_id) {
|
||||
for trace in backtraces.values_mut() {
|
||||
if let Some(trace) = trace {
|
||||
trace.resolve();
|
||||
eprintln!("{:?}", crate::util::CwdBacktrace(trace));
|
||||
}
|
||||
for trace in backtraces.values_mut().flatten() {
|
||||
trace.resolve();
|
||||
eprintln!("{:?}", crate::util::CwdBacktrace(trace));
|
||||
}
|
||||
|
||||
let hint = if *LEAK_BACKTRACE {
|
||||
|
@ -5534,11 +5538,9 @@ impl LeakDetector {
|
|||
type_name.unwrap_or("entity"),
|
||||
id
|
||||
);
|
||||
for trace in backtraces.values_mut() {
|
||||
if let Some(trace) = trace {
|
||||
trace.resolve();
|
||||
eprintln!("{:?}", crate::util::CwdBacktrace(trace));
|
||||
}
|
||||
for trace in backtraces.values_mut().flatten() {
|
||||
trace.resolve();
|
||||
eprintln!("{:?}", crate::util::CwdBacktrace(trace));
|
||||
}
|
||||
found_leaks = true;
|
||||
}
|
||||
|
@ -6586,7 +6588,7 @@ mod tests {
|
|||
let subscription = subscription.clone();
|
||||
move |_, _, e, _| {
|
||||
subscription.borrow_mut().take();
|
||||
events.borrow_mut().push(e.clone());
|
||||
events.borrow_mut().push(*e);
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
@ -7158,8 +7160,8 @@ mod tests {
|
|||
|
||||
let model = cx.add_model(|_| Counter(0));
|
||||
|
||||
let condition1 = model.condition(&cx, |model, _| model.0 == 2);
|
||||
let condition2 = model.condition(&cx, |model, _| model.0 == 3);
|
||||
let condition1 = model.condition(cx, |model, _| model.0 == 2);
|
||||
let condition2 = model.condition(cx, |model, _| model.0 == 3);
|
||||
smol::pin!(condition1, condition2);
|
||||
|
||||
model.update(cx, |model, cx| model.inc(cx));
|
||||
|
@ -7186,7 +7188,7 @@ mod tests {
|
|||
}
|
||||
|
||||
let model = cx.add_model(|_| Model);
|
||||
model.condition(&cx, |_, _| false).await;
|
||||
model.condition(cx, |_, _| false).await;
|
||||
}
|
||||
|
||||
#[crate::test(self)]
|
||||
|
@ -7199,7 +7201,7 @@ mod tests {
|
|||
}
|
||||
|
||||
let model = cx.add_model(|_| Model);
|
||||
let condition = model.condition(&cx, |_, _| false);
|
||||
let condition = model.condition(cx, |_, _| false);
|
||||
cx.update(|_| drop(model));
|
||||
condition.await;
|
||||
}
|
||||
|
@ -7231,8 +7233,8 @@ mod tests {
|
|||
|
||||
let (_, view) = cx.add_window(|_| Counter(0));
|
||||
|
||||
let condition1 = view.condition(&cx, |view, _| view.0 == 2);
|
||||
let condition2 = view.condition(&cx, |view, _| view.0 == 3);
|
||||
let condition1 = view.condition(cx, |view, _| view.0 == 2);
|
||||
let condition2 = view.condition(cx, |view, _| view.0 == 3);
|
||||
smol::pin!(condition1, condition2);
|
||||
|
||||
view.update(cx, |view, cx| view.inc(cx));
|
||||
|
@ -7268,7 +7270,7 @@ mod tests {
|
|||
}
|
||||
|
||||
let (_, view) = cx.add_window(|_| View);
|
||||
view.condition(&cx, |_, _| false).await;
|
||||
view.condition(cx, |_, _| false).await;
|
||||
}
|
||||
|
||||
#[crate::test(self)]
|
||||
|
@ -7293,7 +7295,7 @@ mod tests {
|
|||
let (_, root_view) = cx.add_window(|_| View);
|
||||
let view = cx.add_view(&root_view, |_| View);
|
||||
|
||||
let condition = view.condition(&cx, |_, _| false);
|
||||
let condition = view.condition(cx, |_, _| false);
|
||||
cx.update(|_| drop(view));
|
||||
condition.await;
|
||||
}
|
||||
|
|
|
@ -389,9 +389,9 @@ impl ElementBox {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<ElementRc> for ElementBox {
|
||||
fn into(self) -> ElementRc {
|
||||
self.0
|
||||
impl From<ElementBox> for ElementRc {
|
||||
fn from(val: ElementBox) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,14 @@ use crate::{
|
|||
};
|
||||
use crate::{Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Empty {
|
||||
collapsed: bool,
|
||||
}
|
||||
|
||||
impl Empty {
|
||||
pub fn new() -> Self {
|
||||
Self { collapsed: false }
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn collapsed(mut self) -> Self {
|
||||
|
|
|
@ -24,13 +24,13 @@ impl Expanded {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_full_width(mut self) -> Self {
|
||||
pub fn full_width(mut self) -> Self {
|
||||
self.full_width = true;
|
||||
self.full_height = false;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn to_full_height(mut self) -> Self {
|
||||
pub fn full_height(mut self) -> Self {
|
||||
self.full_width = false;
|
||||
self.full_height = true;
|
||||
self
|
||||
|
|
|
@ -53,8 +53,8 @@ impl Element for Image {
|
|||
_: &mut LayoutContext,
|
||||
) -> (Vector2F, Self::LayoutState) {
|
||||
let desired_size = vec2f(
|
||||
self.style.width.unwrap_or(constraint.max.x()),
|
||||
self.style.height.unwrap_or(constraint.max.y()),
|
||||
self.style.width.unwrap_or_else(|| constraint.max.x()),
|
||||
self.style.height.unwrap_or_else(|| constraint.max.y()),
|
||||
);
|
||||
let size = constrain_size_preserving_aspect_ratio(
|
||||
constraint.constrain(desired_size),
|
||||
|
|
|
@ -33,6 +33,7 @@ struct StateInner {
|
|||
logical_scroll_top: Option<ListOffset>,
|
||||
orientation: Orientation,
|
||||
overdraw: f32,
|
||||
#[allow(clippy::type_complexity)]
|
||||
scroll_handler: Option<Box<dyn FnMut(Range<usize>, &mut EventContext)>>,
|
||||
}
|
||||
|
||||
|
@ -311,19 +312,17 @@ impl Element for List {
|
|||
drop(cursor);
|
||||
state.items = new_items;
|
||||
|
||||
match event {
|
||||
Event::ScrollWheel(ScrollWheelEvent {
|
||||
position,
|
||||
delta,
|
||||
precise,
|
||||
}) => {
|
||||
if bounds.contains_point(*position) {
|
||||
if state.scroll(scroll_top, bounds.height(), *delta, *precise, cx) {
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
if let Event::ScrollWheel(ScrollWheelEvent {
|
||||
position,
|
||||
delta,
|
||||
precise,
|
||||
}) = event
|
||||
{
|
||||
if bounds.contains_point(*position)
|
||||
&& state.scroll(scroll_top, bounds.height(), *delta, *precise, cx)
|
||||
{
|
||||
handled = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
handled
|
||||
|
|
|
@ -129,7 +129,7 @@ impl Element for MouseEventHandler {
|
|||
|
||||
cx.scene.push_mouse_region(MouseRegion::from_handlers(
|
||||
cx.current_view_id(),
|
||||
Some(self.discriminant.clone()),
|
||||
Some(self.discriminant),
|
||||
hit_bounds,
|
||||
self.handlers.clone(),
|
||||
));
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Element for Overlay {
|
|||
size: &mut Self::LayoutState,
|
||||
cx: &mut PaintContext,
|
||||
) {
|
||||
let mut bounds = RectF::new(self.abs_position.unwrap_or(bounds.origin()), *size);
|
||||
let mut bounds = RectF::new(self.abs_position.unwrap_or_else(|| bounds.origin()), *size);
|
||||
cx.scene.push_stacking_context(None);
|
||||
|
||||
if self.hoverable {
|
||||
|
|
|
@ -8,15 +8,14 @@ use crate::{
|
|||
SizeConstraint,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Stack {
|
||||
children: Vec<ElementBox>,
|
||||
}
|
||||
|
||||
impl Stack {
|
||||
pub fn new() -> Self {
|
||||
Stack {
|
||||
children: Vec::new(),
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ impl Element for Text {
|
|||
chunks,
|
||||
&self.style,
|
||||
cx.text_layout_cache,
|
||||
&cx.font_cache,
|
||||
cx.font_cache,
|
||||
usize::MAX,
|
||||
self.text.matches('\n').count() + 1,
|
||||
);
|
||||
|
|
|
@ -45,6 +45,7 @@ pub struct LayoutState {
|
|||
pub struct UniformList {
|
||||
state: UniformListState,
|
||||
item_count: usize,
|
||||
#[allow(clippy::type_complexity)]
|
||||
append_items: Box<dyn Fn(Range<usize>, &mut Vec<ElementBox>, &mut LayoutContext)>,
|
||||
padding_top: f32,
|
||||
padding_bottom: f32,
|
||||
|
@ -310,19 +311,17 @@ impl Element for UniformList {
|
|||
handled = item.dispatch_event(event, cx) || handled;
|
||||
}
|
||||
|
||||
match event {
|
||||
Event::ScrollWheel(ScrollWheelEvent {
|
||||
position,
|
||||
delta,
|
||||
precise,
|
||||
}) => {
|
||||
if bounds.contains_point(*position) {
|
||||
if self.scroll(*position, *delta, *precise, layout.scroll_max, cx) {
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
if let Event::ScrollWheel(ScrollWheelEvent {
|
||||
position,
|
||||
delta,
|
||||
precise,
|
||||
}) = event
|
||||
{
|
||||
if bounds.contains_point(*position)
|
||||
&& self.scroll(*position, *delta, *precise, layout.scroll_max, cx)
|
||||
{
|
||||
handled = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
handled
|
||||
|
|
|
@ -332,7 +332,7 @@ impl Deterministic {
|
|||
|
||||
pub fn now(&self) -> std::time::Instant {
|
||||
let state = self.state.lock();
|
||||
state.now.clone()
|
||||
state.now
|
||||
}
|
||||
|
||||
pub fn advance_clock(&self, duration: Duration) {
|
||||
|
@ -681,6 +681,12 @@ impl Background {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Background {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Scope<'a> {
|
||||
executor: Arc<Background>,
|
||||
futures: Vec<Pin<Box<dyn Future<Output = ()> + Send + 'static>>>,
|
||||
|
|
|
@ -117,7 +117,7 @@ impl FontCache {
|
|||
.font_selections
|
||||
.entry(family_id)
|
||||
.or_default()
|
||||
.insert(properties.clone(), font_id);
|
||||
.insert(*properties, font_id);
|
||||
Ok(font_id)
|
||||
}
|
||||
}
|
||||
|
@ -257,10 +257,10 @@ mod tests {
|
|||
let arial = fonts.load_family(&["Arial"]).unwrap();
|
||||
let arial_regular = fonts.select_font(arial, &Properties::new()).unwrap();
|
||||
let arial_italic = fonts
|
||||
.select_font(arial, &Properties::new().style(Style::Italic))
|
||||
.select_font(arial, Properties::new().style(Style::Italic))
|
||||
.unwrap();
|
||||
let arial_bold = fonts
|
||||
.select_font(arial, &Properties::new().weight(Weight::BOLD))
|
||||
.select_font(arial, Properties::new().weight(Weight::BOLD))
|
||||
.unwrap();
|
||||
assert_ne!(arial_regular, arial_italic);
|
||||
assert_ne!(arial_regular, arial_bold);
|
||||
|
|
|
@ -332,8 +332,7 @@ impl<'de> Deserialize<'de> for TextStyle {
|
|||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
Ok(Self::from_json(TextStyleJson::deserialize(deserializer)?)
|
||||
.map_err(|e| de::Error::custom(e))?)
|
||||
Self::from_json(TextStyleJson::deserialize(deserializer)?).map_err(de::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,12 @@ enum PathVertexKind {
|
|||
Quadratic,
|
||||
}
|
||||
|
||||
impl Default for PathBuilder {
|
||||
fn default() -> Self {
|
||||
PathBuilder::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl PathBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -58,10 +64,7 @@ impl PathBuilder {
|
|||
|
||||
pub fn build(mut self, color: Color, clip_bounds: Option<RectF>) -> Path {
|
||||
if let Some(clip_bounds) = clip_bounds {
|
||||
self.bounds = self
|
||||
.bounds
|
||||
.intersection(clip_bounds)
|
||||
.unwrap_or(RectF::default());
|
||||
self.bounds = self.bounds.intersection(clip_bounds).unwrap_or_default();
|
||||
}
|
||||
Path {
|
||||
bounds: self.bounds,
|
||||
|
|
|
@ -202,7 +202,7 @@ impl Keymap {
|
|||
for (ix, binding) in bindings.iter().enumerate() {
|
||||
binding_indices_by_action_type
|
||||
.entry(binding.action.as_any().type_id())
|
||||
.or_insert_with(|| SmallVec::new())
|
||||
.or_insert_with(SmallVec::new)
|
||||
.push(ix);
|
||||
}
|
||||
Self {
|
||||
|
@ -211,10 +211,7 @@ impl Keymap {
|
|||
}
|
||||
}
|
||||
|
||||
fn bindings_for_action_type<'a>(
|
||||
&'a self,
|
||||
action_type: TypeId,
|
||||
) -> impl Iterator<Item = &'a Binding> {
|
||||
fn bindings_for_action_type(&self, action_type: TypeId) -> impl Iterator<Item = &'_ Binding> {
|
||||
self.binding_indices_by_action_type
|
||||
.get(&action_type)
|
||||
.map(SmallVec::as_slice)
|
||||
|
@ -253,7 +250,7 @@ impl Binding {
|
|||
|
||||
let keystrokes = keystrokes
|
||||
.split_whitespace()
|
||||
.map(|key| Keystroke::parse(key))
|
||||
.map(Keystroke::parse)
|
||||
.collect::<Result<_>>()?;
|
||||
|
||||
Ok(Self {
|
||||
|
@ -281,7 +278,7 @@ impl Keystroke {
|
|||
let mut function = false;
|
||||
let mut key = None;
|
||||
|
||||
let mut components = source.split("-").peekable();
|
||||
let mut components = source.split('-').peekable();
|
||||
while let Some(component) = components.next() {
|
||||
match component {
|
||||
"ctrl" => ctrl = true,
|
||||
|
@ -379,12 +376,12 @@ impl ContextPredicate {
|
|||
let kind = node.kind();
|
||||
|
||||
match kind {
|
||||
"source" => Self::from_node(node.child(0).ok_or(anyhow!(parse_error))?, source),
|
||||
"source" => Self::from_node(node.child(0).ok_or_else(|| anyhow!(parse_error))?, source),
|
||||
"identifier" => Ok(Self::Identifier(node.utf8_text(source)?.into())),
|
||||
"not" => {
|
||||
let child = Self::from_node(
|
||||
node.child_by_field_name("expression")
|
||||
.ok_or(anyhow!(parse_error))?,
|
||||
.ok_or_else(|| anyhow!(parse_error))?,
|
||||
source,
|
||||
)?;
|
||||
Ok(Self::Not(Box::new(child)))
|
||||
|
@ -392,12 +389,12 @@ impl ContextPredicate {
|
|||
"and" | "or" => {
|
||||
let left = Box::new(Self::from_node(
|
||||
node.child_by_field_name("left")
|
||||
.ok_or(anyhow!(parse_error))?,
|
||||
.ok_or_else(|| anyhow!(parse_error))?,
|
||||
source,
|
||||
)?);
|
||||
let right = Box::new(Self::from_node(
|
||||
node.child_by_field_name("right")
|
||||
.ok_or(anyhow!(parse_error))?,
|
||||
.ok_or_else(|| anyhow!(parse_error))?,
|
||||
source,
|
||||
)?);
|
||||
if kind == "and" {
|
||||
|
@ -409,12 +406,12 @@ impl ContextPredicate {
|
|||
"equal" | "not_equal" => {
|
||||
let left = node
|
||||
.child_by_field_name("left")
|
||||
.ok_or(anyhow!(parse_error))?
|
||||
.ok_or_else(|| anyhow!(parse_error))?
|
||||
.utf8_text(source)?
|
||||
.into();
|
||||
let right = node
|
||||
.child_by_field_name("right")
|
||||
.ok_or(anyhow!(parse_error))?
|
||||
.ok_or_else(|| anyhow!(parse_error))?
|
||||
.utf8_text(source)?
|
||||
.into();
|
||||
if kind == "equal" {
|
||||
|
@ -425,7 +422,7 @@ impl ContextPredicate {
|
|||
}
|
||||
"parenthesized" => Self::from_node(
|
||||
node.child_by_field_name("expression")
|
||||
.ok_or(anyhow!(parse_error))?,
|
||||
.ok_or_else(|| anyhow!(parse_error))?,
|
||||
source,
|
||||
),
|
||||
_ => Err(anyhow!(parse_error)),
|
||||
|
@ -604,7 +601,7 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn downcast<'a, A: Action>(action: &'a Option<Box<dyn Action>>) -> Option<&'a A> {
|
||||
fn downcast<A: Action>(action: &Option<Box<dyn Action>>) -> Option<&A> {
|
||||
action
|
||||
.as_ref()
|
||||
.and_then(|action| action.as_any().downcast_ref())
|
||||
|
|
|
@ -74,7 +74,7 @@ pub(crate) trait ForegroundPlatform {
|
|||
fn on_quit(&self, callback: Box<dyn FnMut()>);
|
||||
fn on_event(&self, callback: Box<dyn FnMut(Event) -> bool>);
|
||||
fn on_open_urls(&self, callback: Box<dyn FnMut(Vec<String>)>);
|
||||
fn run(&self, on_finish_launching: Box<dyn FnOnce() -> ()>);
|
||||
fn run(&self, on_finish_launching: Box<dyn FnOnce()>);
|
||||
|
||||
fn on_menu_command(&self, callback: Box<dyn FnMut(&dyn Action)>);
|
||||
fn on_validate_menu_command(&self, callback: Box<dyn FnMut(&dyn Action) -> bool>);
|
||||
|
|
|
@ -223,7 +223,7 @@ unsafe fn parse_keystroke(native_event: id) -> Keystroke {
|
|||
let cmd = modifiers.contains(NSEventModifierFlags::NSCommandKeyMask);
|
||||
let function = modifiers.contains(NSEventModifierFlags::NSFunctionKeyMask)
|
||||
&& first_char.map_or(true, |ch| {
|
||||
ch < NSUpArrowFunctionKey || ch > NSModeSwitchFunctionKey
|
||||
!(NSUpArrowFunctionKey..=NSModeSwitchFunctionKey).contains(&ch)
|
||||
});
|
||||
|
||||
#[allow(non_upper_case_globals)]
|
||||
|
|
|
@ -53,6 +53,12 @@ impl FontSystem {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for FontSystem {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl platform::FontSystem for FontSystem {
|
||||
fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> anyhow::Result<()> {
|
||||
self.0.write().add_fonts(fonts)
|
||||
|
@ -402,7 +408,7 @@ impl FontSystemState {
|
|||
fn wrap_line(&self, text: &str, font_id: FontId, font_size: f32, width: f32) -> Vec<usize> {
|
||||
let mut string = CFMutableAttributedString::new();
|
||||
string.replace_str(&CFString::new(text), CFRange::init(0, 0));
|
||||
let cf_range = CFRange::init(0 as isize, text.encode_utf16().count() as isize);
|
||||
let cf_range = CFRange::init(0, text.encode_utf16().count() as isize);
|
||||
let font = &self.fonts[font_id.0];
|
||||
unsafe {
|
||||
string.set_attribute(
|
||||
|
@ -505,14 +511,14 @@ mod tests {
|
|||
};
|
||||
let menlo_italic = RunStyle {
|
||||
font_id: fonts
|
||||
.select_font(&menlo, &Properties::new().style(Style::Italic))
|
||||
.select_font(&menlo, Properties::new().style(Style::Italic))
|
||||
.unwrap(),
|
||||
color: Default::default(),
|
||||
underline: Default::default(),
|
||||
};
|
||||
let menlo_bold = RunStyle {
|
||||
font_id: fonts
|
||||
.select_font(&menlo, &Properties::new().weight(Weight::BOLD))
|
||||
.select_font(&menlo, Properties::new().weight(Weight::BOLD))
|
||||
.unwrap(),
|
||||
color: Default::default(),
|
||||
underline: Default::default(),
|
||||
|
@ -599,7 +605,7 @@ mod tests {
|
|||
let name = format!("/Users/as-cii/Desktop/twog-{}.png", i);
|
||||
let path = Path::new(&name);
|
||||
let file = File::create(path).unwrap();
|
||||
let ref mut w = BufWriter::new(file);
|
||||
let w = &mut BufWriter::new(file);
|
||||
|
||||
let mut encoder = png::Encoder::new(w, bounds.width() as u32, bounds.height() as u32);
|
||||
encoder.set_color(png::ColorType::Grayscale);
|
||||
|
|
|
@ -50,7 +50,7 @@ use time::UtcOffset;
|
|||
#[allow(non_upper_case_globals)]
|
||||
const NSUTF8StringEncoding: NSUInteger = 4;
|
||||
|
||||
const MAC_PLATFORM_IVAR: &'static str = "platform";
|
||||
const MAC_PLATFORM_IVAR: &str = "platform";
|
||||
static mut APP_CLASS: *const Class = ptr::null();
|
||||
static mut APP_DELEGATE_CLASS: *const Class = ptr::null();
|
||||
|
||||
|
@ -118,7 +118,7 @@ pub struct MacForegroundPlatformState {
|
|||
validate_menu_command: Option<Box<dyn FnMut(&dyn Action) -> bool>>,
|
||||
will_open_menu: Option<Box<dyn FnMut()>>,
|
||||
open_urls: Option<Box<dyn FnMut(Vec<String>)>>,
|
||||
finish_launching: Option<Box<dyn FnOnce() -> ()>>,
|
||||
finish_launching: Option<Box<dyn FnOnce()>>,
|
||||
menu_actions: Vec<Box<dyn Action>>,
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ impl platform::ForegroundPlatform for MacForegroundPlatform {
|
|||
self.0.borrow_mut().open_urls = Some(callback);
|
||||
}
|
||||
|
||||
fn run(&self, on_finish_launching: Box<dyn FnOnce() -> ()>) {
|
||||
fn run(&self, on_finish_launching: Box<dyn FnOnce()>) {
|
||||
self.0.borrow_mut().finish_launching = Some(on_finish_launching);
|
||||
|
||||
unsafe {
|
||||
|
@ -533,7 +533,7 @@ impl platform::Platform for MacPlatform {
|
|||
fn read_from_clipboard(&self) -> Option<ClipboardItem> {
|
||||
unsafe {
|
||||
if let Some(text_bytes) = self.read_from_pasteboard(NSPasteboardTypeString) {
|
||||
let text = String::from_utf8_lossy(&text_bytes).to_string();
|
||||
let text = String::from_utf8_lossy(text_bytes).to_string();
|
||||
let hash_bytes = self
|
||||
.read_from_pasteboard(self.text_hash_pasteboard_type)
|
||||
.and_then(|bytes| bytes.try_into().ok())
|
||||
|
|
|
@ -14,8 +14,7 @@ use metal::{MTLPixelFormat, MTLResourceOptions, NSRange};
|
|||
use shaders::ToFloat2 as _;
|
||||
use std::{collections::HashMap, ffi::c_void, iter::Peekable, mem, sync::Arc, vec};
|
||||
|
||||
const SHADERS_METALLIB: &'static [u8] =
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/shaders.metallib"));
|
||||
const SHADERS_METALLIB: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/shaders.metallib"));
|
||||
const INSTANCE_BUFFER_SIZE: usize = 8192 * 1024; // This is an arbitrary decision. There's probably a more optimal value.
|
||||
|
||||
pub struct Renderer {
|
||||
|
@ -385,10 +384,10 @@ impl Renderer {
|
|||
drawable_size: Vector2F,
|
||||
command_encoder: &metal::RenderCommandEncoderRef,
|
||||
) {
|
||||
let clip_bounds = (layer.clip_bounds().unwrap_or(RectF::new(
|
||||
vec2f(0., 0.),
|
||||
drawable_size / scene.scale_factor(),
|
||||
)) * scene.scale_factor())
|
||||
let clip_bounds = (layer
|
||||
.clip_bounds()
|
||||
.unwrap_or_else(|| RectF::new(vec2f(0., 0.), drawable_size / scene.scale_factor()))
|
||||
* scene.scale_factor())
|
||||
.round();
|
||||
command_encoder.set_scissor_rect(metal::MTLScissorRect {
|
||||
x: clip_bounds.origin_x() as NSUInteger,
|
||||
|
@ -438,8 +437,7 @@ impl Renderer {
|
|||
);
|
||||
|
||||
let buffer_contents = unsafe {
|
||||
(self.instances.contents() as *mut u8).offset(*offset as isize)
|
||||
as *mut shaders::GPUIShadow
|
||||
(self.instances.contents() as *mut u8).add(*offset) as *mut shaders::GPUIShadow
|
||||
};
|
||||
for (ix, shadow) in shadows.iter().enumerate() {
|
||||
let shape_bounds = shadow.bounds * scale_factor;
|
||||
|
@ -451,7 +449,7 @@ impl Renderer {
|
|||
color: shadow.color.to_uchar4(),
|
||||
};
|
||||
unsafe {
|
||||
*(buffer_contents.offset(ix as isize)) = shader_shadow;
|
||||
*(buffer_contents.add(ix)) = shader_shadow;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,8 +501,7 @@ impl Renderer {
|
|||
);
|
||||
|
||||
let buffer_contents = unsafe {
|
||||
(self.instances.contents() as *mut u8).offset(*offset as isize)
|
||||
as *mut shaders::GPUIQuad
|
||||
(self.instances.contents() as *mut u8).add(*offset) as *mut shaders::GPUIQuad
|
||||
};
|
||||
for (ix, quad) in quads.iter().enumerate() {
|
||||
let bounds = quad.bounds * scale_factor;
|
||||
|
@ -514,7 +511,7 @@ impl Renderer {
|
|||
size: bounds.size().round().to_float2(),
|
||||
background_color: quad
|
||||
.background
|
||||
.unwrap_or(Color::transparent_black())
|
||||
.unwrap_or_else(Color::transparent_black)
|
||||
.to_uchar4(),
|
||||
border_top: border_width * (quad.border.top as usize as f32),
|
||||
border_right: border_width * (quad.border.right as usize as f32),
|
||||
|
@ -524,7 +521,7 @@ impl Renderer {
|
|||
corner_radius: quad.corner_radius * scale_factor,
|
||||
};
|
||||
unsafe {
|
||||
*(buffer_contents.offset(ix as isize)) = shader_quad;
|
||||
*(buffer_contents.add(ix)) = shader_quad;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -641,9 +638,8 @@ impl Renderer {
|
|||
);
|
||||
|
||||
unsafe {
|
||||
let buffer_contents = (self.instances.contents() as *mut u8)
|
||||
.offset(*offset as isize)
|
||||
as *mut shaders::GPUISprite;
|
||||
let buffer_contents =
|
||||
(self.instances.contents() as *mut u8).add(*offset) as *mut shaders::GPUISprite;
|
||||
std::ptr::copy_nonoverlapping(sprites.as_ptr(), buffer_contents, sprites.len());
|
||||
}
|
||||
|
||||
|
@ -757,9 +753,8 @@ impl Renderer {
|
|||
);
|
||||
|
||||
unsafe {
|
||||
let buffer_contents = (self.instances.contents() as *mut u8)
|
||||
.offset(*offset as isize)
|
||||
as *mut shaders::GPUIImage;
|
||||
let buffer_contents =
|
||||
(self.instances.contents() as *mut u8).add(*offset) as *mut shaders::GPUIImage;
|
||||
std::ptr::copy_nonoverlapping(images.as_ptr(), buffer_contents, images.len());
|
||||
}
|
||||
|
||||
|
@ -821,10 +816,9 @@ impl Renderer {
|
|||
}
|
||||
|
||||
unsafe {
|
||||
let buffer_contents = (self.instances.contents() as *mut u8)
|
||||
.offset(*offset as isize)
|
||||
as *mut shaders::GPUISprite;
|
||||
*buffer_contents.offset(atlas_sprite_count as isize) = sprite.shader_data;
|
||||
let buffer_contents =
|
||||
(self.instances.contents() as *mut u8).add(*offset) as *mut shaders::GPUISprite;
|
||||
*buffer_contents.add(atlas_sprite_count) = sprite.shader_data;
|
||||
}
|
||||
|
||||
atlas_sprite_count += 1;
|
||||
|
@ -917,8 +911,7 @@ impl Renderer {
|
|||
);
|
||||
|
||||
let buffer_contents = unsafe {
|
||||
(self.instances.contents() as *mut u8).offset(*offset as isize)
|
||||
as *mut shaders::GPUIUnderline
|
||||
(self.instances.contents() as *mut u8).add(*offset) as *mut shaders::GPUIUnderline
|
||||
};
|
||||
for (ix, underline) in underlines.iter().enumerate() {
|
||||
let origin = underline.origin * scale_factor;
|
||||
|
@ -935,7 +928,7 @@ impl Renderer {
|
|||
squiggly: underline.squiggly as u8,
|
||||
};
|
||||
unsafe {
|
||||
*(buffer_contents.offset(ix as isize)) = shader_underline;
|
||||
*(buffer_contents.add(ix)) = shader_underline;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
const WINDOW_STATE_IVAR: &'static str = "windowState";
|
||||
const WINDOW_STATE_IVAR: &str = "windowState";
|
||||
|
||||
static mut WINDOW_CLASS: *const Class = ptr::null();
|
||||
static mut VIEW_CLASS: *const Class = ptr::null();
|
||||
|
@ -72,7 +72,7 @@ impl NSRange {
|
|||
self.location != NSNotFound as NSUInteger
|
||||
}
|
||||
|
||||
fn to_range(&self) -> Option<Range<usize>> {
|
||||
fn to_range(self) -> Option<Range<usize>> {
|
||||
if self.is_valid() {
|
||||
let start = self.location as usize;
|
||||
let end = start + self.length as usize;
|
||||
|
@ -513,7 +513,7 @@ impl platform::Window for Window {
|
|||
};
|
||||
let _: () = msg_send![alert, setAlertStyle: alert_style];
|
||||
let _: () = msg_send![alert, setMessageText: ns_string(msg)];
|
||||
for (ix, answer) in answers.into_iter().enumerate() {
|
||||
for (ix, answer) in answers.iter().enumerate() {
|
||||
let button: id = msg_send![alert, addButtonWithTitle: ns_string(answer)];
|
||||
let _: () = msg_send![button, setTag: ix as NSInteger];
|
||||
}
|
||||
|
@ -721,14 +721,14 @@ extern "C" fn yes(_: &Object, _: Sel) -> BOOL {
|
|||
extern "C" fn dealloc_window(this: &Object, _: Sel) {
|
||||
unsafe {
|
||||
drop_window_state(this);
|
||||
let () = msg_send![super(this, class!(NSWindow)), dealloc];
|
||||
let _: () = msg_send![super(this, class!(NSWindow)), dealloc];
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn dealloc_view(this: &Object, _: Sel) {
|
||||
unsafe {
|
||||
drop_window_state(this);
|
||||
let () = msg_send![super(this, class!(NSView)), dealloc];
|
||||
let _: () = msg_send![super(this, class!(NSView)), dealloc];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -912,7 +912,7 @@ extern "C" fn cancel_operation(this: &Object, _sel: Sel, _sender: id) {
|
|||
|
||||
extern "C" fn send_event(this: &Object, _: Sel, native_event: id) {
|
||||
unsafe {
|
||||
let () = msg_send![super(this, class!(NSWindow)), sendEvent: native_event];
|
||||
let _: () = msg_send![super(this, class!(NSWindow)), sendEvent: native_event];
|
||||
get_window_state(this).borrow_mut().performed_key_equivalent = false;
|
||||
}
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ extern "C" fn close_window(this: &Object, _: Sel) {
|
|||
callback();
|
||||
}
|
||||
|
||||
let () = msg_send![super(this, class!(NSWindow)), close];
|
||||
let _: () = msg_send![super(this, class!(NSWindow)), close];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1157,17 +1157,22 @@ extern "C" fn insert_text(this: &Object, _: Sel, text: id, replacement_range: NS
|
|||
.flatten()
|
||||
.is_some();
|
||||
|
||||
if is_composing || text.chars().count() > 1 || pending_key_down.is_none() {
|
||||
with_input_handler(this, |input_handler| {
|
||||
input_handler.replace_text_in_range(replacement_range, text)
|
||||
});
|
||||
} else {
|
||||
let mut pending_key_down = pending_key_down.unwrap();
|
||||
pending_key_down.1 = Some(InsertText {
|
||||
replacement_range,
|
||||
text: text.to_string(),
|
||||
});
|
||||
window_state.borrow_mut().pending_key_down = Some(pending_key_down);
|
||||
match pending_key_down {
|
||||
None | Some(_) if is_composing || text.chars().count() > 1 => {
|
||||
with_input_handler(this, |input_handler| {
|
||||
input_handler.replace_text_in_range(replacement_range, text)
|
||||
});
|
||||
}
|
||||
|
||||
Some(mut pending_key_down) => {
|
||||
pending_key_down.1 = Some(InsertText {
|
||||
replacement_range,
|
||||
text: text.to_string(),
|
||||
});
|
||||
window_state.borrow_mut().pending_key_down = Some(pending_key_down);
|
||||
}
|
||||
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ impl super::ForegroundPlatform for ForegroundPlatform {
|
|||
|
||||
fn on_open_urls(&self, _: Box<dyn FnMut(Vec<String>)>) {}
|
||||
|
||||
fn run(&self, _on_finish_launching: Box<dyn FnOnce() -> ()>) {
|
||||
fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
|
|
@ -89,8 +89,8 @@ impl Presenter {
|
|||
) {
|
||||
cx.start_frame();
|
||||
for view_id in &invalidation.removed {
|
||||
invalidation.updated.remove(&view_id);
|
||||
self.rendered_views.remove(&view_id);
|
||||
invalidation.updated.remove(view_id);
|
||||
self.rendered_views.remove(view_id);
|
||||
}
|
||||
for view_id in &invalidation.updated {
|
||||
self.rendered_views.insert(
|
||||
|
@ -285,7 +285,7 @@ impl Presenter {
|
|||
{
|
||||
dragged_region = Some((
|
||||
clicked_region.clone(),
|
||||
MouseRegionEvent::Drag(*prev_drag_position, e.clone()),
|
||||
MouseRegionEvent::Drag(*prev_drag_position, *e),
|
||||
));
|
||||
*prev_drag_position = *position;
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ impl Presenter {
|
|||
},
|
||||
) = event
|
||||
{
|
||||
if let None = pressed_button {
|
||||
if pressed_button.is_none() {
|
||||
let mut style_to_assign = CursorStyle::Arrow;
|
||||
for region in self.cursor_regions.iter().rev() {
|
||||
if region.bounds.contains_point(*position) {
|
||||
|
@ -385,23 +385,17 @@ impl Presenter {
|
|||
if let Some(region_id) = region.id() {
|
||||
if !self.hovered_region_ids.contains(®ion_id) {
|
||||
invalidated_views.push(region.view_id);
|
||||
hover_regions.push((
|
||||
region.clone(),
|
||||
MouseRegionEvent::Hover(true, e.clone()),
|
||||
));
|
||||
hover_regions
|
||||
.push((region.clone(), MouseRegionEvent::Hover(true, *e)));
|
||||
self.hovered_region_ids.insert(region_id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(region_id) = region.id() {
|
||||
if self.hovered_region_ids.contains(®ion_id) {
|
||||
invalidated_views.push(region.view_id);
|
||||
hover_regions.push((
|
||||
region.clone(),
|
||||
MouseRegionEvent::Hover(false, e.clone()),
|
||||
));
|
||||
self.hovered_region_ids.remove(®ion_id);
|
||||
}
|
||||
} else if let Some(region_id) = region.id() {
|
||||
if self.hovered_region_ids.contains(®ion_id) {
|
||||
invalidated_views.push(region.view_id);
|
||||
hover_regions
|
||||
.push((region.clone(), MouseRegionEvent::Hover(false, *e)));
|
||||
self.hovered_region_ids.remove(®ion_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -625,7 +619,7 @@ impl<'a> PaintContext<'a> {
|
|||
#[inline]
|
||||
pub fn paint_layer<F>(&mut self, clip_bounds: Option<RectF>, f: F)
|
||||
where
|
||||
F: FnOnce(&mut Self) -> (),
|
||||
F: FnOnce(&mut Self),
|
||||
{
|
||||
self.scene.push_layer(clip_bounds);
|
||||
f(self);
|
||||
|
|
|
@ -107,6 +107,7 @@ pub struct MouseRegionId {
|
|||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct HandlerSet {
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub set: HashMap<
|
||||
(Discriminant<MouseRegionEvent>, Option<MouseButton>),
|
||||
Rc<dyn Fn(MouseRegionEvent, &mut EventContext)>,
|
||||
|
@ -115,6 +116,7 @@ pub struct HandlerSet {
|
|||
|
||||
impl HandlerSet {
|
||||
pub fn handle_all() -> Self {
|
||||
#[allow(clippy::type_complexity)]
|
||||
let mut set: HashMap<
|
||||
(Discriminant<MouseRegionEvent>, Option<MouseButton>),
|
||||
Rc<dyn Fn(MouseRegionEvent, &mut EventContext)>,
|
||||
|
|
|
@ -66,7 +66,7 @@ impl TextLayoutCache {
|
|||
let mut curr_frame = RwLockUpgradableReadGuard::upgrade(curr_frame);
|
||||
if let Some((key, layout)) = self.prev_frame.lock().remove_entry(key) {
|
||||
curr_frame.insert(key, layout.clone());
|
||||
Line::new(layout.clone(), runs)
|
||||
Line::new(layout, runs)
|
||||
} else {
|
||||
let layout = Arc::new(self.fonts.layout_line(text, font_size, runs));
|
||||
let key = CacheKeyValue {
|
||||
|
@ -81,7 +81,7 @@ impl TextLayoutCache {
|
|||
}
|
||||
|
||||
trait CacheKey {
|
||||
fn key<'a>(&'a self) -> CacheKeyRef<'a>;
|
||||
fn key(&self) -> CacheKeyRef;
|
||||
}
|
||||
|
||||
impl<'a> PartialEq for (dyn CacheKey + 'a) {
|
||||
|
@ -98,7 +98,7 @@ impl<'a> Hash for (dyn CacheKey + 'a) {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
#[derive(Eq)]
|
||||
struct CacheKeyValue {
|
||||
text: String,
|
||||
font_size: OrderedFloat<f32>,
|
||||
|
@ -106,15 +106,21 @@ struct CacheKeyValue {
|
|||
}
|
||||
|
||||
impl CacheKey for CacheKeyValue {
|
||||
fn key<'a>(&'a self) -> CacheKeyRef<'a> {
|
||||
fn key(&self) -> CacheKeyRef {
|
||||
CacheKeyRef {
|
||||
text: &self.text.as_str(),
|
||||
text: self.text.as_str(),
|
||||
font_size: self.font_size,
|
||||
runs: self.runs.as_slice(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for CacheKeyValue {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.key().eq(&other.key())
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for CacheKeyValue {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.key().hash(state);
|
||||
|
@ -135,7 +141,7 @@ struct CacheKeyRef<'a> {
|
|||
}
|
||||
|
||||
impl<'a> CacheKey for CacheKeyRef<'a> {
|
||||
fn key<'b>(&'b self) -> CacheKeyRef<'b> {
|
||||
fn key(&self) -> CacheKeyRef {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
@ -242,6 +248,10 @@ impl Line {
|
|||
self.layout.len
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.layout.len == 0
|
||||
}
|
||||
|
||||
pub fn index_for_x(&self, x: f32) -> Option<usize> {
|
||||
if x >= self.layout.width {
|
||||
None
|
||||
|
@ -300,7 +310,7 @@ impl Line {
|
|||
),
|
||||
Underline {
|
||||
color: Some(run_underline.color.unwrap_or(*run_color)),
|
||||
thickness: run_underline.thickness.into(),
|
||||
thickness: run_underline.thickness,
|
||||
squiggly: run_underline.squiggly,
|
||||
},
|
||||
));
|
||||
|
@ -484,7 +494,7 @@ impl LineWrapper {
|
|||
let mut prev_c = '\0';
|
||||
let mut char_indices = line.char_indices();
|
||||
iter::from_fn(move || {
|
||||
while let Some((ix, c)) = char_indices.next() {
|
||||
for (ix, c) in char_indices.by_ref() {
|
||||
if c == '\n' {
|
||||
continue;
|
||||
}
|
||||
|
@ -746,7 +756,7 @@ mod tests {
|
|||
let mut wrapper = LineWrapper::new(font_id, 16., font_system);
|
||||
assert_eq!(
|
||||
wrapper
|
||||
.wrap_shaped_line(&text, &line, 72.0)
|
||||
.wrap_shaped_line(text, &line, 72.0)
|
||||
.collect::<Vec<_>>(),
|
||||
&[
|
||||
ShapedBoundary {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue