mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Replace ui.ctx().foo with ui.foo in a few places (#7774)
Internal code cleanup after * https://github.com/emilk/egui/pull/7770
This commit is contained in:
@@ -69,7 +69,7 @@ impl CollapsingState {
|
|||||||
|
|
||||||
pub fn toggle(&mut self, ui: &Ui) {
|
pub fn toggle(&mut self, ui: &Ui) {
|
||||||
self.state.open = !self.state.open;
|
self.state.open = !self.state.open;
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 0 for closed, 1 for open, with tweening
|
/// 0 for closed, 1 for open, with tweening
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ impl MenuState {
|
|||||||
/// egui::MenuBar::new().ui(ui, |ui| {
|
/// egui::MenuBar::new().ui(ui, |ui| {
|
||||||
/// ui.menu_button("File", |ui| {
|
/// ui.menu_button("File", |ui| {
|
||||||
/// if ui.button("Quit").clicked() {
|
/// if ui.button("Quit").clicked() {
|
||||||
/// ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
/// ui.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
/// }
|
/// }
|
||||||
/// });
|
/// });
|
||||||
/// });
|
/// });
|
||||||
@@ -556,7 +556,7 @@ impl SubMenu {
|
|||||||
if is_moving_towards_rect {
|
if is_moving_towards_rect {
|
||||||
// We need to repaint while this is true, so we can detect when
|
// We need to repaint while this is true, so we can detect when
|
||||||
// the pointer is no longer moving towards the rect
|
// the pointer is no longer moving towards the rect
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
let hovering_other_menu_entry = is_open
|
let hovering_other_menu_entry = is_open
|
||||||
&& !is_hovered
|
&& !is_hovered
|
||||||
|
|||||||
@@ -713,7 +713,7 @@ impl Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resize_hover || is_resizing {
|
if resize_hover || is_resizing {
|
||||||
ui.ctx().set_cursor_icon(self.cursor_icon(&panel_sizer));
|
ui.set_cursor_icon(self.cursor_icon(&panel_sizer));
|
||||||
}
|
}
|
||||||
|
|
||||||
PanelState { rect }.store(ui.ctx(), id);
|
PanelState { rect }.store(ui.ctx(), id);
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ impl Resize {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let mut state = State::load(ui.ctx(), id).unwrap_or_else(|| {
|
let mut state = State::load(ui.ctx(), id).unwrap_or_else(|| {
|
||||||
ui.ctx().request_repaint(); // counter frame delay
|
ui.request_repaint(); // counter frame delay
|
||||||
|
|
||||||
let default_size = self
|
let default_size = self
|
||||||
.default_size
|
.default_size
|
||||||
@@ -362,7 +362,7 @@ impl Resize {
|
|||||||
paint_resize_corner(ui, &corner_response);
|
paint_resize_corner(ui, &corner_response);
|
||||||
|
|
||||||
if corner_response.hovered() || corner_response.dragged() {
|
if corner_response.hovered() || corner_response.dragged() {
|
||||||
ui.ctx().set_cursor_icon(CursorIcon::ResizeNwSe);
|
ui.set_cursor_icon(CursorIcon::ResizeNwSe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,12 +370,12 @@ impl Resize {
|
|||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
if ui.global_style().debug.show_resize {
|
if ui.global_style().debug.show_resize {
|
||||||
ui.ctx().debug_painter().debug_rect(
|
ui.debug_painter().debug_rect(
|
||||||
Rect::from_min_size(content_ui.min_rect().left_top(), state.desired_size),
|
Rect::from_min_size(content_ui.min_rect().left_top(), state.desired_size),
|
||||||
Color32::GREEN,
|
Color32::GREEN,
|
||||||
"desired_size",
|
"desired_size",
|
||||||
);
|
);
|
||||||
ui.ctx().debug_painter().debug_rect(
|
ui.debug_painter().debug_rect(
|
||||||
Rect::from_min_size(content_ui.min_rect().left_top(), state.last_content_size),
|
Rect::from_min_size(content_ui.min_rect().left_top(), state.last_content_size),
|
||||||
Color32::LIGHT_BLUE,
|
Color32::LIGHT_BLUE,
|
||||||
"last_content_size",
|
"last_content_size",
|
||||||
|
|||||||
@@ -244,8 +244,8 @@ impl Scene {
|
|||||||
&& resp.contains_pointer()
|
&& resp.contains_pointer()
|
||||||
{
|
{
|
||||||
let pointer_in_scene = to_global.inverse() * mouse_pos;
|
let pointer_in_scene = to_global.inverse() * mouse_pos;
|
||||||
let zoom_delta = ui.ctx().input(|i| i.zoom_delta());
|
let zoom_delta = ui.input(|i| i.zoom_delta());
|
||||||
let pan_delta = ui.ctx().input(|i| i.smooth_scroll_delta());
|
let pan_delta = ui.input(|i| i.smooth_scroll_delta());
|
||||||
|
|
||||||
// Most of the time we can return early. This is also important to
|
// Most of the time we can return early. This is also important to
|
||||||
// avoid `ui_from_scene` to change slightly due to floating point errors.
|
// avoid `ui_from_scene` to change slightly due to floating point errors.
|
||||||
|
|||||||
@@ -856,11 +856,11 @@ impl ScrollArea {
|
|||||||
if response.dragged()
|
if response.dragged()
|
||||||
&& let Some(cursor) = on_drag_cursor
|
&& let Some(cursor) = on_drag_cursor
|
||||||
{
|
{
|
||||||
ui.ctx().set_cursor_icon(cursor);
|
ui.set_cursor_icon(cursor);
|
||||||
} else if response.hovered()
|
} else if response.hovered()
|
||||||
&& let Some(cursor) = on_hover_cursor
|
&& let Some(cursor) = on_hover_cursor
|
||||||
{
|
{
|
||||||
ui.ctx().set_cursor_icon(cursor);
|
ui.set_cursor_icon(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1125,7 +1125,7 @@ impl Prepared {
|
|||||||
target_offset,
|
target_offset,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1178,7 +1178,7 @@ impl Prepared {
|
|||||||
&& direction_enabled[0] != direction_enabled[1];
|
&& direction_enabled[0] != direction_enabled[1];
|
||||||
for d in 0..2 {
|
for d in 0..2 {
|
||||||
if direction_enabled[d] {
|
if direction_enabled[d] {
|
||||||
let scroll_delta = ui.ctx().input(|input| {
|
let scroll_delta = ui.input(|input| {
|
||||||
if always_scroll_enabled_direction {
|
if always_scroll_enabled_direction {
|
||||||
// no bidirectional scrolling; allow horizontal scrolling without pressing shift
|
// no bidirectional scrolling; allow horizontal scrolling without pressing shift
|
||||||
input.smooth_scroll_delta()[0] + input.smooth_scroll_delta()[1]
|
input.smooth_scroll_delta()[0] + input.smooth_scroll_delta()[1]
|
||||||
@@ -1195,7 +1195,7 @@ impl Prepared {
|
|||||||
state.offset[d] -= scroll_delta;
|
state.offset[d] -= scroll_delta;
|
||||||
|
|
||||||
// Clear scroll delta so no parent scroll will use it:
|
// Clear scroll delta so no parent scroll will use it:
|
||||||
ui.ctx().input_mut(|input| {
|
ui.input_mut(|input| {
|
||||||
if always_scroll_enabled_direction {
|
if always_scroll_enabled_direction {
|
||||||
input.smooth_scroll_delta()[0] = 0.0;
|
input.smooth_scroll_delta()[0] = 0.0;
|
||||||
input.smooth_scroll_delta()[1] = 0.0;
|
input.smooth_scroll_delta()[1] = 0.0;
|
||||||
@@ -1475,7 +1475,7 @@ impl Prepared {
|
|||||||
ui.advance_cursor_after_rect(outer_rect);
|
ui.advance_cursor_after_rect(outer_rect);
|
||||||
|
|
||||||
if show_scroll_this_frame != state.show_scroll {
|
if show_scroll_this_frame != state.show_scroll {
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
let available_offset = content_size - inner_rect.size();
|
let available_offset = content_size - inner_rect.size();
|
||||||
|
|||||||
@@ -1143,8 +1143,7 @@ impl TitleBar {
|
|||||||
title_bar_height_with_margin: f32,
|
title_bar_height_with_margin: f32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
if false {
|
if false {
|
||||||
ui.ctx()
|
ui.debug_painter()
|
||||||
.debug_painter()
|
|
||||||
.debug_rect(ui.min_rect(), Color32::GREEN, "outer_min_rect");
|
.debug_rect(ui.min_rect(), Color32::GREEN, "outer_min_rect");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1172,8 +1171,7 @@ impl TitleBar {
|
|||||||
let min_rect = Rect::from_min_size(ui.min_rect().min, min_inner_size);
|
let min_rect = Rect::from_min_size(ui.min_rect().min, min_inner_size);
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
ui.ctx()
|
ui.debug_painter()
|
||||||
.debug_painter()
|
|
||||||
.debug_rect(min_rect, Color32::LIGHT_BLUE, "min_rect");
|
.debug_rect(min_rect, Color32::LIGHT_BLUE, "min_rect");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1210,8 +1208,7 @@ impl TitleBar {
|
|||||||
let title_inner_rect = self.inner_rect;
|
let title_inner_rect = self.inner_rect;
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
ui.ctx()
|
ui.debug_painter()
|
||||||
.debug_painter()
|
|
||||||
.debug_rect(self.inner_rect, Color32::RED, "TitleBar");
|
.debug_rect(self.inner_rect, Color32::RED, "TitleBar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1250,8 +1247,7 @@ impl TitleBar {
|
|||||||
// Paint separator between title and content:
|
// Paint separator between title and content:
|
||||||
let content_rect = content_response.rect;
|
let content_rect = content_response.rect;
|
||||||
if false {
|
if false {
|
||||||
ui.ctx()
|
ui.debug_painter()
|
||||||
.debug_painter()
|
|
||||||
.debug_rect(content_rect, Color32::RED, "content_rect");
|
.debug_rect(content_rect, Color32::RED, "content_rect");
|
||||||
}
|
}
|
||||||
let y = title_inner_rect.bottom() + window_frame.stroke.width / 2.0;
|
let y = title_inner_rect.bottom() + window_frame.stroke.width / 2.0;
|
||||||
@@ -1265,11 +1261,8 @@ impl TitleBar {
|
|||||||
let double_click_rect = title_inner_rect.shrink2(vec2(32.0, 0.0));
|
let double_click_rect = title_inner_rect.shrink2(vec2(32.0, 0.0));
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
ui.ctx().debug_painter().debug_rect(
|
ui.debug_painter()
|
||||||
double_click_rect,
|
.debug_rect(double_click_rect, Color32::GREEN, "double_click_rect");
|
||||||
Color32::GREEN,
|
|
||||||
"double_click_rect",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = ui.unique_id().with("__window_title_bar");
|
let id = ui.unique_id().with("__window_title_bar");
|
||||||
|
|||||||
@@ -1505,7 +1505,7 @@ impl Context {
|
|||||||
Painter::new(self.clone(), layer_id, content_rect)
|
Painter::new(self.clone(), layer_id, content_rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Paint on top of everything else
|
/// Paint on top of _everything_ else (even on top of tooltips and popups).
|
||||||
pub fn debug_painter(&self) -> Painter {
|
pub fn debug_painter(&self) -> Painter {
|
||||||
Self::layer_painter(self, LayerId::debug())
|
Self::layer_painter(self, LayerId::debug())
|
||||||
}
|
}
|
||||||
@@ -3554,9 +3554,7 @@ impl Context {
|
|||||||
let response =
|
let response =
|
||||||
ui.add(Label::new(RichText::new(text).monospace()).sense(Sense::click()));
|
ui.add(Label::new(RichText::new(text).monospace()).sense(Sense::click()));
|
||||||
if response.hovered() && is_visible {
|
if response.hovered() && is_visible {
|
||||||
ui.ctx()
|
ui.debug_painter().debug_rect(area.rect(), Color32::RED, "");
|
||||||
.debug_painter()
|
|
||||||
.debug_rect(area.rect(), Color32::RED, "");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ui.monospace(layer_id.short_debug_format());
|
ui.monospace(layer_id.short_debug_format());
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ impl Grid {
|
|||||||
|
|
||||||
if ui.is_visible() {
|
if ui.is_visible() {
|
||||||
// Try to cover up the glitchy initial frame:
|
// Try to cover up the glitchy initial frame:
|
||||||
ui.ctx().request_discard("new Grid");
|
ui.request_discard("new Grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide the ui this frame, and make things as narrow as possible:
|
// Hide the ui this frame, and make things as narrow as possible:
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ impl ThemePreference {
|
|||||||
/// Show radio-buttons to switch between light mode, dark mode and following the system theme.
|
/// Show radio-buttons to switch between light mode, dark mode and following the system theme.
|
||||||
pub fn radio_buttons(&mut self, ui: &mut crate::Ui) {
|
pub fn radio_buttons(&mut self, ui: &mut crate::Ui) {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let system_theme = ui.ctx().input(|i| i.raw.system_theme);
|
let system_theme = ui.input(|i| i.raw.system_theme);
|
||||||
|
|
||||||
ui.selectable_value(self, Self::System, "💻 System")
|
ui.selectable_value(self, Self::System, "💻 System")
|
||||||
.on_hover_ui(|ui| {
|
.on_hover_ui(|ui| {
|
||||||
|
|||||||
@@ -701,7 +701,7 @@ impl MenuState {
|
|||||||
if self.moving_towards_current_submenu(&pointer) {
|
if self.moving_towards_current_submenu(&pointer) {
|
||||||
// We don't close the submenu if the pointer is on its way to hover it.
|
// We don't close the submenu if the pointer is on its way to hover it.
|
||||||
// ensure to repaint once even when pointer is not moving
|
// ensure to repaint once even when pointer is not moving
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
} else if !open && button.hovered() {
|
} else if !open && button.hovered() {
|
||||||
// TODO(emilk): open menu to the left if there isn't enough space to the right
|
// TODO(emilk): open menu to the left if there isn't enough space to the right
|
||||||
let mut pos = button.rect.right_top();
|
let mut pos = button.rect.right_top();
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ impl LabelSelectionState {
|
|||||||
let global_from_galley = global_from_layer * layer_from_galley;
|
let global_from_galley = global_from_layer * layer_from_galley;
|
||||||
|
|
||||||
if response.hovered() {
|
if response.hovered() {
|
||||||
ui.ctx().set_cursor_icon(CursorIcon::Text);
|
ui.set_cursor_icon(CursorIcon::Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.any_hovered |= response.hovered();
|
self.any_hovered |= response.hovered();
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ pub fn paint_text_cursor(
|
|||||||
total_duration - time_in_cycle
|
total_duration - time_in_cycle
|
||||||
};
|
};
|
||||||
|
|
||||||
ui.ctx().request_repaint_after_secs(wake_in);
|
ui.request_repaint_after_secs(wake_in);
|
||||||
} else {
|
} else {
|
||||||
paint_cursor_end(painter, ui.visuals(), primary_cursor_rect);
|
paint_cursor_end(painter, ui.visuals(), primary_cursor_rect);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3207,7 +3207,7 @@ fn register_rect(ui: &Ui, rect: Rect) {
|
|||||||
|
|
||||||
// Use the debug-painter to avoid clip rect,
|
// Use the debug-painter to avoid clip rect,
|
||||||
// otherwise the content of the widget may cover what we paint here!
|
// otherwise the content of the widget may cover what we paint here!
|
||||||
let painter = ui.ctx().debug_painter();
|
let painter = ui.debug_painter();
|
||||||
|
|
||||||
if debug.hover_shows_next {
|
if debug.hover_shows_next {
|
||||||
ui.placer.debug_paint_cursor(&painter, "next");
|
ui.placer.debug_paint_cursor(&painter, "next");
|
||||||
|
|||||||
@@ -402,9 +402,9 @@ fn srgba_edit_ui(ui: &mut Ui, [r, g, b, a]: &mut [u8; 4], alpha: Alpha) -> bool
|
|||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
if alpha == Alpha::Opaque {
|
if alpha == Alpha::Opaque {
|
||||||
ui.ctx().copy_text(format!("{r}, {g}, {b}"));
|
ui.copy_text(format!("{r}, {g}, {b}"));
|
||||||
} else {
|
} else {
|
||||||
ui.ctx().copy_text(format!("{r}, {g}, {b}, {a}"));
|
ui.copy_text(format!("{r}, {g}, {b}, {a}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
edited |= DragValue::new(r).speed(0.5).prefix("R ").ui(ui).changed();
|
edited |= DragValue::new(r).speed(0.5).prefix("R ").ui(ui).changed();
|
||||||
@@ -443,10 +443,9 @@ fn rgba_edit_ui(ui: &mut Ui, [r, g, b, a]: &mut [f32; 4], alpha: Alpha) -> bool
|
|||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
if alpha == Alpha::Opaque {
|
if alpha == Alpha::Opaque {
|
||||||
ui.ctx().copy_text(format!("{r:.03}, {g:.03}, {b:.03}"));
|
ui.copy_text(format!("{r:.03}, {g:.03}, {b:.03}"));
|
||||||
} else {
|
} else {
|
||||||
ui.ctx()
|
ui.copy_text(format!("{r:.03}, {g:.03}, {b:.03}, {a:.03}"));
|
||||||
.copy_text(format!("{r:.03}, {g:.03}, {b:.03}, {a:.03}"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -624,7 +624,7 @@ impl Widget for DragValue<'_> {
|
|||||||
ui.memory_mut(|mem| mem.request_focus(id));
|
ui.memory_mut(|mem| mem.request_focus(id));
|
||||||
select_all_text(ui, id, response.id, &value_text);
|
select_all_text(ui, id, response.id, &value_text);
|
||||||
} else if response.dragged() {
|
} else if response.dragged() {
|
||||||
ui.ctx().set_cursor_icon(cursor_icon);
|
ui.set_cursor_icon(cursor_icon);
|
||||||
|
|
||||||
let mdelta = response.drag_delta();
|
let mdelta = response.drag_delta();
|
||||||
let delta_points = mdelta.x - mdelta.y; // Increase to the right and up
|
let delta_points = mdelta.x - mdelta.y; // Increase to the right and up
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ impl Widget for Link {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response.hovered() {
|
if response.hovered() {
|
||||||
ui.ctx().set_cursor_icon(CursorIcon::PointingHand);
|
ui.set_cursor_icon(CursorIcon::PointingHand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,12 +130,12 @@ impl Widget for Hyperlink {
|
|||||||
let response = ui.add(Link::new(text));
|
let response = ui.add(Link::new(text));
|
||||||
|
|
||||||
if response.clicked_with_open_in_background() {
|
if response.clicked_with_open_in_background() {
|
||||||
ui.ctx().open_url(crate::OpenUrl {
|
ui.open_url(crate::OpenUrl {
|
||||||
url: url.clone(),
|
url: url.clone(),
|
||||||
new_tab: true,
|
new_tab: true,
|
||||||
});
|
});
|
||||||
} else if response.clicked() {
|
} else if response.clicked() {
|
||||||
ui.ctx().open_url(crate::OpenUrl {
|
ui.open_url(crate::OpenUrl {
|
||||||
url: url.clone(),
|
url: url.clone(),
|
||||||
new_tab,
|
new_tab,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ pub fn global_theme_preference_switch(ui: &mut Ui) {
|
|||||||
|
|
||||||
/// Show larger buttons for switching between light and dark mode (globally).
|
/// Show larger buttons for switching between light and dark mode (globally).
|
||||||
pub fn global_theme_preference_buttons(ui: &mut Ui) {
|
pub fn global_theme_preference_buttons(ui: &mut Ui) {
|
||||||
let mut theme_preference = ui.ctx().options(|opt| opt.theme_preference);
|
let mut theme_preference = ui.options(|opt| opt.theme_preference);
|
||||||
theme_preference.radio_buttons(ui);
|
theme_preference.radio_buttons(ui);
|
||||||
ui.ctx().set_theme(theme_preference);
|
ui.ctx().set_theme(theme_preference);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ impl Widget for ProgressBar {
|
|||||||
|
|
||||||
if ui.is_rect_visible(response.rect) {
|
if ui.is_rect_visible(response.rect) {
|
||||||
if animate {
|
if animate {
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
let visuals = ui.style().visuals.clone();
|
let visuals = ui.style().visuals.clone();
|
||||||
|
|||||||
@@ -687,7 +687,7 @@ impl Slider<'_> {
|
|||||||
let mut increment = 0usize;
|
let mut increment = 0usize;
|
||||||
|
|
||||||
if response.has_focus() {
|
if response.has_focus() {
|
||||||
ui.ctx().memory_mut(|m| {
|
ui.memory_mut(|m| {
|
||||||
m.set_focus_lock_filter(
|
m.set_focus_lock_filter(
|
||||||
response.id,
|
response.id,
|
||||||
EventFilter {
|
EventFilter {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ impl Spinner {
|
|||||||
/// Paint the spinner in the given rectangle.
|
/// Paint the spinner in the given rectangle.
|
||||||
pub fn paint_at(&self, ui: &Ui, rect: Rect) {
|
pub fn paint_at(&self, ui: &Ui, rect: Rect) {
|
||||||
if ui.is_rect_visible(rect) {
|
if ui.is_rect_visible(rect) {
|
||||||
ui.ctx().request_repaint(); // because it is animated
|
ui.request_repaint(); // because it is animated
|
||||||
|
|
||||||
let color = self
|
let color = self
|
||||||
.color
|
.color
|
||||||
|
|||||||
@@ -605,12 +605,12 @@ impl TextEdit<'_> {
|
|||||||
if did_interact || response.clicked() {
|
if did_interact || response.clicked() {
|
||||||
ui.memory_mut(|mem| mem.request_focus(response.id));
|
ui.memory_mut(|mem| mem.request_focus(response.id));
|
||||||
|
|
||||||
state.last_interaction_time = ui.ctx().input(|i| i.time);
|
state.last_interaction_time = ui.input(|i| i.time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if interactive && response.hovered() {
|
if interactive && response.hovered() {
|
||||||
ui.ctx().set_cursor_icon(CursorIcon::Text);
|
ui.set_cursor_icon(CursorIcon::Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cursor_range = None;
|
let mut cursor_range = None;
|
||||||
@@ -768,7 +768,7 @@ impl TextEdit<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if text.is_mutable() && interactive {
|
if text.is_mutable() && interactive {
|
||||||
let now = ui.ctx().input(|i| i.time);
|
let now = ui.input(|i| i.time);
|
||||||
if response.changed() || selection_changed {
|
if response.changed() || selection_changed {
|
||||||
state.last_interaction_time = now;
|
state.last_interaction_time = now;
|
||||||
}
|
}
|
||||||
@@ -777,7 +777,7 @@ impl TextEdit<'_> {
|
|||||||
// This is for two reasons:
|
// This is for two reasons:
|
||||||
// * Don't give the impression that the user can type into a window without focus
|
// * Don't give the impression that the user can type into a window without focus
|
||||||
// * Don't repaint the ui because of a blinking cursor in an app that is not in focus
|
// * Don't repaint the ui because of a blinking cursor in an app that is not in focus
|
||||||
let viewport_has_focus = ui.ctx().input(|i| i.focused);
|
let viewport_has_focus = ui.input(|i| i.focused);
|
||||||
if viewport_has_focus {
|
if viewport_has_focus {
|
||||||
text_selection::visuals::paint_text_cursor(
|
text_selection::visuals::paint_text_cursor(
|
||||||
ui,
|
ui,
|
||||||
@@ -922,7 +922,7 @@ fn events(
|
|||||||
|
|
||||||
let copy_if_not_password = |ui: &Ui, text: String| {
|
let copy_if_not_password = |ui: &Ui, text: String| {
|
||||||
if !password {
|
if !password {
|
||||||
ui.ctx().copy_text(text);
|
ui.copy_text(text);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ impl AccessibilityInspectorPlugin {
|
|||||||
let node_response = ui.ctx().read_response(selected_node);
|
let node_response = ui.ctx().read_response(selected_node);
|
||||||
|
|
||||||
if let Some(widget_response) = node_response {
|
if let Some(widget_response) = node_response {
|
||||||
ui.ctx().debug_painter().debug_rect(
|
ui.debug_painter().debug_rect(
|
||||||
widget_response.rect,
|
widget_response.rect,
|
||||||
ui.style_mut().visuals.selection.bg_fill,
|
ui.style_mut().visuals.selection.bg_fill,
|
||||||
"",
|
"",
|
||||||
@@ -233,8 +233,7 @@ impl AccessibilityInspectorPlugin {
|
|||||||
let widget_response = ui.ctx().read_response(egui_node_id);
|
let widget_response = ui.ctx().read_response(egui_node_id);
|
||||||
|
|
||||||
if let Some(widget_response) = widget_response {
|
if let Some(widget_response) = widget_response {
|
||||||
ui.ctx()
|
ui.debug_painter()
|
||||||
.debug_painter()
|
|
||||||
.debug_rect(widget_response.rect, Color32::RED, "");
|
.debug_rect(widget_response.rect, Color32::RED, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ impl FractalClock {
|
|||||||
pub fn ui(&mut self, ui: &mut Ui, seconds_since_midnight: Option<f64>) {
|
pub fn ui(&mut self, ui: &mut Ui, seconds_since_midnight: Option<f64>) {
|
||||||
if !self.paused {
|
if !self.paused {
|
||||||
self.time = seconds_since_midnight.unwrap_or_else(|| ui.input(|i| i.time));
|
self.time = seconds_since_midnight.unwrap_or_else(|| ui.input(|i| i.time));
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
let painter = Painter::new(
|
let painter = Painter::new(
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ fn ui_resource(ui: &mut egui::Ui, resource: &Resource) {
|
|||||||
if let Some(text) = &text {
|
if let Some(text) = &text {
|
||||||
let tooltip = "Click to copy the response body";
|
let tooltip = "Click to copy the response body";
|
||||||
if ui.button("📋").on_hover_text(tooltip).clicked() {
|
if ui.button("📋").on_hover_text(tooltip).clicked() {
|
||||||
ui.ctx().copy_text(text.clone());
|
ui.copy_text(text.clone());
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,9 +102,9 @@ impl BackendPanel {
|
|||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
ui.separator();
|
ui.separator();
|
||||||
let mut screen_reader = ui.ctx().options(|o| o.screen_reader);
|
let mut screen_reader = ui.options(|o| o.screen_reader);
|
||||||
ui.checkbox(&mut screen_reader, "🔈 Screen reader").on_hover_text("Experimental feature: checking this will turn on the screen reader on supported platforms");
|
ui.checkbox(&mut screen_reader, "🔈 Screen reader").on_hover_text("Experimental feature: checking this will turn on the screen reader on supported platforms");
|
||||||
ui.ctx().options_mut(|o| o.screen_reader = screen_reader);
|
ui.options_mut(|o| o.screen_reader = screen_reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(debug_assertions) && cfg!(target_arch = "wasm32") {
|
if cfg!(debug_assertions) && cfg!(target_arch = "wasm32") {
|
||||||
@@ -119,7 +119,7 @@ impl BackendPanel {
|
|||||||
if !cfg!(target_arch = "wasm32") {
|
if !cfg!(target_arch = "wasm32") {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui.button("Quit").clicked() {
|
if ui.button("Quit").clicked() {
|
||||||
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
ui.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ impl BackendPanel {
|
|||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Request discard").clicked() {
|
if ui.button("Request discard").clicked() {
|
||||||
ui.ctx().request_discard("Manual button click");
|
ui.request_discard("Manual button click");
|
||||||
|
|
||||||
if !ui.ctx().will_discard() {
|
if !ui.ctx().will_discard() {
|
||||||
ui.label("Discard denied!");
|
ui.label("Discard denied!");
|
||||||
@@ -305,8 +305,7 @@ fn integration_ui(ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
|||||||
.on_hover_text("Fullscreen the window")
|
.on_hover_text("Fullscreen the window")
|
||||||
.changed()
|
.changed()
|
||||||
{
|
{
|
||||||
ui.ctx()
|
ui.send_viewport_cmd(egui::ViewportCommand::Fullscreen(fullscreen));
|
||||||
.send_viewport_cmd(egui::ViewportCommand::Fullscreen(fullscreen));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,10 +332,8 @@ fn integration_ui(ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if let Some(size) = size {
|
if let Some(size) = size {
|
||||||
ui.ctx()
|
ui.send_viewport_cmd(egui::ViewportCommand::InnerSize(size));
|
||||||
.send_viewport_cmd(egui::ViewportCommand::InnerSize(size));
|
ui.send_viewport_cmd(egui::ViewportCommand::Fullscreen(false));
|
||||||
ui.ctx()
|
|
||||||
.send_viewport_cmd(egui::ViewportCommand::Fullscreen(false));
|
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -379,7 +379,7 @@ impl WrapApp {
|
|||||||
.on_hover_text("Forget scroll, positions, sizes etc")
|
.on_hover_text("Forget scroll, positions, sizes etc")
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
ui.ctx().memory_mut(|mem| *mem = Default::default());
|
ui.memory_mut(|mem| *mem = Default::default());
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,8 +423,7 @@ impl WrapApp {
|
|||||||
{
|
{
|
||||||
selected_anchor = anchor;
|
selected_anchor = anchor;
|
||||||
if frame.is_web() {
|
if frame.is_web() {
|
||||||
ui.ctx()
|
ui.open_url(egui::OpenUrl::same_tab(format!("#{anchor}")));
|
||||||
.open_url(egui::OpenUrl::same_tab(format!("#{anchor}")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,7 +435,7 @@ impl WrapApp {
|
|||||||
if clock_button(ui, crate::seconds_since_midnight()).clicked() {
|
if clock_button(ui, crate::seconds_since_midnight()).clicked() {
|
||||||
self.state.selected_anchor = Anchor::Clock;
|
self.state.selected_anchor = Anchor::Clock;
|
||||||
if frame.is_web() {
|
if frame.is_web() {
|
||||||
ui.ctx().open_url(egui::OpenUrl::same_tab("#clock"));
|
ui.open_url(egui::OpenUrl::same_tab("#clock"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ impl crate::View for DancingStrings {
|
|||||||
.on_hover_text("Demonstrates how a path can have varying color across its length.");
|
.on_hover_text("Demonstrates how a path can have varying color across its length.");
|
||||||
|
|
||||||
Frame::canvas(ui.style()).show(ui, |ui| {
|
Frame::canvas(ui.style()).show(ui, |ui| {
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
let time = ui.input(|i| i.time);
|
let time = ui.input(|i| i.time);
|
||||||
|
|
||||||
let desired_size = ui.available_width() * vec2(1.0, 0.35);
|
let desired_size = ui.available_width() * vec2(1.0, 0.35);
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ impl DemoWindows {
|
|||||||
self.groups.checkboxes(ui, &mut self.open);
|
self.groups.checkboxes(ui, &mut self.open);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui.button("Organize windows").clicked() {
|
if ui.button("Organize windows").clicked() {
|
||||||
ui.ctx().memory_mut(|mem| mem.reset_areas());
|
ui.memory_mut(|mem| mem.reset_areas());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -323,11 +323,11 @@ fn file_menu_button(ui: &mut Ui) {
|
|||||||
// or else they would only be checked if the "File" menu was actually open!
|
// or else they would only be checked if the "File" menu was actually open!
|
||||||
|
|
||||||
if ui.input_mut(|i| i.consume_shortcut(&organize_shortcut)) {
|
if ui.input_mut(|i| i.consume_shortcut(&organize_shortcut)) {
|
||||||
ui.ctx().memory_mut(|mem| mem.reset_areas());
|
ui.memory_mut(|mem| mem.reset_areas());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui.input_mut(|i| i.consume_shortcut(&reset_shortcut)) {
|
if ui.input_mut(|i| i.consume_shortcut(&reset_shortcut)) {
|
||||||
ui.ctx().memory_mut(|mem| *mem = Default::default());
|
ui.memory_mut(|mem| *mem = Default::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.menu_button("File", |ui| {
|
ui.menu_button("File", |ui| {
|
||||||
@@ -352,7 +352,7 @@ fn file_menu_button(ui: &mut Ui) {
|
|||||||
)
|
)
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
ui.ctx().memory_mut(|mem| mem.reset_areas());
|
ui.memory_mut(|mem| mem.reset_areas());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui
|
if ui
|
||||||
@@ -363,7 +363,7 @@ fn file_menu_button(ui: &mut Ui) {
|
|||||||
.on_hover_text("Forget scroll, positions, sizes etc")
|
.on_hover_text("Forget scroll, positions, sizes etc")
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
ui.ctx().memory_mut(|mem| *mem = Default::default());
|
ui.memory_mut(|mem| *mem = Default::default());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ impl crate::View for FontBook {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if ui.add(button).on_hover_ui(tooltip_ui).clicked() {
|
if ui.add(button).on_hover_ui(tooltip_ui).clicked() {
|
||||||
ui.ctx().copy_text(chr.to_string());
|
ui.copy_text(chr.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -541,12 +541,12 @@ fn ui_stack_demo(ui: &mut Ui) {
|
|||||||
let response = ui.label(format!("{:?}", node.id));
|
let response = ui.label(format!("{:?}", node.id));
|
||||||
|
|
||||||
if response.hovered() {
|
if response.hovered() {
|
||||||
ui.ctx().debug_painter().debug_rect(
|
ui.debug_painter().debug_rect(
|
||||||
node.max_rect,
|
node.max_rect,
|
||||||
Color32::GREEN,
|
Color32::GREEN,
|
||||||
"max_rect",
|
"max_rect",
|
||||||
);
|
);
|
||||||
ui.ctx().debug_painter().circle_filled(
|
ui.debug_painter().circle_filled(
|
||||||
node.min_rect.min,
|
node.min_rect.min,
|
||||||
2.0,
|
2.0,
|
||||||
Color32::RED,
|
Color32::RED,
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ impl crate::View for Modals {
|
|||||||
*user_modal_open = false;
|
*user_modal_open = false;
|
||||||
} else {
|
} else {
|
||||||
*save_progress = Some(progress + 0.003);
|
*save_progress = Some(progress + 0.003);
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ impl MultiTouch {
|
|||||||
|
|
||||||
let delay = 0.5;
|
let delay = 0.5;
|
||||||
if time_since_last_touch < delay {
|
if time_since_last_touch < delay {
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
} else {
|
} else {
|
||||||
// seconds after which half the amount of zoom/rotation will be reverted:
|
// seconds after which half the amount of zoom/rotation will be reverted:
|
||||||
let half_life =
|
let half_life =
|
||||||
@@ -157,7 +157,7 @@ impl MultiTouch {
|
|||||||
self.zoom = 1. + ((self.zoom - 1.) * half_life_factor);
|
self.zoom = 1. + ((self.zoom - 1.) * half_life_factor);
|
||||||
self.rotation *= half_life_factor;
|
self.rotation *= half_life_factor;
|
||||||
self.translation *= half_life_factor;
|
self.translation *= half_life_factor;
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,7 @@ impl PaintBezier {
|
|||||||
ui.collapsing("Global tessellation options", |ui| {
|
ui.collapsing("Global tessellation options", |ui| {
|
||||||
let mut tessellation_options = ui.ctx().tessellation_options(|to| *to);
|
let mut tessellation_options = ui.ctx().tessellation_options(|to| *to);
|
||||||
tessellation_options.ui(ui);
|
tessellation_options.ui(ui);
|
||||||
ui.ctx()
|
ui.tessellation_options_mut(|to| *to = tessellation_options);
|
||||||
.tessellation_options_mut(|to| *to = tessellation_options);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.radio_value(&mut self.degree, 3, "Quadratic Bézier");
|
ui.radio_value(&mut self.degree, 3, "Quadratic Bézier");
|
||||||
|
|||||||
@@ -43,12 +43,11 @@ impl crate::View for Screenshot {
|
|||||||
let capture = ui.button("📷 Take Screenshot").clicked();
|
let capture = ui.button("📷 Take Screenshot").clicked();
|
||||||
ui.checkbox(&mut self.continuous, "Capture continuously");
|
ui.checkbox(&mut self.continuous, "Capture continuously");
|
||||||
if capture || self.continuous {
|
if capture || self.continuous {
|
||||||
ui.ctx()
|
ui.send_viewport_cmd(ViewportCommand::Screenshot(UserData::default()));
|
||||||
.send_viewport_cmd(ViewportCommand::Screenshot(UserData::default()));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let image = ui.ctx().input(|i| {
|
let image = ui.input(|i| {
|
||||||
i.events
|
i.events
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|e| {
|
.filter_map(|e| {
|
||||||
|
|||||||
@@ -388,6 +388,6 @@ impl crate::View for ScrollStickTo {
|
|||||||
);
|
);
|
||||||
|
|
||||||
self.n_items += 1;
|
self.n_items += 1;
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ impl crate::View for ClipboardTest {
|
|||||||
.horizontal(|ui| {
|
.horizontal(|ui| {
|
||||||
let text_edit_response = ui.text_edit_singleline(&mut self.text);
|
let text_edit_response = ui.text_edit_singleline(&mut self.text);
|
||||||
if ui.button("📋").clicked() {
|
if ui.button("📋").clicked() {
|
||||||
ui.ctx().copy_text(self.text.clone());
|
ui.copy_text(self.text.clone());
|
||||||
}
|
}
|
||||||
text_edit_response
|
text_edit_response
|
||||||
})
|
})
|
||||||
@@ -48,7 +48,7 @@ impl crate::View for ClipboardTest {
|
|||||||
] {
|
] {
|
||||||
if ui.button(name).clicked() {
|
if ui.button(name).clicked() {
|
||||||
// Next frame we should get a copy/cut/paste-event…
|
// Next frame we should get a copy/cut/paste-event…
|
||||||
ui.ctx().send_viewport_cmd(cmd);
|
ui.send_viewport_cmd(cmd);
|
||||||
|
|
||||||
// …that should en up here:
|
// …that should en up here:
|
||||||
text_edit_response.request_focus();
|
text_edit_response.request_focus();
|
||||||
@@ -69,7 +69,7 @@ impl crate::View for ClipboardTest {
|
|||||||
ui.ctx().try_load_image(&uri, Default::default())
|
ui.ctx().try_load_image(&uri, Default::default())
|
||||||
&& ui.button("📋").clicked()
|
&& ui.button("📋").clicked()
|
||||||
{
|
{
|
||||||
ui.ctx().copy_image((*image).clone());
|
ui.copy_image((*image).clone());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ impl crate::Demo for IdTest {
|
|||||||
impl crate::View for IdTest {
|
impl crate::View for IdTest {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
// Make sure the warnings are on (by default they are only on in debug builds).
|
// Make sure the warnings are on (by default they are only on in debug builds).
|
||||||
ui.ctx().options_mut(|opt| opt.warn_on_id_clash = true);
|
ui.options_mut(|opt| opt.warn_on_id_clash = true);
|
||||||
|
|
||||||
ui.heading("Name collision example");
|
ui.heading("Name collision example");
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ impl crate::View for TextEditDemo {
|
|||||||
.cursor
|
.cursor
|
||||||
.set_char_range(Some(egui::text::CCursorRange::one(ccursor)));
|
.set_char_range(Some(egui::text::CCursorRange::one(ccursor)));
|
||||||
state.store(ui.ctx(), text_edit_id);
|
state.store(ui.ctx(), text_edit_id);
|
||||||
ui.ctx().memory_mut(|mem| mem.request_focus(text_edit_id)); // give focus back to the [`TextEdit`].
|
ui.memory_mut(|mem| mem.request_focus(text_edit_id)); // give focus back to the [`TextEdit`].
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ impl crate::View for TextEditDemo {
|
|||||||
.cursor
|
.cursor
|
||||||
.set_char_range(Some(egui::text::CCursorRange::one(ccursor)));
|
.set_char_range(Some(egui::text::CCursorRange::one(ccursor)));
|
||||||
state.store(ui.ctx(), text_edit_id);
|
state.store(ui.ctx(), text_edit_id);
|
||||||
ui.ctx().memory_mut(|mem| mem.request_focus(text_edit_id)); // give focus back to the [`TextEdit`].
|
ui.memory_mut(|mem| mem.request_focus(text_edit_id)); // give focus back to the [`TextEdit`].
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ impl crate::View for TextLayoutDemo {
|
|||||||
|
|
||||||
use egui::text::LayoutJob;
|
use egui::text::LayoutJob;
|
||||||
|
|
||||||
let pixels_per_point = ui.ctx().pixels_per_point();
|
let pixels_per_point = ui.pixels_per_point();
|
||||||
let points_per_pixel = 1.0 / pixels_per_point;
|
let points_per_pixel = 1.0 / pixels_per_point;
|
||||||
|
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
|
|||||||
@@ -69,6 +69,6 @@ impl crate::View for UndoRedoDemo {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.undoer
|
self.undoer
|
||||||
.feed_state(ui.ctx().input(|input| input.time), &self.state);
|
.feed_state(ui.input(|input| input.time), &self.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ fn pixel_test_strokes(ui: &mut Ui) {
|
|||||||
egui::Color32::BLACK
|
egui::Color32::BLACK
|
||||||
};
|
};
|
||||||
|
|
||||||
let pixels_per_point = ui.ctx().pixels_per_point();
|
let pixels_per_point = ui.pixels_per_point();
|
||||||
|
|
||||||
for thickness_pixels in 1..=3 {
|
for thickness_pixels in 1..=3 {
|
||||||
let thickness_pixels = thickness_pixels as f32;
|
let thickness_pixels = thickness_pixels as f32;
|
||||||
@@ -506,7 +506,7 @@ fn pixel_test_squares(ui: &mut Ui) {
|
|||||||
egui::Color32::BLACK
|
egui::Color32::BLACK
|
||||||
};
|
};
|
||||||
|
|
||||||
let pixels_per_point = ui.ctx().pixels_per_point();
|
let pixels_per_point = ui.pixels_per_point();
|
||||||
|
|
||||||
let num_squares = (pixels_per_point * 10.0).round().max(10.0) as u32;
|
let num_squares = (pixels_per_point * 10.0).round().max(10.0) as u32;
|
||||||
let size_pixels = vec2(
|
let size_pixels = vec2(
|
||||||
@@ -532,7 +532,7 @@ fn pixel_test_squares(ui: &mut Ui) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn pixel_test_lines(ui: &mut Ui) {
|
fn pixel_test_lines(ui: &mut Ui) {
|
||||||
let pixels_per_point = ui.ctx().pixels_per_point();
|
let pixels_per_point = ui.pixels_per_point();
|
||||||
let n = (96.0 * pixels_per_point) as usize;
|
let n = (96.0 * pixels_per_point) as usize;
|
||||||
|
|
||||||
ui.label("The lines should be exactly one physical pixel wide, one physical pixel apart.");
|
ui.label("The lines should be exactly one physical pixel wide, one physical pixel apart.");
|
||||||
|
|||||||
@@ -892,7 +892,7 @@ impl Table<'_> {
|
|||||||
let resize_hover = resize_response.hovered() && !dragging_something_else;
|
let resize_hover = resize_response.hovered() && !dragging_something_else;
|
||||||
|
|
||||||
if resize_hover || resize_response.dragged() {
|
if resize_hover || resize_response.dragged() {
|
||||||
ui.ctx().set_cursor_icon(egui::CursorIcon::ResizeColumn);
|
ui.set_cursor_icon(egui::CursorIcon::ResizeColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
let stroke = if resize_response.dragged() {
|
let stroke = if resize_response.dragged() {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl eframe::App for MyApp {
|
|||||||
if ui.button("Yes").clicked() {
|
if ui.button("Yes").clicked() {
|
||||||
self.show_confirmation_dialog = false;
|
self.show_confirmation_dialog = false;
|
||||||
self.allowed_to_close = true;
|
self.allowed_to_close = true;
|
||||||
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
ui.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -106,12 +106,11 @@ fn title_bar_ui(ui: &mut egui::Ui, title_bar_rect: eframe::epaint::Rect, title:
|
|||||||
// Interact with the title bar (drag to move window):
|
// Interact with the title bar (drag to move window):
|
||||||
if title_bar_response.double_clicked() {
|
if title_bar_response.double_clicked() {
|
||||||
let is_maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
|
let is_maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
|
||||||
ui.ctx()
|
ui.send_viewport_cmd(ViewportCommand::Maximized(!is_maximized));
|
||||||
.send_viewport_cmd(ViewportCommand::Maximized(!is_maximized));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if title_bar_response.drag_started_by(PointerButton::Primary) {
|
if title_bar_response.drag_started_by(PointerButton::Primary) {
|
||||||
ui.ctx().send_viewport_cmd(ViewportCommand::StartDrag);
|
ui.send_viewport_cmd(ViewportCommand::StartDrag);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.scope_builder(
|
ui.scope_builder(
|
||||||
@@ -137,7 +136,7 @@ fn close_maximize_minimize(ui: &mut egui::Ui) {
|
|||||||
.add(Button::new(RichText::new("❌").size(button_height)))
|
.add(Button::new(RichText::new("❌").size(button_height)))
|
||||||
.on_hover_text("Close the window");
|
.on_hover_text("Close the window");
|
||||||
if close_response.clicked() {
|
if close_response.clicked() {
|
||||||
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
ui.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
|
let is_maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
|
||||||
@@ -146,15 +145,14 @@ fn close_maximize_minimize(ui: &mut egui::Ui) {
|
|||||||
.add(Button::new(RichText::new("🗗").size(button_height)))
|
.add(Button::new(RichText::new("🗗").size(button_height)))
|
||||||
.on_hover_text("Restore window");
|
.on_hover_text("Restore window");
|
||||||
if maximized_response.clicked() {
|
if maximized_response.clicked() {
|
||||||
ui.ctx()
|
ui.send_viewport_cmd(ViewportCommand::Maximized(false));
|
||||||
.send_viewport_cmd(ViewportCommand::Maximized(false));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let maximized_response = ui
|
let maximized_response = ui
|
||||||
.add(Button::new(RichText::new("🗗").size(button_height)))
|
.add(Button::new(RichText::new("🗗").size(button_height)))
|
||||||
.on_hover_text("Maximize window");
|
.on_hover_text("Maximize window");
|
||||||
if maximized_response.clicked() {
|
if maximized_response.clicked() {
|
||||||
ui.ctx().send_viewport_cmd(ViewportCommand::Maximized(true));
|
ui.send_viewport_cmd(ViewportCommand::Maximized(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +160,6 @@ fn close_maximize_minimize(ui: &mut egui::Ui) {
|
|||||||
.add(Button::new(RichText::new("🗕").size(button_height)))
|
.add(Button::new(RichText::new("🗕").size(button_height)))
|
||||||
.on_hover_text("Minimize the window");
|
.on_hover_text("Minimize the window");
|
||||||
if minimized_response.clicked() {
|
if minimized_response.clicked() {
|
||||||
ui.ctx().send_viewport_cmd(ViewportCommand::Minimized(true));
|
ui.send_viewport_cmd(ViewportCommand::Minimized(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ impl eframe::App for MyApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.blinky {
|
if self.blinky {
|
||||||
let now = ui.ctx().input(|i| i.time);
|
let now = ui.input(|i| i.time);
|
||||||
let blink = now % 1.0 < 0.5;
|
let blink = now % 1.0 < 0.5;
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.inner_margin(3)
|
.inner_margin(3)
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ impl eframe::App for MyApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.blinky {
|
if self.blinky {
|
||||||
let now = ui.ctx().input(|i| i.time);
|
let now = ui.input(|i| i.time);
|
||||||
let blink = now % 1.0 < 0.5;
|
let blink = now % 1.0 < 0.5;
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.inner_margin(3)
|
.inner_margin(3)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ impl eframe::App for Content {
|
|||||||
}
|
}
|
||||||
if ctx.input(|i| i.key_down(Key::A)) {
|
if ctx.input(|i| i.key_down(Key::A)) {
|
||||||
self.text.push_str("\nHeld");
|
self.text.push_str("\nHeld");
|
||||||
ui.ctx().request_repaint(); // make sure we note the holding.
|
ui.request_repaint(); // make sure we note the holding.
|
||||||
}
|
}
|
||||||
if ctx.input(|i| i.key_released(Key::A)) {
|
if ctx.input(|i| i.key_released(Key::A)) {
|
||||||
self.text.push_str("\nReleased");
|
self.text.push_str("\nReleased");
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ impl eframe::App for MyApp {
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.monospace(cmd);
|
ui.monospace(cmd);
|
||||||
if ui.small_button("📋").clicked() {
|
if ui.small_button("📋").clicked() {
|
||||||
ui.ctx().copy_text(cmd.into());
|
ui.copy_text(cmd.into());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ impl eframe::App for MyApp {
|
|||||||
ui.checkbox(&mut self.keep_repainting, "Keep repainting");
|
ui.checkbox(&mut self.keep_repainting, "Keep repainting");
|
||||||
if self.keep_repainting {
|
if self.keep_repainting {
|
||||||
ui.spinner();
|
ui.spinner();
|
||||||
ui.ctx().request_repaint();
|
ui.request_repaint();
|
||||||
} else {
|
} else {
|
||||||
ui.label("Repainting on events (e.g. mouse movement)");
|
ui.label("Repainting on events (e.g. mouse movement)");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ impl eframe::App for MyApp {
|
|||||||
|
|
||||||
if ui.button("Close").clicked() {
|
if ui.button("Close").clicked() {
|
||||||
log::info!("Pressed Close button");
|
log::info!("Pressed Close button");
|
||||||
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
|
ui.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,8 +95,7 @@ fn main() -> eframe::Result {
|
|||||||
.selected_text("ComboBox")
|
.selected_text("ComboBox")
|
||||||
.width(100.0)
|
.width(100.0)
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
ui.ctx()
|
ui.debug_painter()
|
||||||
.debug_painter()
|
|
||||||
.debug_rect(ui.max_rect(), egui::Color32::RED, "");
|
.debug_rect(ui.max_rect(), egui::Color32::RED, "");
|
||||||
|
|
||||||
ui.label("Hello");
|
ui.label("Hello");
|
||||||
|
|||||||
@@ -297,12 +297,12 @@ fn stack_ui_impl(ui: &mut egui::Ui, stack: &egui::UiStack) {
|
|||||||
body.row(20.0, |mut row| {
|
body.row(20.0, |mut row| {
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
if ui.label(format!("{:?}", node.id)).hovered() {
|
if ui.label(format!("{:?}", node.id)).hovered() {
|
||||||
ui.ctx().debug_painter().debug_rect(
|
ui.debug_painter().debug_rect(
|
||||||
node.max_rect,
|
node.max_rect,
|
||||||
egui::Color32::GREEN,
|
egui::Color32::GREEN,
|
||||||
"max",
|
"max",
|
||||||
);
|
);
|
||||||
ui.ctx().debug_painter().circle_filled(
|
ui.debug_painter().circle_filled(
|
||||||
node.min_rect.min,
|
node.min_rect.min,
|
||||||
2.0,
|
2.0,
|
||||||
egui::Color32::RED,
|
egui::Color32::RED,
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ fn generic_child_ui(ui: &mut egui::Ui, vp_state: &mut ViewportState, close_butto
|
|||||||
ui.label("Title:");
|
ui.label("Title:");
|
||||||
if ui.text_edit_singleline(&mut vp_state.title).changed() {
|
if ui.text_edit_singleline(&mut vp_state.title).changed() {
|
||||||
// Title changes
|
// Title changes
|
||||||
ui.ctx().send_viewport_cmd_to(
|
ui.send_viewport_cmd_to(
|
||||||
vp_state.id,
|
vp_state.id,
|
||||||
egui::ViewportCommand::Title(vp_state.title.clone()),
|
egui::ViewportCommand::Title(vp_state.title.clone()),
|
||||||
);
|
);
|
||||||
@@ -430,11 +430,11 @@ fn drag_source<R>(
|
|||||||
// Check for drags:
|
// Check for drags:
|
||||||
let response = ui.interact(res.response.rect, id, egui::Sense::drag());
|
let response = ui.interact(res.response.rect, id, egui::Sense::drag());
|
||||||
if response.hovered() {
|
if response.hovered() {
|
||||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Grab);
|
ui.set_cursor_icon(egui::CursorIcon::Grab);
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing);
|
ui.set_cursor_icon(egui::CursorIcon::Grabbing);
|
||||||
|
|
||||||
// Paint the body to a new layer:
|
// Paint the body to a new layer:
|
||||||
let layer_id = egui::LayerId::new(egui::Order::Tooltip, id);
|
let layer_id = egui::LayerId::new(egui::Order::Tooltip, id);
|
||||||
|
|||||||
Reference in New Issue
Block a user