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 {
last_pointer_serial,
reference_x: request.at.position().0,
reference_y: request.at.position().1,
reference_x: request.placement.position().0,
reference_y: request.placement.position().1,
width,
height,
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::popup_positioning_mode::PopupPositioningMode;
pub use layer_shika_domain::value_objects::popup_request::{
PopupAt, PopupHandle, PopupRequest, PopupSize,
PopupHandle, PopupPlacement, PopupRequest, PopupSize,
};
pub use popup_builder::PopupBuilder;
pub use system::{App, EventContext, EventLoopHandle, ShellControl};
@ -51,7 +51,7 @@ pub mod prelude {
pub use crate::{
AnchorEdges, AnchorStrategy, App, EventContext, EventLoopHandle, KeyboardInteractivity,
Layer, LayerShika, OutputGeometry, OutputHandle, OutputInfo, OutputPolicy, OutputRegistry,
PopupAt, PopupBuilder, PopupHandle, PopupPositioningMode, PopupRequest, PopupSize,
PopupBuilder, PopupHandle, PopupPlacement, PopupPositioningMode, PopupRequest, PopupSize,
PopupWindow, Result, ShellControl,
};

View file

@ -3,12 +3,12 @@ use crate::system::App;
use layer_shika_adapters::platform::slint_interpreter::Value;
use layer_shika_domain::prelude::AnchorStrategy;
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> {
app: &'a App,
component: String,
reference: PopupAt,
reference: PopupPlacement,
anchor: PopupPositioningMode,
size: PopupSize,
grab: bool,
@ -21,7 +21,7 @@ impl<'a> PopupBuilder<'a> {
Self {
app,
component,
reference: PopupAt::Cursor,
reference: PopupPlacement::AtCursor,
anchor: PopupPositioningMode::TopLeft,
size: PopupSize::Content,
grab: false,
@ -32,19 +32,19 @@ impl<'a> PopupBuilder<'a> {
#[must_use]
pub fn relative_to_cursor(mut self) -> Self {
self.reference = PopupAt::Cursor;
self.reference = PopupPlacement::AtCursor;
self
}
#[must_use]
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
}
#[must_use]
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
}
@ -284,7 +284,7 @@ impl<'a> PopupBuilder<'a> {
);
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)
.grab(grab)
.mode(mode);
@ -318,7 +318,7 @@ impl<'a> PopupBuilder<'a> {
fn build_request(&self) -> PopupRequest {
let mut builder = PopupRequest::builder(self.component.clone())
.at(self.reference)
.placement(self.reference)
.size(self.size)
.mode(self.anchor)
.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::popup_positioning_mode::PopupPositioningMode;
use layer_shika_domain::value_objects::popup_request::{
PopupAt, PopupHandle, PopupRequest, PopupSize,
PopupHandle, PopupPlacement, PopupRequest, PopupSize,
};
use std::cell::Cell;
use std::cell::RefCell;
@ -58,14 +58,14 @@ impl ShellControl {
pub fn show_popup_at_cursor(&self, component: impl Into<String>) -> Result<()> {
let request = PopupRequest::builder(component.into())
.at(PopupAt::Cursor)
.placement(PopupPlacement::AtCursor)
.build();
self.show_popup(&request)
}
pub fn show_popup_centered(&self, component: impl Into<String>) -> Result<()> {
let request = PopupRequest::builder(component.into())
.at(PopupAt::Cursor)
.placement(PopupPlacement::AtCursor)
.mode(PopupPositioningMode::Center)
.build();
self.show_popup(&request)
@ -78,7 +78,7 @@ impl ShellControl {
y: f32,
) -> Result<()> {
let request = PopupRequest::builder(component.into())
.at(PopupAt::Absolute { x, y })
.placement(PopupPlacement::AtPosition { x, y })
.build();
self.show_popup(&request)
}
@ -342,8 +342,8 @@ impl EventContext<'_> {
req.component,
initial_dimensions.0,
initial_dimensions.1,
req.at.position().0,
req.at.position().1,
req.placement.position().0,
req.placement.position().1,
req.mode
);

View file

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

View file

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

View file

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