[input] widgets must say if they are interested in click or drags

This commit is contained in:
Emil Ernerfeldt
2020-05-23 12:38:52 +02:00
parent 4bea65595c
commit 5c966bdc76
14 changed files with 170 additions and 114 deletions
+2 -1
View File
@@ -163,7 +163,8 @@ impl Prepared {
} else {
None
};
let move_interact = ctx.interact(layer, clip_rect, rect, interact_id);
let move_interact =
ctx.interact(layer, clip_rect, rect, interact_id, Sense::click_and_drag());
let input = ctx.input();
if move_interact.active {
+8 -8
View File
@@ -96,7 +96,7 @@ impl State {
&mut self,
ui: &mut Ui,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> Option<(R, InteractInfo)> {
) -> Option<(R, Rect)> {
let openness = self.openness(ui);
let animate = 0.0 < openness && openness < 1.0;
if animate {
@@ -132,7 +132,7 @@ impl State {
}))
} else if self.open {
let r_interact = ui.add_custom(add_contents);
let full_size = r_interact.1.rect.size();
let full_size = r_interact.1.size();
self.open_height = Some(full_size.y);
Some(r_interact)
} else {
@@ -190,13 +190,13 @@ impl CollapsingHeader {
let desired_width = text_max_x - available.left();
let desired_width = desired_width.max(available.width());
let interact = ui.reserve_space(
vec2(
desired_width,
galley.size.y + 2.0 * ui.style().button_padding.y,
),
Some(id),
let size = vec2(
desired_width,
galley.size.y + 2.0 * ui.style().button_padding.y,
);
let rect = ui.allocate_space(size);
let interact = ui.interact(rect, id, Sense::click());
let text_pos = pos2(text_pos.x, interact.rect.center().y - galley.size.y / 2.0);
let mut state = State::from_memory_with_default_open(ui, id, default_open);
+1 -1
View File
@@ -20,7 +20,7 @@ impl Default for BarState {
}
}
pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, InteractInfo) {
pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
ui.inner_layout(Layout::horizontal(Align::Center), |ui| {
Frame::menu_bar(ui.style()).show(ui, |ui| {
let mut style = ui.style().clone();
+2 -2
View File
@@ -209,7 +209,7 @@ impl Resize {
position + state.size + self.handle_offset - corner_size,
corner_size,
);
let corner_interact = ui.interact_rect(corner_rect, id.with("corner"));
let corner_interact = ui.interact(corner_rect, id.with("corner"), Sense::drag());
if corner_interact.active {
if let Some(mouse_pos) = ui.input().mouse.pos {
@@ -304,7 +304,7 @@ impl Resize {
// state.size = state.size.clamp(self.min_size..=self.max_size);
state.size = state.size.round(); // TODO: round to pixels
ui.reserve_space(state.size, None);
ui.allocate_space(state.size);
// ------------------------------
+6 -5
View File
@@ -146,8 +146,8 @@ impl Prepared {
let content_is_too_small = content_size.y > inner_rect.height();
if content_is_too_small {
// Dragg contents to scroll (for touch screens mostly):
let content_interact = ui.interact_rect(inner_rect, id.with("area"));
// Drag contents to scroll (for touch screens mostly):
let content_interact = ui.interact(inner_rect, id.with("area"), Sense::drag());
if content_interact.active {
state.offset.y -= ui.input().mouse.delta.y;
}
@@ -181,7 +181,7 @@ impl Prepared {
// intentionally use same id for inside and outside of handle
let interact_id = id.with("vertical");
let handle_interact = ui.interact_rect(handle_rect, interact_id);
let handle_interact = ui.interact(handle_rect, interact_id, Sense::click_and_drag());
if let Some(mouse_pos) = ui.input().mouse.pos {
if handle_interact.active {
@@ -191,7 +191,8 @@ impl Prepared {
}
} else {
// Check for mouse down outside handle:
let scroll_bg_interact = ui.interact_rect(outer_scroll_rect, interact_id);
let scroll_bg_interact =
ui.interact(outer_scroll_rect, interact_id, Sense::click_and_drag());
if scroll_bg_interact.active {
// Center scroll at mouse pos:
@@ -235,7 +236,7 @@ impl Prepared {
// content_size.y.min(inner_rect.size().y), // respect vertical height.
// );
let size = outer_rect.size();
ui.reserve_space(size, None);
ui.allocate_space(size);
state.offset.y = state.offset.y.min(content_size.y - inner_rect.height());
state.offset.y = state.offset.y.max(0.0);
+8 -8
View File
@@ -529,10 +529,10 @@ fn show_title_bar(
{
// TODO: make clickable radius larger
ui.reserve_space(vec2(0.0, 0.0), None); // HACK: will add left spacing
ui.allocate_space(vec2(0.0, 0.0)); // HACK: will add left spacing
let collapse_button_interact =
ui.reserve_space(Vec2::splat(button_size), Some(collapsing_id));
let rect = ui.allocate_space(Vec2::splat(button_size));
let collapse_button_interact = ui.interact(rect, collapsing_id, Sense::click());
if collapse_button_interact.clicked {
// TODO: also do this when double-clicking window title
collapsing.toggle(ui);
@@ -541,7 +541,7 @@ fn show_title_bar(
}
let title_galley = title_label.layout(ui);
let title_rect = ui.reserve_space(title_galley.size, None).rect;
let title_rect = ui.allocate_space(title_galley.size);
if show_close_button {
// Reserve space for close button which will be added later:
@@ -566,7 +566,7 @@ fn show_title_bar(
});
TitleBar {
rect: tb_interact.1.rect,
rect: tb_interact.1,
..tb_interact.0
}
}
@@ -577,8 +577,8 @@ impl TitleBar {
.paint_galley(ui, self.title_rect.min, self.title_galley);
}
pub fn close_button_ui(&self, ui: &mut Ui, content: &Option<InteractInfo>) -> InteractInfo {
let right = content.map(|c| c.rect.right()).unwrap_or(self.rect.right());
pub fn close_button_ui(&self, ui: &mut Ui, content: &Option<Rect>) -> InteractInfo {
let right = content.map(|c| c.right()).unwrap_or(self.rect.right());
let button_size = ui.style().start_icon_width;
let button_rect = Rect::from_min_size(
@@ -595,7 +595,7 @@ impl TitleBar {
fn close_button(ui: &mut Ui, rect: Rect) -> InteractInfo {
let close_id = ui.make_child_id("window_close_button");
let interact = ui.interact_rect(rect, close_id);
let interact = ui.interact(rect, close_id, Sense::click());
ui.expand_to_include_child(interact.rect);
let stroke_color = ui.style().interact(&interact).stroke_color;