feat(bluetooth): icons & text sizing
This commit is contained in:
parent
4f9544f682
commit
f272037bdd
2 changed files with 43 additions and 28 deletions
|
|
@ -301,17 +301,22 @@ impl Application for CosmicBluetoothApplet {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |(dev, _, _)| d.address == dev.address)
|
.map_or(false, |(dev, _, _)| d.address == dev.address)
|
||||||
}) {
|
}) {
|
||||||
let mut row = row![].align_items(Alignment::Center);
|
let mut row = row![
|
||||||
row = row.push(
|
icon(dev.icon.as_str(), 16).style(Svg::Symbolic),
|
||||||
text(dev.name.clone())
|
text(dev.name.clone())
|
||||||
|
.size(14)
|
||||||
.horizontal_alignment(Horizontal::Left)
|
.horizontal_alignment(Horizontal::Left)
|
||||||
.vertical_alignment(Vertical::Center)
|
.vertical_alignment(Vertical::Center)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill)
|
||||||
);
|
]
|
||||||
|
.align_items(Alignment::Center)
|
||||||
|
.spacing(12);
|
||||||
|
|
||||||
match &dev.status {
|
match &dev.status {
|
||||||
BluerDeviceStatus::Connected => {
|
BluerDeviceStatus::Connected => {
|
||||||
row = row.push(
|
row = row.push(
|
||||||
text(fl!("connected"))
|
text(fl!("connected"))
|
||||||
|
.size(14)
|
||||||
.horizontal_alignment(Horizontal::Right)
|
.horizontal_alignment(Horizontal::Right)
|
||||||
.vertical_alignment(Vertical::Center),
|
.vertical_alignment(Vertical::Center),
|
||||||
);
|
);
|
||||||
|
|
@ -333,6 +338,7 @@ impl Application for CosmicBluetoothApplet {
|
||||||
known_bluetooth = known_bluetooth.push(
|
known_bluetooth = known_bluetooth.push(
|
||||||
button(APPLET_BUTTON_THEME)
|
button(APPLET_BUTTON_THEME)
|
||||||
.custom(vec![row.into()])
|
.custom(vec![row.into()])
|
||||||
|
.style(APPLET_BUTTON_THEME)
|
||||||
.on_press(match dev.status {
|
.on_press(match dev.status {
|
||||||
BluerDeviceStatus::Connected => {
|
BluerDeviceStatus::Connected => {
|
||||||
Message::Request(BluerRequest::DisconnectDevice(dev.address))
|
Message::Request(BluerRequest::DisconnectDevice(dev.address))
|
||||||
|
|
@ -358,15 +364,18 @@ impl Application for CosmicBluetoothApplet {
|
||||||
toggler(fl!("bluetooth"), self.bluer_state.bluetooth_enabled, |m| {
|
toggler(fl!("bluetooth"), self.bluer_state.bluetooth_enabled, |m| {
|
||||||
Message::Request(BluerRequest::SetBluetoothEnabled(m))
|
Message::Request(BluerRequest::SetBluetoothEnabled(m))
|
||||||
},)
|
},)
|
||||||
|
.text_size(14)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
// these are not in the UX mockup, but they are useful imo
|
// these are not in the UX mockup, but they are useful imo
|
||||||
toggler(fl!("discoverable"), self.bluer_state.discoverable, |m| {
|
toggler(fl!("discoverable"), self.bluer_state.discoverable, |m| {
|
||||||
Message::Request(BluerRequest::SetDiscoverable(m))
|
Message::Request(BluerRequest::SetDiscoverable(m))
|
||||||
},)
|
},)
|
||||||
|
.text_size(14)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
toggler(fl!("pairable"), self.bluer_state.pairable, |m| {
|
toggler(fl!("pairable"), self.bluer_state.pairable, |m| {
|
||||||
Message::Request(BluerRequest::SetPairable(m))
|
Message::Request(BluerRequest::SetPairable(m))
|
||||||
},)
|
},)
|
||||||
|
.text_size(14)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
]
|
]
|
||||||
.spacing(8)
|
.spacing(8)
|
||||||
|
|
@ -415,6 +424,7 @@ impl Application for CosmicBluetoothApplet {
|
||||||
|
|
||||||
if let Some((device, pin, _)) = self.request_confirmation.as_ref() {
|
if let Some((device, pin, _)) = self.request_confirmation.as_ref() {
|
||||||
let row = column![
|
let row = column![
|
||||||
|
icon(device.icon.as_str(), 16).style(Svg::Symbolic),
|
||||||
text(&device.name)
|
text(&device.name)
|
||||||
.horizontal_alignment(Horizontal::Left)
|
.horizontal_alignment(Horizontal::Left)
|
||||||
.vertical_alignment(Vertical::Center)
|
.vertical_alignment(Vertical::Center)
|
||||||
|
|
@ -425,12 +435,13 @@ impl Application for CosmicBluetoothApplet {
|
||||||
))
|
))
|
||||||
.horizontal_alignment(Horizontal::Left)
|
.horizontal_alignment(Horizontal::Left)
|
||||||
.vertical_alignment(Vertical::Center)
|
.vertical_alignment(Vertical::Center)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill)
|
||||||
|
.size(14),
|
||||||
text(pin)
|
text(pin)
|
||||||
.horizontal_alignment(Horizontal::Center)
|
.horizontal_alignment(Horizontal::Center)
|
||||||
.vertical_alignment(Vertical::Center)
|
.vertical_alignment(Vertical::Center)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.size(24),
|
.size(32),
|
||||||
row![
|
row![
|
||||||
button(Button::Secondary)
|
button(Button::Secondary)
|
||||||
.custom(
|
.custom(
|
||||||
|
|
@ -463,7 +474,7 @@ impl Application for CosmicBluetoothApplet {
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
.padding([0, 24])
|
.padding([0, 24])
|
||||||
.spacing(8);
|
.spacing(12);
|
||||||
list_column.push(row.into());
|
list_column.push(row.into());
|
||||||
}
|
}
|
||||||
if self.show_visible_devices {
|
if self.show_visible_devices {
|
||||||
|
|
@ -478,10 +489,16 @@ impl Application for CosmicBluetoothApplet {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |(dev, _, _)| d.address == dev.address)
|
.map_or(false, |(dev, _, _)| d.address == dev.address)
|
||||||
}) {
|
}) {
|
||||||
let mut row = row![].width(Length::Fill).align_items(Alignment::Center);
|
let row = row![
|
||||||
row = row.push(
|
icon(dev.icon.as_str(), 16).style(Svg::Symbolic),
|
||||||
text(dev.name.clone()).horizontal_alignment(Horizontal::Left),
|
text(dev.name.clone())
|
||||||
);
|
.horizontal_alignment(Horizontal::Left)
|
||||||
|
.size(14),
|
||||||
|
]
|
||||||
|
.width(Length::Fill)
|
||||||
|
.align_items(Alignment::Center)
|
||||||
|
.spacing(12);
|
||||||
|
|
||||||
visible_devices = visible_devices.push(
|
visible_devices = visible_devices.push(
|
||||||
button(APPLET_BUTTON_THEME)
|
button(APPLET_BUTTON_THEME)
|
||||||
.custom(vec![row.width(Length::Fill).into()])
|
.custom(vec![row.width(Length::Fill).into()])
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@ pub struct BluerDevice {
|
||||||
pub address: Address,
|
pub address: Address,
|
||||||
pub status: BluerDeviceStatus,
|
pub status: BluerDeviceStatus,
|
||||||
pub properties: Vec<DeviceProperty>,
|
pub properties: Vec<DeviceProperty>,
|
||||||
|
pub icon: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for BluerDevice {}
|
impl Eq for BluerDevice {}
|
||||||
|
|
@ -197,11 +198,23 @@ impl BluerDevice {
|
||||||
} else {
|
} else {
|
||||||
BluerDeviceStatus::Disconnected
|
BluerDeviceStatus::Disconnected
|
||||||
};
|
};
|
||||||
|
let icon = properties
|
||||||
|
.iter()
|
||||||
|
.find_map(|p| {
|
||||||
|
if let DeviceProperty::Icon(icon) = p {
|
||||||
|
Some(icon.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| "bluetooth-symbolic".into());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
address: device.address(),
|
address: device.address(),
|
||||||
status,
|
status,
|
||||||
properties,
|
properties,
|
||||||
|
icon,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -617,23 +630,8 @@ async fn build_device_list(adapter: &Adapter) -> Vec<BluerDevice> {
|
||||||
Ok(device) => device,
|
Ok(device) => device,
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
let name = device.name().await.unwrap_or_default().unwrap_or_default();
|
|
||||||
let is_paired = device.is_paired().await.unwrap_or_default();
|
devices.push(BluerDevice::from_device(&device).await);
|
||||||
let is_connected = device.is_connected().await.unwrap_or_default();
|
|
||||||
let properties = device.all_properties().await.unwrap_or_default();
|
|
||||||
let status = if is_connected {
|
|
||||||
BluerDeviceStatus::Connected
|
|
||||||
} else if is_paired {
|
|
||||||
BluerDeviceStatus::Paired
|
|
||||||
} else {
|
|
||||||
BluerDeviceStatus::Disconnected
|
|
||||||
};
|
|
||||||
devices.push(BluerDevice {
|
|
||||||
name,
|
|
||||||
address,
|
|
||||||
status,
|
|
||||||
properties,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
devices.sort();
|
devices.sort();
|
||||||
devices
|
devices
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue