summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-19 15:31:29 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-19 15:52:15 +0200
commita6f260ca39f70f82617eca87855789413715f47d (patch)
tree08141ae619bd21e0544d21433bce759aebc7ba83 /src/lib.rs
parentfdab7158c91c52a4ace211c804fdd8e9110f56de (diff)
Refactor layouting a bit
Notably: - Handle aspect ratio in fixed node - Inline constraint inflation into pad node
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d646cf6a..b2d48a2b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -53,7 +53,7 @@ use crate::eval::{Module, Scope, State};
use crate::font::FontStore;
use crate::image::ImageStore;
#[cfg(feature = "layout-cache")]
-use crate::layout::{EvictionStrategy, LayoutCache};
+use crate::layout::{EvictionPolicy, LayoutCache};
use crate::layout::{Frame, LayoutTree};
use crate::loading::Loader;
use crate::source::{SourceId, SourceStore};
@@ -137,12 +137,13 @@ impl Context {
/// A builder for a [`Context`].
///
/// This struct is created by [`Context::builder`].
-#[derive(Default)]
pub struct ContextBuilder {
std: Option<Scope>,
state: Option<State>,
#[cfg(feature = "layout-cache")]
- policy: Option<EvictionStrategy>,
+ policy: EvictionPolicy,
+ #[cfg(feature = "layout-cache")]
+ max_size: usize,
}
impl ContextBuilder {
@@ -161,8 +162,18 @@ impl ContextBuilder {
/// The policy for eviction of the layout cache.
#[cfg(feature = "layout-cache")]
- pub fn policy(mut self, policy: EvictionStrategy) -> Self {
- self.policy = Some(policy);
+ pub fn cache_policy(mut self, policy: EvictionPolicy) -> Self {
+ self.policy = policy;
+ self
+ }
+
+ /// The maximum number of entries the layout cache should have.
+ ///
+ /// Note that this can be exceeded if more entries are categorized as [must
+ /// keep][crate::layout::PatternProperties::must_keep].
+ #[cfg(feature = "layout-cache")]
+ pub fn cache_max_size(mut self, max_size: usize) -> Self {
+ self.max_size = max_size;
self
}
@@ -175,9 +186,22 @@ impl ContextBuilder {
images: ImageStore::new(Rc::clone(&loader)),
loader,
#[cfg(feature = "layout-cache")]
- layouts: LayoutCache::new(self.policy.unwrap_or_default()),
+ layouts: LayoutCache::new(self.policy, self.max_size),
std: self.std.unwrap_or(library::new()),
state: self.state.unwrap_or_default(),
}
}
}
+
+impl Default for ContextBuilder {
+ fn default() -> Self {
+ Self {
+ std: None,
+ state: None,
+ #[cfg(feature = "layout-cache")]
+ policy: EvictionPolicy::default(),
+ #[cfg(feature = "layout-cache")]
+ max_size: 2000,
+ }
+ }
+}