Skip to content

Commit

Permalink
Support for font scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
salihgerdan committed Mar 10, 2023
1 parent affd6b0 commit bff6eb7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/gui/treemap_widget/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,17 @@ impl WidgetImpl for TreeMapWidget {

let rect = Rect::new(0.0, 0.0, w, h);
let root = tree.get_elem(0);

let text_offset =
pango::units_to_double(*&obj.pango_context().font_description().unwrap().size())
as f32;
dbg!(text_offset);
if invalidate {
self.gui_node_map
.replace(squarify::compute_gui_nodes(&tree, root, rect));
self.gui_node_map.replace(squarify::compute_gui_nodes(
&tree,
root,
rect,
text_offset,
));
self.invalidate_gui_nodes_flag.replace(false);
}
update_rects(
Expand Down
17 changes: 12 additions & 5 deletions src/squarify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::collections::HashMap;

const MAX_FS_DEPTH: usize = 16;
const MIN_BOX_SIZE: f32 = 20.0;
const TEXT_OFFSET: f32 = 13.0;
const PAD: f32 = 1.0;

#[derive(Debug)]
Expand All @@ -15,8 +14,13 @@ pub struct GUINode {
}

// wrapper function
pub fn compute_gui_nodes(tree: &Tree, root: &Node, bound: Rect) -> HashMap<NodeID, GUINode> {
let vec_gui_nodes = compute_gui_nodes_imp(tree, vec![root], bound, 0);
pub fn compute_gui_nodes(
tree: &Tree,
root: &Node,
bound: Rect,
text_offset: f32,
) -> HashMap<NodeID, GUINode> {
let vec_gui_nodes = compute_gui_nodes_imp(tree, vec![root], bound, 0, text_offset);
let mut hmap: HashMap<NodeID, GUINode> = HashMap::with_capacity(vec_gui_nodes.len());
for gui_node in vec_gui_nodes {
hmap.insert(gui_node.node_id, gui_node);
Expand All @@ -29,6 +33,7 @@ fn compute_gui_nodes_imp(
nodes: Vec<&Node>,
mut bound: Rect,
dir_level: usize,
text_offset: f32,
) -> Vec<GUINode> {
if dir_level > MAX_FS_DEPTH
|| bound.width() < MIN_BOX_SIZE
Expand Down Expand Up @@ -59,9 +64,9 @@ fn compute_gui_nodes_imp(
// add padding for directory
bound = Rect::new(
bound.x() + 3.0,
bound.y() + TEXT_OFFSET,
bound.y() + text_offset,
bound.width() - 6.0,
bound.height() - TEXT_OFFSET - 3.0,
bound.height() - text_offset - 3.0,
);
}
};
Expand All @@ -88,12 +93,14 @@ fn compute_gui_nodes_imp(
group_a,
bound_a,
dir_level + subdir_level,
text_offset,
));
gui_nodes.extend(compute_gui_nodes_imp(
tree,
group_b,
bound_b,
dir_level + subdir_level,
text_offset,
));
}

Expand Down

0 comments on commit bff6eb7

Please sign in to comment.