Skip to content

Commit 6a58864

Browse files
committed
merge: root master
2 parents a44b648 + 0f2b427 commit 6a58864

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

crates/egui-wgpu/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ default = ["fragile-send-sync-non-atomic-wasm"]
3737
puffin = ["dep:puffin"]
3838

3939
## Enable [`winit`](https://docs.rs/winit) integration. On Linux, requires either `wayland` or `x11`
40-
winit = ["dep:winit"]
40+
winit = ["dep:winit", "winit/rwh_06"]
4141

4242
## Enables Wayland support for winit.
4343
wayland = ["winit?/wayland"]

crates/egui/src/containers/scroll_area.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -621,20 +621,28 @@ impl ScrollArea {
621621
.interact_rect
622622
.map(|rect| ui.interact(rect, id.with("area"), Sense::drag()));
623623

624-
if content_response_option.map(|response| response.dragged()) == Some(true) {
624+
if content_response_option
625+
.as_ref()
626+
.is_some_and(|response| response.dragged())
627+
{
625628
for d in 0..2 {
626629
if scroll_enabled[d] {
627630
ui.input(|input| {
628631
state.offset[d] -= input.pointer.delta()[d];
629-
state.vel[d] = input.pointer.velocity()[d];
630632
});
631633
state.scroll_stuck_to_end[d] = false;
632634
state.offset_target[d] = None;
633-
} else {
634-
state.vel[d] = 0.0;
635635
}
636636
}
637637
} else {
638+
// Apply the cursor velocity to the scroll area when the user releases the drag.
639+
if content_response_option
640+
.as_ref()
641+
.is_some_and(|response| response.drag_stopped())
642+
{
643+
state.vel =
644+
scroll_enabled.to_vec2() * ui.input(|input| input.pointer.velocity());
645+
}
638646
for d in 0..2 {
639647
// Kinetic scrolling
640648
let stop_speed = 20.0; // Pixels per second.

crates/egui/src/widgets/text_edit/builder.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use super::{TextEditOutput, TextEditState};
5959
/// See [`TextEdit::show`].
6060
///
6161
/// ## Other
62-
/// The background color of a [`crate::TextEdit`] is [`crate::Visuals::extreme_bg_color`].
62+
/// The background color of a [`crate::TextEdit`] is [`crate::Visuals::extreme_bg_color`] or can be set with [`crate::TextEdit::background_color`].
6363
#[must_use = "You should put this widget in a ui with `ui.add(widget);`"]
6464
pub struct TextEdit<'t> {
6565
text: &'t mut dyn TextBuffer,
@@ -84,6 +84,7 @@ pub struct TextEdit<'t> {
8484
clip_text: bool,
8585
char_limit: usize,
8686
return_key: Option<KeyboardShortcut>,
87+
background_color: Option<Color32>,
8788
}
8889

8990
impl<'t> WidgetWithState for TextEdit<'t> {
@@ -142,6 +143,7 @@ impl<'t> TextEdit<'t> {
142143
clip_text: false,
143144
char_limit: usize::MAX,
144145
return_key: Some(KeyboardShortcut::new(Modifiers::NONE, Key::Enter)),
146+
background_color: None,
145147
}
146148
}
147149

@@ -201,6 +203,14 @@ impl<'t> TextEdit<'t> {
201203
self
202204
}
203205

206+
/// Set the background color of the [`TextEdit`]. The default is [`crate::Visuals::extreme_bg_color`].
207+
// TODO(bircni): remove this once #3284 is implemented
208+
#[inline]
209+
pub fn background_color(mut self, color: Color32) -> Self {
210+
self.background_color = Some(color);
211+
self
212+
}
213+
204214
/// Set a specific style for the hint text.
205215
#[inline]
206216
pub fn hint_text_font(mut self, hint_text_font: impl Into<FontSelection>) -> Self {
@@ -409,7 +419,9 @@ impl<'t> TextEdit<'t> {
409419
let is_mutable = self.text.is_mutable();
410420
let frame = self.frame;
411421
let where_to_put_background = ui.painter().add(Shape::Noop);
412-
422+
let background_color = self
423+
.background_color
424+
.unwrap_or(ui.visuals().extreme_bg_color);
413425
let margin = self.margin;
414426
let mut output = self.show_content(ui);
415427

@@ -427,14 +439,14 @@ impl<'t> TextEdit<'t> {
427439
epaint::RectShape::new(
428440
frame_rect,
429441
visuals.rounding,
430-
ui.visuals().extreme_bg_color,
442+
background_color,
431443
ui.visuals().selection.stroke,
432444
)
433445
} else {
434446
epaint::RectShape::new(
435447
frame_rect,
436448
visuals.rounding,
437-
ui.visuals().extreme_bg_color,
449+
background_color,
438450
visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
439451
)
440452
}
@@ -477,6 +489,7 @@ impl<'t> TextEdit<'t> {
477489
clip_text,
478490
char_limit,
479491
return_key,
492+
background_color: _,
480493
} = self;
481494

482495
let text_color = text_color

crates/emath/src/vec2b.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::Vec2;
2+
13
/// Two bools, one for each axis (X and Y).
24
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
35
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
@@ -43,6 +45,12 @@ impl Vec2b {
4345
y: self.y || other.y,
4446
}
4547
}
48+
49+
/// Convert to a float `Vec2` where the components are 1.0 for `true` and 0.0 for `false`.
50+
#[inline]
51+
pub fn to_vec2(self) -> Vec2 {
52+
Vec2::new(self.x.into(), self.y.into())
53+
}
4654
}
4755

4856
impl From<bool> for Vec2b {

examples/hello_world_simple/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Example showing some UI controls like `Label`, `TextEdit`, `Slider`, `Button`.
22

33
```sh
4-
cargo run -p hello_world
4+
cargo run -p hello_world_simple
55
```
66

77
![](screenshot.png)

0 commit comments

Comments
 (0)