Skip to content

Commit

Permalink
refactoring some code
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Feb 2, 2024
1 parent 4e9325f commit 4ed685c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 47 deletions.
12 changes: 4 additions & 8 deletions sugarloaf/src/components/rich_text/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,11 @@ impl Batch {
}
let has_image = image.is_some();
let has_mask = mask.is_some();
if has_image {
if self.image.is_some() && self.image != image {
return false;
}
if has_image && self.image.is_some() && self.image != image {
return false;
}
if has_mask {
if self.mask.is_some() && self.mask != mask {
return false;
}
if has_mask && self.mask.is_some() && self.mask != mask {
return false;
}
self.subpix = subpix;
let flags = match (has_image, has_mask) {
Expand Down
12 changes: 5 additions & 7 deletions sugarloaf/src/components/rich_text/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,11 @@ impl Compositor {
}
}

if underline {
if entry.top - underline_offset < entry.height as i32 {
if let Some(mut desc_ink) = entry.desc.range() {
desc_ink.0 += gx;
desc_ink.1 += gx;
self.intercepts.push(desc_ink);
}
if underline && entry.top - underline_offset < entry.height as i32 {
if let Some(mut desc_ink) = entry.desc.range() {
desc_ink.0 += gx;
desc_ink.1 += gx;
self.intercepts.push(desc_ink);
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions sugarloaf/src/components/rich_text/image_cache/atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ impl AtlasAllocator {
let slot = *slot;
if let Some(prev) = prev_index {
self.slots[prev as usize].next = slot.next;
} else if slot.next == !0 {
// We're filling the last slot with no previous
// slot. Revert to the offset state.
self.lines[line_index].state = slot_end;
} else {
if slot.next == !0 {
// We're filling the last slot with no previous
// slot. Revert to the offset state.
self.lines[line_index].state = slot_end;
} else {
self.lines[line_index].state = FRAGMENTED_BIT | slot.next;
}
self.lines[line_index].state = FRAGMENTED_BIT | slot.next;
}
self.free_slot(slot_index);
}
Expand Down
3 changes: 2 additions & 1 deletion sugarloaf/src/components/rich_text/image_cache/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use swash::FontRef;

const IS_MACOS: bool = cfg!(target_os = "macos");

const SOURCES: &'static [Source] = &[
const SOURCES: &[Source] = &[
Source::ColorBitmap(StrikeWith::BestFit),
Source::ColorOutline(0),
//Source::Bitmap(Strike::ExactSize),
Expand Down Expand Up @@ -78,6 +78,7 @@ impl GlyphCache {
}
}

#[allow(unused)]
pub fn clear_evicted(&mut self, images: &mut ImageCache) {
self.fonts.retain(|_, entry| {
entry.glyphs.retain(|_, g| images.is_valid(g.image));
Expand Down
12 changes: 4 additions & 8 deletions sugarloaf/src/layout/bidi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,10 @@ impl BidiResolver {
},
is_isolate,
);
} else {
if is_isolate {
overflow_isolates += 1;
} else {
if overflow_isolates == 0 {
overflow_embedding += 1;
}
}
} else if is_isolate {
overflow_isolates += 1;
} else if overflow_isolates == 0 {
overflow_embedding += 1;
}
} else if t == PDI {
if overflow_isolates > 0 {
Expand Down
20 changes: 9 additions & 11 deletions sugarloaf/src/layout/layout_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,17 @@ impl ClusterData {
f32::from_bits(self.glyphs)
} else if self.is_empty() {
0.
} else {
if let Some(glyph) = glyphs.get(self.glyphs as usize) {
if glyph.is_simple() {
glyph.simple_data().1
} else {
detail_glyphs
.get(glyph.detail_index())
.map(|x| x.advance)
.unwrap_or(0.)
}
} else if let Some(glyph) = glyphs.get(self.glyphs as usize) {
if glyph.is_simple() {
glyph.simple_data().1
} else {
0.
detail_glyphs
.get(glyph.detail_index())
.map(|x| x.advance)
.unwrap_or(0.)
}
} else {
0.
}
}

Expand Down
6 changes: 2 additions & 4 deletions sugarloaf/src/layout/nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,8 @@ impl Selection {
}
} else if anchor.line > focus.line || anchor.edge > focus.edge {
// Otherwise, set it to 'after' state.
if !anchor.after {
if anchor.cluster > 0 {
anchor = Node::from_visual_cluster(layout, anchor.cluster - 1, true);
}
if !anchor.after && anchor.cluster > 0 {
anchor = Node::from_visual_cluster(layout, anchor.cluster - 1, true);
}
}
Self {
Expand Down
2 changes: 1 addition & 1 deletion sugarloaf/src/sugarloaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ pub struct SugarloafWindow {

#[derive(PartialEq, Default)]
pub enum SugarloafRendererLevel {
#[default]
Basic,
#[default]
Advanced,
}

Expand Down

0 comments on commit 4ed685c

Please sign in to comment.