use std::cell::{Cell, RefCell};
use std::rc::Rc;
use windui::prelude::*;
const BG: u32 = 0xEEF1F5;
const SIDEBAR: u32 = 0xF7F8FA;
const CARD: u32 = 0xFFFFFF;
const FG: u32 = 0x2D3436;
const SUB: u32 = 0x8A9099;
const HEAD: u32 = 0x9AA0A6;
fn section_header(text: &str) -> Element {
Element::label(text).font_size(12.0).fg(Color::hex(HEAD)).height(22).width_match()
}
fn setting_row(label: &str, indent: i32, control: Element) -> Element {
Element::row()
.width_match()
.height(44)
.cross(Align::Center)
.child(Element::label(label).font_size(14.0).fg(Color::hex(FG)).width(180 - indent).margin_xy(indent / 2, 0))
.child(Element::label("").weight(1.0))
.child(control)
}
fn main() {
let nav_sel = Rc::new(Cell::new(0usize)); let attr_expand = Rc::new(Cell::new(true)); let zh_form = Rc::new(Cell::new(0usize)); let width_mode = Rc::new(Cell::new(0usize)); let cn_en = Rc::new(Cell::new(0usize)); let pinyin = Rc::new(Cell::new(0usize)); let hide_bar = Rc::new(Cell::new(false));
let fullscreen_hide = Rc::new(Cell::new(true));
let fuzzy = Rc::new(Cell::new(true));
let status = Rc::new(RefCell::new(String::from("提示:点击带 > 的行可钻入子页")));
let sidebar = Element::col()
.width(170)
.height_match()
.bg(Color::hex(SIDEBAR))
.padding(10)
.spacing(4)
.child(Element::label("输入法设置").font_size(15.0).fg(Color::hex(FG)).height(34).width_match())
.child(Element::divider())
.child(Element::collapsible(
"属性设置",
attr_expand.clone(),
Element::list(
vec!["常用", "外观", "词库", "账户", "按键", "高级"],
nav_sel.clone(),
)
.width_match()
.height(6 * 36),
));
let (s1, s2, s3) = (status.clone(), status.clone(), status.clone());
let content = Element::scroll().fill().weight(1.0).child(
Element::col()
.width_match()
.padding(22)
.spacing(6)
.child(Element::label("常用").font_size(20.0).fg(Color::hex(FG)).height(34).width_match())
.child(section_header("默认状态"))
.child(setting_row("简体 / 繁体", 0, Element::segmented(vec!["简体", "繁体"], zh_form.clone())))
.child(setting_row("半角 / 全角", 0, Element::segmented(vec!["半角", "全角"], width_mode.clone())))
.child(setting_row("中文 / 英文", 0, Element::segmented(vec!["中文", "英文"], cn_en.clone())))
.child(setting_row("隐藏状态栏", 0, Element::switch(hide_bar.clone())))
.child(
Element::row()
.width_match()
.height(44)
.cross(Align::Center)
.child(Element::label("显示输入指示器").font_size(14.0).fg(Color::hex(FG)).margin_xy(12, 0))
.child(
Element::label("(?)")
.font_size(13.0)
.fg(Color::hex(SUB))
.height(20)
.tooltip("开启后,输入时在光标附近显示当前输入状态(中/英、全/半角等)"),
)
.child(Element::label("").weight(1.0))
.child(Element::switch(Rc::new(Cell::new(false))).disabled(true)),
)
.child(setting_row("全屏隐藏状态栏", 0, Element::switch(fullscreen_hide.clone())))
.child(Element::divider())
.child(section_header("输入习惯"))
.child(setting_row("输入方案", 0, Element::segmented(vec!["全拼", "双拼", "笔画"], pinyin.clone())))
.child(Element::nav_row("双拼方案设定").on_click(move |_| *s1.borrow_mut() = "已进入:双拼方案设定".into()))
.child(setting_row("拼音纠错", 0, Element::switch(fuzzy.clone())))
.child(Element::nav_row("拼音纠错设置").on_click(move |_| *s2.borrow_mut() = "已进入:拼音纠错设置".into()))
.child(Element::nav_row("模糊音设置").on_click(move |_| *s3.borrow_mut() = "已进入:模糊音设置".into()))
.child(Element::divider())
.child(Element::label_rc(status.clone()).font_size(13.0).fg(Color::hex(SUB)).height(20).width_match()),
);
let ui = Element::row()
.fill()
.bg(Color::hex(CARD))
.child(sidebar)
.child(content);
App::new("输入法设置 — windui 示例", 720, 520)
.bg(Color::hex(BG))
.screenshot_from_args()
.content(ui)
.run();
}