refactor: popup placement renaming

This commit is contained in:
drendog 2025-12-01 00:58:31 +01:00
parent b1c605dd7c
commit a2c376e8fc
Signed by: dwenya
GPG key ID: 8DD77074645332D0
7 changed files with 42 additions and 42 deletions

View file

@ -244,8 +244,8 @@ impl PopupManager {
let params = CreatePopupParams { let params = CreatePopupParams {
last_pointer_serial, last_pointer_serial,
reference_x: request.at.position().0, reference_x: request.placement.position().0,
reference_y: request.at.position().1, reference_y: request.placement.position().1,
width, width,
height, height,
positioning_mode: request.mode, positioning_mode: request.mode,

View file

@ -22,7 +22,7 @@ pub use layer_shika_domain::value_objects::output_info::{OutputGeometry, OutputI
pub use layer_shika_domain::value_objects::output_policy::OutputPolicy; pub use layer_shika_domain::value_objects::output_policy::OutputPolicy;
pub use layer_shika_domain::value_objects::popup_positioning_mode::PopupPositioningMode; pub use layer_shika_domain::value_objects::popup_positioning_mode::PopupPositioningMode;
pub use layer_shika_domain::value_objects::popup_request::{ pub use layer_shika_domain::value_objects::popup_request::{
PopupAt, PopupHandle, PopupRequest, PopupSize, PopupHandle, PopupPlacement, PopupRequest, PopupSize,
}; };
pub use popup_builder::PopupBuilder; pub use popup_builder::PopupBuilder;
pub use system::{App, EventContext, EventLoopHandle, ShellControl}; pub use system::{App, EventContext, EventLoopHandle, ShellControl};
@ -51,7 +51,7 @@ pub mod prelude {
pub use crate::{ pub use crate::{
AnchorEdges, AnchorStrategy, App, EventContext, EventLoopHandle, KeyboardInteractivity, AnchorEdges, AnchorStrategy, App, EventContext, EventLoopHandle, KeyboardInteractivity,
Layer, LayerShika, OutputGeometry, OutputHandle, OutputInfo, OutputPolicy, OutputRegistry, Layer, LayerShika, OutputGeometry, OutputHandle, OutputInfo, OutputPolicy, OutputRegistry,
PopupAt, PopupBuilder, PopupHandle, PopupPositioningMode, PopupRequest, PopupSize, PopupBuilder, PopupHandle, PopupPlacement, PopupPositioningMode, PopupRequest, PopupSize,
PopupWindow, Result, ShellControl, PopupWindow, Result, ShellControl,
}; };

View file

@ -3,12 +3,12 @@ use crate::system::App;
use layer_shika_adapters::platform::slint_interpreter::Value; use layer_shika_adapters::platform::slint_interpreter::Value;
use layer_shika_domain::prelude::AnchorStrategy; use layer_shika_domain::prelude::AnchorStrategy;
use layer_shika_domain::value_objects::popup_positioning_mode::PopupPositioningMode; use layer_shika_domain::value_objects::popup_positioning_mode::PopupPositioningMode;
use layer_shika_domain::value_objects::popup_request::{PopupAt, PopupRequest, PopupSize}; use layer_shika_domain::value_objects::popup_request::{PopupPlacement, PopupRequest, PopupSize};
pub struct PopupBuilder<'a> { pub struct PopupBuilder<'a> {
app: &'a App, app: &'a App,
component: String, component: String,
reference: PopupAt, reference: PopupPlacement,
anchor: PopupPositioningMode, anchor: PopupPositioningMode,
size: PopupSize, size: PopupSize,
grab: bool, grab: bool,
@ -21,7 +21,7 @@ impl<'a> PopupBuilder<'a> {
Self { Self {
app, app,
component, component,
reference: PopupAt::Cursor, reference: PopupPlacement::AtCursor,
anchor: PopupPositioningMode::TopLeft, anchor: PopupPositioningMode::TopLeft,
size: PopupSize::Content, size: PopupSize::Content,
grab: false, grab: false,
@ -32,19 +32,19 @@ impl<'a> PopupBuilder<'a> {
#[must_use] #[must_use]
pub fn relative_to_cursor(mut self) -> Self { pub fn relative_to_cursor(mut self) -> Self {
self.reference = PopupAt::Cursor; self.reference = PopupPlacement::AtCursor;
self self
} }
#[must_use] #[must_use]
pub fn relative_to_point(mut self, x: f32, y: f32) -> Self { pub fn relative_to_point(mut self, x: f32, y: f32) -> Self {
self.reference = PopupAt::Absolute { x, y }; self.reference = PopupPlacement::AtPosition { x, y };
self self
} }
#[must_use] #[must_use]
pub fn relative_to_rect(mut self, x: f32, y: f32, w: f32, h: f32) -> Self { pub fn relative_to_rect(mut self, x: f32, y: f32, w: f32, h: f32) -> Self {
self.reference = PopupAt::AnchorRect { x, y, w, h }; self.reference = PopupPlacement::AtRect { x, y, w, h };
self self
} }
@ -284,7 +284,7 @@ impl<'a> PopupBuilder<'a> {
); );
let mut builder = PopupRequest::builder(component_clone.clone()) let mut builder = PopupRequest::builder(component_clone.clone())
.at(PopupAt::absolute(reference_x, reference_y)) .placement(PopupPlacement::at_position(reference_x, reference_y))
.size(PopupSize::Content) .size(PopupSize::Content)
.grab(grab) .grab(grab)
.mode(mode); .mode(mode);
@ -318,7 +318,7 @@ impl<'a> PopupBuilder<'a> {
fn build_request(&self) -> PopupRequest { fn build_request(&self) -> PopupRequest {
let mut builder = PopupRequest::builder(self.component.clone()) let mut builder = PopupRequest::builder(self.component.clone())
.at(self.reference) .placement(self.reference)
.size(self.size) .size(self.size)
.mode(self.anchor) .mode(self.anchor)
.grab(self.grab); .grab(self.grab);

View file

@ -21,7 +21,7 @@ use layer_shika_domain::value_objects::output_handle::OutputHandle;
use layer_shika_domain::value_objects::output_info::OutputInfo; use layer_shika_domain::value_objects::output_info::OutputInfo;
use layer_shika_domain::value_objects::popup_positioning_mode::PopupPositioningMode; use layer_shika_domain::value_objects::popup_positioning_mode::PopupPositioningMode;
use layer_shika_domain::value_objects::popup_request::{ use layer_shika_domain::value_objects::popup_request::{
PopupAt, PopupHandle, PopupRequest, PopupSize, PopupHandle, PopupPlacement, PopupRequest, PopupSize,
}; };
use std::cell::Cell; use std::cell::Cell;
use std::cell::RefCell; use std::cell::RefCell;
@ -58,14 +58,14 @@ impl ShellControl {
pub fn show_popup_at_cursor(&self, component: impl Into<String>) -> Result<()> { pub fn show_popup_at_cursor(&self, component: impl Into<String>) -> Result<()> {
let request = PopupRequest::builder(component.into()) let request = PopupRequest::builder(component.into())
.at(PopupAt::Cursor) .placement(PopupPlacement::AtCursor)
.build(); .build();
self.show_popup(&request) self.show_popup(&request)
} }
pub fn show_popup_centered(&self, component: impl Into<String>) -> Result<()> { pub fn show_popup_centered(&self, component: impl Into<String>) -> Result<()> {
let request = PopupRequest::builder(component.into()) let request = PopupRequest::builder(component.into())
.at(PopupAt::Cursor) .placement(PopupPlacement::AtCursor)
.mode(PopupPositioningMode::Center) .mode(PopupPositioningMode::Center)
.build(); .build();
self.show_popup(&request) self.show_popup(&request)
@ -78,7 +78,7 @@ impl ShellControl {
y: f32, y: f32,
) -> Result<()> { ) -> Result<()> {
let request = PopupRequest::builder(component.into()) let request = PopupRequest::builder(component.into())
.at(PopupAt::Absolute { x, y }) .placement(PopupPlacement::AtPosition { x, y })
.build(); .build();
self.show_popup(&request) self.show_popup(&request)
} }
@ -342,8 +342,8 @@ impl EventContext<'_> {
req.component, req.component,
initial_dimensions.0, initial_dimensions.0,
initial_dimensions.1, initial_dimensions.1,
req.at.position().0, req.placement.position().0,
req.at.position().1, req.placement.position().1,
req.mode req.mode
); );

View file

@ -18,7 +18,7 @@ impl PopupHandle {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct PopupRequest { pub struct PopupRequest {
pub component: String, pub component: String,
pub at: PopupAt, pub placement: PopupPlacement,
pub size: PopupSize, pub size: PopupSize,
pub mode: PopupPositioningMode, pub mode: PopupPositioningMode,
pub grab: bool, pub grab: bool,
@ -30,13 +30,13 @@ impl PopupRequest {
#[must_use] #[must_use]
pub fn new( pub fn new(
component: String, component: String,
at: PopupAt, placement: PopupPlacement,
size: PopupSize, size: PopupSize,
mode: PopupPositioningMode, mode: PopupPositioningMode,
) -> Self { ) -> Self {
Self { Self {
component, component,
at, placement,
size, size,
mode, mode,
grab: false, grab: false,
@ -52,33 +52,33 @@ impl PopupRequest {
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum PopupAt { pub enum PopupPlacement {
Absolute { x: f32, y: f32 }, AtPosition { x: f32, y: f32 },
Cursor, AtCursor,
AnchorRect { x: f32, y: f32, w: f32, h: f32 }, AtRect { x: f32, y: f32, w: f32, h: f32 },
} }
impl PopupAt { impl PopupPlacement {
#[must_use] #[must_use]
pub const fn absolute(x: f32, y: f32) -> Self { pub const fn at_position(x: f32, y: f32) -> Self {
Self::Absolute { x, y } Self::AtPosition { x, y }
} }
#[must_use] #[must_use]
pub const fn cursor() -> Self { pub const fn at_cursor() -> Self {
Self::Cursor Self::AtCursor
} }
#[must_use] #[must_use]
pub const fn anchor_rect(x: f32, y: f32, w: f32, h: f32) -> Self { pub const fn at_rect(x: f32, y: f32, w: f32, h: f32) -> Self {
Self::AnchorRect { x, y, w, h } Self::AtRect { x, y, w, h }
} }
#[must_use] #[must_use]
pub const fn position(&self) -> (f32, f32) { pub const fn position(&self) -> (f32, f32) {
match *self { match *self {
Self::Absolute { x, y } | Self::AnchorRect { x, y, .. } => (x, y), Self::AtPosition { x, y } | Self::AtRect { x, y, .. } => (x, y),
Self::Cursor => (0.0, 0.0), Self::AtCursor => (0.0, 0.0),
} }
} }
} }
@ -111,7 +111,7 @@ impl PopupSize {
pub struct PopupRequestBuilder { pub struct PopupRequestBuilder {
component: String, component: String,
at: PopupAt, placement: PopupPlacement,
size: PopupSize, size: PopupSize,
mode: PopupPositioningMode, mode: PopupPositioningMode,
grab: bool, grab: bool,
@ -124,7 +124,7 @@ impl PopupRequestBuilder {
pub fn new(component: String) -> Self { pub fn new(component: String) -> Self {
Self { Self {
component, component,
at: PopupAt::Cursor, placement: PopupPlacement::AtCursor,
size: PopupSize::Content, size: PopupSize::Content,
mode: PopupPositioningMode::default(), mode: PopupPositioningMode::default(),
grab: false, grab: false,
@ -134,8 +134,8 @@ impl PopupRequestBuilder {
} }
#[must_use] #[must_use]
pub const fn at(mut self, at: PopupAt) -> Self { pub const fn placement(mut self, placement: PopupPlacement) -> Self {
self.at = at; self.placement = placement;
self self
} }
@ -173,7 +173,7 @@ impl PopupRequestBuilder {
pub fn build(self) -> PopupRequest { pub fn build(self) -> PopupRequest {
PopupRequest { PopupRequest {
component: self.component, component: self.component,
at: self.at, placement: self.placement,
size: self.size, size: self.size,
mode: self.mode, mode: self.mode,
grab: self.grab, grab: self.grab,

View file

@ -44,8 +44,8 @@ pub mod prelude;
pub use layer_shika_composition::{ pub use layer_shika_composition::{
AnchorEdges, AnchorStrategy, App, Error, EventContext, EventLoopHandle, KeyboardInteractivity, AnchorEdges, AnchorStrategy, App, Error, EventContext, EventLoopHandle, KeyboardInteractivity,
Layer, LayerShika, OutputGeometry, OutputHandle, OutputInfo, OutputPolicy, OutputRegistry, Layer, LayerShika, OutputGeometry, OutputHandle, OutputInfo, OutputPolicy, OutputRegistry,
PopupAt, PopupHandle, PopupPositioningMode, PopupRequest, PopupSize, PopupWindow, Result, PopupHandle, PopupPlacement, PopupPositioningMode, PopupRequest, PopupSize, PopupWindow,
ShellControl, Result, ShellControl,
}; };
pub use layer_shika_composition::{slint, slint_interpreter}; pub use layer_shika_composition::{slint, slint_interpreter};

View file

@ -16,7 +16,7 @@ pub use crate::{
// Domain value objects // Domain value objects
pub use crate::{ pub use crate::{
AnchorEdges, KeyboardInteractivity, Layer, OutputGeometry, OutputHandle, OutputInfo, AnchorEdges, KeyboardInteractivity, Layer, OutputGeometry, OutputHandle, OutputInfo,
OutputPolicy, OutputRegistry, PopupAt, PopupHandle, PopupPositioningMode, PopupRequest, OutputPolicy, OutputRegistry, PopupHandle, PopupPlacement, PopupPositioningMode, PopupRequest,
PopupSize, PopupSize,
}; };