forked from 1b-agent/opencadstudio-upstream
refactor(statusbar): unify popup menus
This commit is contained in:
1 parent
d5be78a187
commit
b9de8940bc
14 files changed
+478
-557
No files matched your search
+13
-43
@@ -1,10 +1,10 @@
|
||||
//! Drawing-units picker — sets the INSUNITS header value. Rendered as a
|
||||
//! floating overlay above the status bar, same pattern as the scale picker.
|
||||
//! Drawing-units status menu.
|
||||
|
||||
use iced::widget::{button, column, container, mouse_area, row, text};
|
||||
use iced::{Background, Border, Color, Element, Fill, Length, Rectangle, Theme};
|
||||
use iced::widget::{button, row, text};
|
||||
use iced::{Background, Color, Element, Fill, Theme};
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::ui::statusbar::status_menu::Entry;
|
||||
|
||||
/// Units offered in the picker: (INSUNITS code, menu label).
|
||||
const UNITS: &[(i16, &str)] = &[
|
||||
@@ -35,35 +35,17 @@ pub fn unit_short(code: i16) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// Full-screen overlay: transparent click-catcher + units list pinned
|
||||
/// bottom-right, above the status bar.
|
||||
pub fn units_popup_overlay(
|
||||
current: i16,
|
||||
pill: Option<Rectangle>,
|
||||
win: (f32, f32),
|
||||
) -> Element<'static, Message> {
|
||||
let rows: Vec<Element<'static, Message>> = UNITS
|
||||
pub fn menu_entries(current: i16) -> Vec<Entry<'static>> {
|
||||
UNITS
|
||||
.iter()
|
||||
.map(|&(code, label)| unit_row(label, code == current, Message::SetDrawingUnits(code)))
|
||||
.collect();
|
||||
|
||||
let panel = container(column(rows))
|
||||
.style(|_: &Theme| container::Style {
|
||||
background: Some(Background::Color(PANEL_BG)),
|
||||
border: Border {
|
||||
color: PANEL_BORDER,
|
||||
width: 1.0,
|
||||
radius: 3.0.into(),
|
||||
},
|
||||
..Default::default()
|
||||
.map(|&(code, label)| {
|
||||
Entry::close(unit_row(
|
||||
label,
|
||||
code == current,
|
||||
Message::SetDrawingUnits(code),
|
||||
))
|
||||
})
|
||||
.width(Length::Fixed(140.0));
|
||||
|
||||
let positioned = super::position_statusbar_popup(panel.into(), pill, win, 140.0, true);
|
||||
|
||||
mouse_area(positioned)
|
||||
.on_press(Message::CloseUnitsPopup)
|
||||
.into()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn unit_row(label: &'static str, active: bool, msg: Message) -> Element<'static, Message> {
|
||||
@@ -91,18 +73,6 @@ fn unit_row(label: &'static str, active: bool, msg: Message) -> Element<'static,
|
||||
|
||||
// ── Colours ───────────────────────────────────────────────────────────────
|
||||
|
||||
const PANEL_BG: Color = Color {
|
||||
r: 0.15,
|
||||
g: 0.15,
|
||||
b: 0.15,
|
||||
a: 1.0,
|
||||
};
|
||||
const PANEL_BORDER: Color = Color {
|
||||
r: 0.32,
|
||||
g: 0.32,
|
||||
b: 0.32,
|
||||
a: 1.0,
|
||||
};
|
||||
const ROW_HOVER: Color = Color {
|
||||
r: 0.22,
|
||||
g: 0.22,
|
||||
|
||||
Reference in new issue
Block a user