You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iced 0.10.0设置resizable=false无法禁用最大化按钮求助

Iced 0.10.0中resizable=false无法禁用窗口最大化按钮的问题与解决方案

问题描述

  • 在Iced 0.9.0及更早版本中,将iced::window::Settings的resizable设为false时,窗口的最大化按钮会被禁用(按钮变灰,无法点击)。
  • 升级到Iced 0.10.0后,相同设置下,窗口最大化按钮仍处于启用状态,可正常点击触发窗口最大化,导致预期的窗口尺寸限制失效。

复现代码

use iced::window;
use iced::settings::Settings;
use iced::{Element, Sandbox};
use iced::widget::{column, progress_bar, slider};

pub fn main() -> iced::Result {
    Progress::run(Settings{
         window: iced::window::Settings 
         { 
                    resizable: false,
                    ..window::Settings::default()
             },
             ..Settings::default()
         }
    )
}

#[derive(Default)]
struct Progress {
    value: f32,
}

#[derive(Debug, Clone, Copy)]
enum Message {
    SliderChanged(f32),
}

impl Sandbox for Progress {
    type Message = Message;

    fn new() -> Self {
        Self::default()
    }

    fn title(&self) -> String {
        String::from("A simple Progressbar")
    }

    fn update(&mut self, message: Message) {
        match message {
            Message::SliderChanged(x) => self.value = x,
        }
    }

    fn view(&self) -> Element<Message> {
        column![
            progress_bar(0.0..=100.0, self.value),
            slider(0.0..=100.0, self.value, Message::SliderChanged).step(0.01)
        ]
        .padding(20)
        .into()
    }
}

临时解决方案

Iced 0.10.0对窗口设置的逻辑进行了调整,resizable不再直接控制最大化按钮的状态。可以通过自定义底层winit的WindowBuilder来显式禁用最大化按钮,同时保留resizable=false的设置:

修改main函数中的Settings配置:

pub fn main() -> iced::Result {
    Progress::run(Settings {
        window: window::Settings {
            resizable: false,
            // 通过自定义WindowBuilder显式禁用最大化按钮
            window_builder: Some(Box::new(|builder| {
                builder.maximizable(false).resizable(false)
            })),
            ..window::Settings::default()
        },
        ..Settings::default()
    })
}

说明

  • 该方法直接操作Iced底层依赖的winit库的窗口构建器,显式设置maximizable(false),确保最大化按钮被禁用。
  • 同时保留resizable=false以防止用户通过拖拽边缘调整窗口尺寸,实现与旧版本一致的窗口限制效果。
  • 此方案跨平台有效(Windows、macOS、Linux均适用)。

后续建议

可以关注Iced官方仓库的相关issue,等待官方修复resizable属性的行为回归,或查看后续版本的更新日志确认该问题是否被解决。

内容的提问来源于stack exchange,提问作者Mayank Joshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 11:52:45