Skip to content

Commit

Permalink
Merge pull request #351 from kas-gui/work
Browse files Browse the repository at this point in the history
Update deps; simpler solving of span sizes
  • Loading branch information
dhardy committed Aug 20, 2022
2 parents 963a36b + c7f6d4c commit 20f4a21
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 162 deletions.
10 changes: 3 additions & 7 deletions crates/kas-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ linear-map = "1.2.0"
thiserror = "1.0.23"
serde = { version = "1.0.123", features = ["derive"], optional = true }
serde_json = { version = "1.0.61", optional = true }
serde_yaml = { version = "0.8.16", optional = true }
ron = { version = "0.7.1", package = "ron", optional = true }
serde_yaml = { version = "0.9.9", optional = true }
ron = { version = "0.8.0", package = "ron", optional = true }
num_enum = "0.5.6"

[dependencies.kas-macros]
Expand All @@ -81,15 +81,11 @@ path = "../kas-macros"

[dependencies.kas-text]
version = "0.5.0"
git = "https://github.com/kas-gui/kas-text.git"
rev = "e6278e05761c306b9a3527331445d76745a1a1ca"

[dependencies.easy-cast]
git = "https://github.com/kas-gui/easy-cast.git"
rev = "6bf6084bb78f6bd1e781158016916ef103db0b19"
version = "0.5.0" # used in doc links

[dependencies.winit]
# Provides translations for several winit types
version = "0.26"
version = "0.27"
optional = true
7 changes: 6 additions & 1 deletion crates/kas-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ pub enum Error {

#[cfg(feature = "ron")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "ron")))]
#[error("config (de)serialisation to RON failed")]
#[error("config serialisation to RON failed")]
Ron(#[from] ron::Error),

#[cfg(feature = "ron")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "ron")))]
#[error("config deserialisation from RON failed")]
RonSpanned(#[from] ron::error::SpannedError),

#[error("error reading / writing config file")]
IoError(#[from] std::io::Error),

Expand Down
2 changes: 1 addition & 1 deletion crates/kas-core/src/event/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl WindowConfig {
///
/// Calculates scroll distance from `(horiz, vert)` lines.
pub fn scroll_distance(&self, lines: (f32, f32)) -> Offset {
let x = (self.scroll_dist * -lines.0).cast_nearest();
let x = (self.scroll_dist * lines.0).cast_nearest();
let y = (self.scroll_dist * lines.1).cast_nearest();
Offset(x, y)
}
Expand Down
40 changes: 3 additions & 37 deletions crates/kas-core/src/layout/grid_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,46 +198,12 @@ where
.distribute_stretch_over_by(&mut widths[range.clone()], &scores[range]);
}

// We merge all overlapping spans in arbitrary order.
let (mut i, mut j) = (0, 1);
let mut len = spans.len();
while j < len {
let (first, second) = if spans[i].1 <= spans[j].1 {
(i, j)
} else {
(j, i)
};
let first_end = usize::conv(spans[first].2);
let second_begin = usize::conv(spans[second].1);
if first_end <= second_begin {
j += 1;
if j >= len {
i += 1;
j = i + 1;
}
continue;
}

// Internal margins would be lost; handle those first.
widths[second_begin].include_margins((spans[second].0.margins().0, 0));
widths[first_end - 1].include_margins((0, spans[first].0.margins().1));

let overlap_sum = widths[second_begin..first_end].iter().sum();
spans[first].0.sub_add(overlap_sum, spans[second].0);
debug_assert!(spans[first].1 <= spans[second].1);
spans[first].2 = spans[first].2.max(spans[second].2);

spans.swap(second, len - 1);
len -= 1;
if j >= len {
i += 1;
j = i + 1;
}
}
// Sort spans to apply smallest first
spans.sort_by_key(|span| span.2.saturating_sub(span.1));

// We are left with non-overlapping spans.
// For each span, we ensure cell widths are sufficiently large.
for span in &spans[..len] {
for span in spans {
let rules = span.0;
let begin = usize::conv(span.1);
let end = usize::conv(span.2);
Expand Down
9 changes: 2 additions & 7 deletions crates/kas-core/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,12 @@ pub trait AutoLayout {

/// Set size and position
///
/// The implementation does not assign to `self.core.rect`;
/// [`Layout::set_rect`] should do so before calling this method.
/// This functions identically to [`Layout::set_rect`].
fn set_rect(&mut self, mgr: &mut ConfigMgr, rect: Rect);

/// Translate a coordinate to a [`WidgetId`]
///
/// This method does not test `coord` against `self.rect()` nor does it ever
/// return `self.id()`; it only ever returns a child's [`WidgetId`] or
/// `None`. [`Layout::find_id`] should test against `self.rect()` before
/// calling this method, then return `self.id()` if the result of this
/// method is `None`.
/// This functions identically to [`Layout::find_id`].
fn find_id(&mut self, coord: Coord) -> Option<WidgetId>;

/// Draw a widget and its children
Expand Down
4 changes: 1 addition & 3 deletions crates/kas-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ proc-macro-error = "1.0"
bitflags = "1.3.1"

[dependencies.impl-tools-lib]
version = "0.3.0" # version used in doc links
git = "https://github.com/kas-gui/impl-tools.git"
rev = "fc33ba95d15a56ff376eabcd3c2a852097171914"
version = "0.4.0" # version used in doc links

[dependencies.syn]
version = "1.0.14"
Expand Down
6 changes: 3 additions & 3 deletions crates/kas-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod widget_index;

/// Implement `Default`
///
/// See [`impl_tools::impl_default`](https://docs.rs/impl-tools/0.3/impl_tools/attr.impl_default.html)
/// See [`impl_tools::impl_default`](https://docs.rs/impl-tools/0.4/impl_tools/attr.impl_default.html)
/// for full documentation.
#[proc_macro_attribute]
#[proc_macro_error]
Expand All @@ -52,7 +52,7 @@ pub fn impl_default(attr: TokenStream, item: TokenStream) -> TokenStream {

/// A variant of the standard `derive` macro
///
/// See [`impl_tools::autoimpl`](https://docs.rs/impl-tools/0.3/impl_tools/attr.autoimpl.html)
/// See [`impl_tools::autoimpl`](https://docs.rs/impl-tools/0.4/impl_tools/attr.autoimpl.html)
/// for full documentation.
///
/// The following traits are supported:
Expand Down Expand Up @@ -117,7 +117,7 @@ const IMPL_SCOPE_RULES: [&'static dyn ScopeAttr; 2] = [&AttrImplDefault, &widget

/// Implementation scope
///
/// See [`impl_tools::impl_scope`](https://docs.rs/impl-tools/0.3/impl_tools/macro.impl_scope.html)
/// See [`impl_tools::impl_scope`](https://docs.rs/impl-tools/0.4/impl_tools/macro.impl_scope.html)
/// for full documentation.
#[proc_macro_error]
#[proc_macro]
Expand Down
8 changes: 1 addition & 7 deletions crates/kas-theme/src/dim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,7 @@ impl<D: 'static> ThemeSize for Window<D> {
// NOTE: using different variable-width stretch policies here can
// cause problems (e.g. edit boxes greedily consuming too much
// space). This is a hard layout problem; for now don't do this.
if bound <= limit {
SizeRules::new(bound.min(min), bound, margins, Stretch::Filler)
} else {
SizeRules::new(min, limit, margins, Stretch::Low)
}
SizeRules::new(bound.min(min), bound.min(limit), margins, Stretch::Filler)
} else {
let bound: i32 = text
.measure_width(f32::INFINITY)
Expand All @@ -366,8 +362,6 @@ impl<D: 'static> ThemeSize for Window<D> {
}
} else {
let bound: i32 = text.measure_height().expect("invalid font_id").cast_ceil();
// Reset env since measure_height adjusts vertical alignment:
text.set_env(env);

let line_height = self.dims.dpem.cast_ceil();
let min = bound.max(line_height);
Expand Down
4 changes: 1 addition & 3 deletions crates/kas-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ futures = "0.3"
log = "0.4"
smallvec = "1.6.1"
wgpu = { version = "0.13.0", features = ["spirv"] }
winit = "0.26"
winit = "0.27"
thiserror = "1.0.23"
window_clipboard = { version = "0.2.0", optional = true }
guillotiere = "0.6.0"
Expand All @@ -53,8 +53,6 @@ default-features = false

[dependencies.kas-text]
version = "0.5.0"
git = "https://github.com/kas-gui/kas-text.git"
rev = "e6278e05761c306b9a3527331445d76745a1a1ca"

[build-dependencies]
glob = "0.3"
Loading

0 comments on commit 20f4a21

Please sign in to comment.