panels-w2: review fixes (review-2)

This commit is contained in:
aiongg
2026-11-14 17:56:00 +00:00
parent db29b49895
commit d7ed431c5c
5 changed files with 26 additions and 10 deletions
@@ -8,13 +8,19 @@ use super::shell::{base_shell, os_of, window_info};
use super::spec::WindowLevel;
use super::{HandOff, Record, SEARCH_EVERY, shared};
use crate::runtime::egui::{pass, viewports};
use crate::runtime::frame::PerViewport;
use crate::runtime::frame::{PerViewport, Stored};
use craft_host::target::{Caps, DoubleClick, WindowState};
use craft_window::native::NativeWindow;
use craft_window::policy::Frame;
use egui::{Context, Pos2, Rect, Vec2, ViewportId};
use std::sync::Arc;
/// The last title the host set for a viewport.
#[derive(Default)]
struct SentTitle(Option<String>);
impl Stored for SentTitle {}
/// A window command `act` sends.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
@@ -137,7 +143,19 @@ pub fn act(ctx: &Context, viewport: ViewportId, action: WindowAction) -> bool {
viewports::command(ctx, viewport, egui::ViewportCommand::WindowLevel(level.for_egui(active, os_of(ctx))));
}
}
WindowAction::SetTitle(title) => viewports::command(ctx, viewport, egui::ViewportCommand::Title(title)),
WindowAction::SetTitle(title) => {
// `ViewportInfo::title` is empty on X11 and Wayland, so the host remembers what it set itself.
let fresh = PerViewport::<SentTitle>::with(ctx, viewport, |sent| {
let fresh = sent.0.as_deref() != Some(title.as_str());
if fresh {
sent.0 = Some(title.clone());
}
fresh
});
if fresh {
viewports::command(ctx, viewport, egui::ViewportCommand::Title(title));
}
}
WindowAction::SetOpacity(_) => {}
}
true
+2 -1
View File
@@ -283,7 +283,8 @@ impl<T: Value + 'static> Component for FlyoutButton<'_, T> {
self.open = open;
self.double = cx.press().double_pressed() && cx.press().mods.is_none();
if alt {
if let Some(at) = stepped {
// The release that ends a hold or a drag away fires nothing, with Alt held or not.
if let Some(at) = stepped.filter(|_| !held) {
let tool = &self.tools[at];
cx.fire(tool.command.clone(), FireSource::Pointer);
self.picked = Some(tool.id.clone());
-1
View File
@@ -135,7 +135,6 @@ fn a_click_command_cycles_and_a_hold_lists_the_tools_without_firing_it() {
clicked.fixture.click(&target);
clicked.fixture.idle(3);
assert_eq!(fired(&clicked), 1, "a click fires the click command");
clicked.fixture.key(Key::Tab, Modifiers::NONE);
clicked.fixture.key(Key::Enter, Modifiers::NONE);
assert_eq!(fired(&clicked), 1, "Enter fires it");
clicked.fixture.key(Key::Space, Modifiers::NONE);
+4 -5
View File
@@ -282,8 +282,8 @@ pub struct AppShell<'a, S> {
/// The host's flag for the document tabs, read back through `ShellCx::tabs_visible`.
#[prop]
document_tabs: bool,
/// The window's title: the shell sends `WindowAction::SetTitle` when it differs from the title the viewport
/// reports. Not in an embedded shell.
/// The window's title: the shell sends `WindowAction::SetTitle` every pass and the window host drops a title equal
/// to the last one it set. Not in an embedded shell.
#[prop(into)]
window_title: Option<String>,
/// The name of the body region; the translated "Document" without it.
@@ -433,10 +433,9 @@ impl<'a, S> AppShell<'a, S> {
&& !embedded
&& !ui.is_sizing_pass()
{
// The window host skips a title equal to the one it last set for the viewport.
let ctx = ui.ctx();
if ctx.input(|input| input.viewport().title.clone()).as_deref() != Some(title.as_str()) {
WindowHost::of(ctx).act(pass::current_viewport(ctx), WindowAction::SetTitle(title));
}
WindowHost::of(ctx).act(pass::current_viewport(ctx), WindowAction::SetTitle(title));
}
let env = Env::of(ui);
let outer = env.get::<ShellEntry>().0;
-1
View File
@@ -23,7 +23,6 @@ mod opening;
mod reveal;
mod screen_mode;
mod screen_mode_button;
mod screen_mode_button;
pub use app_shell::{AppShell, AppShellOutput, ShellDialogsCx, ShellRegion, ShellRegionOutput, WindowDialogs};
pub use canvas_shell::{CanvasPanel, CanvasPanelOutput, slots};