Skip to content

Commit

Permalink
Merge pull request #395 from kas-gui/work7
Browse files Browse the repository at this point in the history
Add assoc. type Widget::Data, Events::Data
  • Loading branch information
dhardy authored Jul 27, 2023
2 parents 3ef5445 + d5faf2d commit c9bdd35
Show file tree
Hide file tree
Showing 92 changed files with 2,195 additions and 1,189 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Test kas-wgpu
run: |
cargo test --manifest-path crates/kas-wgpu/Cargo.toml
cargo test --manifest-path crates/kas-wgpu/Cargo.toml --no-default-features --features raster,kas/x11
cargo test --manifest-path crates/kas-wgpu/Cargo.toml --no-default-features --features raster,kas/wayland
cargo test --manifest-path crates/kas-wgpu/Cargo.toml --all-features --features kas/x11
- name: Test kas-dylib
run: |
Expand All @@ -60,16 +60,6 @@ jobs:
cargo test --all-features
- name: Test examples/mandlebrot
run: cargo test --manifest-path examples/mandlebrot/Cargo.toml
- name: Clippy
run: |
cargo clippy --all --features nightly -- \
-A clippy::collapsible-if \
-A clippy::collapsible_else_if \
-A clippy::module-inception \
-A clippy::too-many-arguments \
-A clippy::comparison_chain \
-A clippy::redundant_pattern_matching \
-A clippy::unit_arg

test:
name: Test
Expand Down Expand Up @@ -113,7 +103,7 @@ jobs:
- name: Test examples/mandlebrot
run: cargo test --manifest-path examples/mandlebrot/Cargo.toml
- name: Clippy (stable)
if: matrix.os == 'macos-latest'
if: matrix.toolchain != 'beta' && matrix.toolchain != 'stable'
run: |
cargo clippy --all -- -D warnings \
-A clippy::collapsible-if \
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ cfg_aliases = "0.1.1"
[dependencies]
log = "0.4"
smallvec = "1.6.1"
bitflags = "1.3.1"
bitflags = "2.3.3"
unicode-segmentation = "1.7"
linear-map = "1.2.0"
thiserror = "1.0.23"
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bitflags! {
/// (`toolkit.run()`) or if the widget in question is not part of a UI these
/// values can be ignored.
#[must_use]
#[derive(Default)]
#[derive(Copy, Clone, Default)]
pub struct Action: u32 {
/// No flags
///
Expand Down
6 changes: 0 additions & 6 deletions crates/kas-core/src/core/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ impl Clone for CoreData {
/// A pop-up widget's rect is not contained by its parent, therefore the parent
/// must not call any [`Layout`] methods on the pop-up (whether or not it is
/// visible). The window is responsible for calling these methods.
//
// NOTE: it's tempting to include a pointer to the widget here. There are two
// options: (a) an unsafe aliased pointer or (b) Rc<RefCell<dyn Widget>>.
// Option (a) should work but is an unnecessary performance hack; (b) could in
// theory work but requires adjusting WidgetChildren::get, find etc. to take a
// closure instead of returning a reference, causing *significant* complication.
#[derive(Clone, Debug)]
pub struct Popup {
pub id: WidgetId,
Expand Down
57 changes: 33 additions & 24 deletions crates/kas-core/src/core/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,50 @@

use crate::event::{ConfigMgr, Event, EventMgr, Response};
use crate::util::IdentifyWidget;
use crate::{Erased, Events, Layout, NavAdvance, WidgetChildren, WidgetId};
use crate::{Erased, Events, Layout, NavAdvance, Widget, WidgetId};

/// Generic implementation of [`Widget::_configure`]
pub fn _configure<W: WidgetChildren + Events>(widget: &mut W, cx: &mut ConfigMgr, id: WidgetId) {
pub fn _configure<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
data: &<W as Widget>::Data,
cx: &mut ConfigMgr,
id: WidgetId,
) {
widget.pre_configure(cx, id);

for index in 0..widget.num_children() {
let id = widget.make_child_id(index);
if id.is_valid() {
if let Some(widget) = widget.get_child_mut(index) {
if let Some(mut widget) = widget.get_child_mut(data, index) {
widget._configure(cx, id);
}
}
}

widget.configure(cx);
widget.configure(data, cx);
}

/// Generic implementation of [`Widget::_broadcast`]
pub fn _broadcast<W: WidgetChildren + Events>(
pub fn _broadcast<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
data: &<W as Widget>::Data,
cx: &mut EventMgr,
count: &mut usize,
event: Event,
) {
widget.handle_event(cx, event.clone());
widget.handle_event(data, cx, event.clone());
*count += 1;
for index in 0..widget.num_children() {
if let Some(w) = widget.get_child_mut(index) {
if let Some(mut w) = widget.get_child_mut(data, index) {
w._broadcast(cx, count, event.clone());
}
}
}

/// Generic implementation of [`Widget::_send`]
pub fn _send<W: WidgetChildren + Events>(
pub fn _send<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
data: &<W as Widget>::Data,
cx: &mut EventMgr,
id: WidgetId,
disabled: bool,
Expand All @@ -55,17 +62,17 @@ pub fn _send<W: WidgetChildren + Events>(
return response;
}

response |= widget.pre_handle_event(cx, event);
} else if widget.steal_event(cx, &id, &event).is_used() {
response |= widget.pre_handle_event(data, cx, event);
} else if widget.steal_event(data, cx, &id, &event).is_used() {
response = Response::Used;
} else {
cx.assert_post_steal_unused();
if let Some(index) = widget.find_child_index(&id) {
let translation = widget.translation();
if let Some(w) = widget.get_child_mut(index) {
if let Some(mut w) = widget.get_child_mut(data, index) {
response = w._send(cx, id, disabled, event.clone() + translation);
if let Some(scroll) = cx.post_send(index) {
widget.handle_scroll(cx, scroll);
widget.handle_scroll(data, cx, scroll);
}
} else {
#[cfg(debug_assertions)]
Expand All @@ -77,29 +84,30 @@ pub fn _send<W: WidgetChildren + Events>(
}

if response.is_unused() && event.is_reusable() {
response = widget.handle_event(cx, event);
response = widget.handle_event(data, cx, event);
}
}

if cx.has_msg() {
widget.handle_message(cx);
widget.handle_message(data, cx);
}

response
}

/// Generic implementation of [`Widget::_replay`]
pub fn _replay<W: WidgetChildren + Events>(
pub fn _replay<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
data: &<W as Widget>::Data,
cx: &mut EventMgr,
id: WidgetId,
msg: Erased,
) {
if let Some(index) = widget.find_child_index(&id) {
if let Some(w) = widget.get_child_mut(index) {
if let Some(mut w) = widget.get_child_mut(data, index) {
w._replay(cx, id, msg);
if let Some(scroll) = cx.post_send(index) {
widget.handle_scroll(cx, scroll);
widget.handle_scroll(data, cx, scroll);
}
} else {
#[cfg(debug_assertions)]
Expand All @@ -110,11 +118,11 @@ pub fn _replay<W: WidgetChildren + Events>(
}

if cx.has_msg() {
widget.handle_message(cx);
widget.handle_message(data, cx);
}
} else if id == widget.id_ref() {
cx.push_erased(msg);
widget.handle_message(cx);
widget.handle_message(data, cx);
} else {
#[cfg(debug_assertions)]
log::debug!(
Expand All @@ -125,8 +133,9 @@ pub fn _replay<W: WidgetChildren + Events>(
}

/// Generic implementation of [`Widget::_nav_next`]
pub fn _nav_next<W: WidgetChildren + Events>(
pub fn _nav_next<W: Widget + Events<Data = <W as Widget>::Data>>(
widget: &mut W,
data: &<W as Widget>::Data,
cx: &mut EventMgr,
focus: Option<&WidgetId>,
advance: NavAdvance,
Expand All @@ -139,8 +148,8 @@ pub fn _nav_next<W: WidgetChildren + Events>(

if let Some(index) = child {
if let Some(id) = widget
.get_child_mut(index)
.and_then(|w| w._nav_next(cx, focus, advance))
.get_child_mut(data, index)
.and_then(|mut w| w._nav_next(cx, focus, advance))
{
return Some(id);
}
Expand All @@ -166,8 +175,8 @@ pub fn _nav_next<W: WidgetChildren + Events>(

while let Some(index) = widget.nav_next(rev, child) {
if let Some(id) = widget
.get_child_mut(index)
.and_then(|w| w._nav_next(cx, focus, advance))
.get_child_mut(data, index)
.and_then(|mut w| w._nav_next(cx, focus, advance))
{
return Some(id);
}
Expand Down
2 changes: 2 additions & 0 deletions crates/kas-core/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! Core widget types

mod data;
mod node;
mod scroll_traits;
mod widget;
mod widget_id;
Expand All @@ -15,6 +16,7 @@ mod widget_id;
pub mod impls;

pub use data::*;
pub use node::{Node, NodeMut};
pub use scroll_traits::*;
pub use widget::*;
pub use widget_id::*;
Loading

0 comments on commit c9bdd35

Please sign in to comment.