mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
api: Change logical/physical position and size on window (#1620)
* Add `RequestedSize` and `RequestedPosition` enum to enable asking for logical or physical size/position. * Rename `Window::size()` to `Window::physical_size()` * Make `Window::set_size(...)` take an `Into<RequestedSize>` * Rename `Window::position()` to `Window::physical_position()` * Make `Window::set_position(...)` take an `Into<RequestedPosition>` * Change `WindowAdapter` and related classes to be able to handle requests being made in the either physical or logical units. Implement this for C++, Rust and node.
This commit is contained in:
parent
9bef6f519a
commit
53a3c72b57
11 changed files with 298 additions and 85 deletions
|
@ -313,9 +313,11 @@ fn gen_corelib(
|
|||
"slint_windowrc_request_redraw",
|
||||
"slint_windowrc_on_close_requested",
|
||||
"slint_windowrc_position",
|
||||
"slint_windowrc_set_position",
|
||||
"slint_windowrc_set_logical_position",
|
||||
"slint_windowrc_set_physical_position",
|
||||
"slint_windowrc_size",
|
||||
"slint_windowrc_set_size",
|
||||
"slint_windowrc_set_logical_size",
|
||||
"slint_windowrc_set_physical_size",
|
||||
"slint_new_path_elements",
|
||||
"slint_new_path_events",
|
||||
"slint_color_brighter",
|
||||
|
|
|
@ -25,6 +25,8 @@ struct ComponentVTable;
|
|||
struct ItemVTable;
|
||||
}
|
||||
#include "slint_internal.h"
|
||||
#include "slint_size.h"
|
||||
#include "slint_point.h"
|
||||
#include "slint_backend_internal.h"
|
||||
#include "slint_qt_internal.h"
|
||||
#include "slint_selector_internal.h"
|
||||
|
@ -178,23 +180,33 @@ public:
|
|||
|
||||
void request_redraw() const { cbindgen_private::slint_windowrc_request_redraw(&inner); }
|
||||
|
||||
slint::Point<int> position() const
|
||||
slint::PhysicalPosition position() const
|
||||
{
|
||||
slint::Point<int> pos { 0, 0 };
|
||||
slint::PhysicalPosition pos { 0, 0 };
|
||||
cbindgen_private::slint_windowrc_position(&inner, &pos);
|
||||
return pos;
|
||||
}
|
||||
|
||||
void set_position(const slint::Point<int> &pos)
|
||||
void set_logical_position(const slint::LogicalPosition &pos)
|
||||
{
|
||||
cbindgen_private::slint_windowrc_set_position(&inner, &pos);
|
||||
cbindgen_private::slint_windowrc_set_logical_position(&inner, &pos);
|
||||
}
|
||||
|
||||
slint::Size<unsigned int> size() const { return cbindgen_private::slint_windowrc_size(&inner); }
|
||||
|
||||
void set_size(const slint::Size<unsigned int> &size)
|
||||
void set_physical_position(const slint::PhysicalPosition &pos)
|
||||
{
|
||||
cbindgen_private::slint_windowrc_set_size(&inner, &size);
|
||||
cbindgen_private::slint_windowrc_set_physical_position(&inner, &pos);
|
||||
}
|
||||
|
||||
slint::PhysicalSize size() const { return cbindgen_private::slint_windowrc_size(&inner); }
|
||||
|
||||
void set_logical_size(const slint::LogicalSize &size)
|
||||
{
|
||||
cbindgen_private::slint_windowrc_set_logical_size(&inner, &size);
|
||||
}
|
||||
|
||||
void set_physical_size(const slint::PhysicalSize &size)
|
||||
{
|
||||
cbindgen_private::slint_windowrc_set_physical_size(&inner, &size);
|
||||
}
|
||||
|
||||
/// Registers a font by the specified path. The path must refer to an existing
|
||||
|
@ -416,20 +428,27 @@ public:
|
|||
|
||||
/// Returns the position of the window on the screen, in physical screen coordinates and
|
||||
/// including a window frame (if present).
|
||||
slint::Point<int> position() const { return inner.position(); }
|
||||
slint::PhysicalPosition position() const { return inner.position(); }
|
||||
|
||||
/// Sets the position of the window on the screen, in physical screen coordinates and including
|
||||
/// a window frame (if present).
|
||||
/// Note that on some windowing systems, such as Wayland, this functionality is not available.
|
||||
void set_position(const slint::Point<int> &pos) { inner.set_position(pos); }
|
||||
void set_position(const slint::LogicalPosition &pos) { inner.set_logical_position(pos); }
|
||||
/// Sets the position of the window on the screen, in physical screen coordinates and including
|
||||
/// a window frame (if present).
|
||||
/// Note that on some windowing systems, such as Wayland, this functionality is not available.
|
||||
void set_position(const slint::PhysicalPosition &pos) { inner.set_physical_position(pos); }
|
||||
|
||||
/// Returns the size of the window on the screen, in physical screen coordinates and excluding
|
||||
/// a window frame (if present).
|
||||
slint::Size<unsigned int> size() const { return inner.size(); }
|
||||
slint::PhysicalSize size() const { return inner.size(); }
|
||||
|
||||
/// Resizes the window to the specified size on the screen, in logical pixels and excluding
|
||||
/// a window frame (if present).
|
||||
void set_size(const slint::LogicalSize &size) { inner.set_logical_size(size); }
|
||||
/// Resizes the window to the specified size on the screen, in physical pixels and excluding
|
||||
/// a window frame (if present).
|
||||
void set_size(const slint::Size<unsigned int> &size) { inner.set_size(size); }
|
||||
void set_size(const slint::PhysicalSize &size) { inner.set_physical_size(size); }
|
||||
|
||||
/// \private
|
||||
private_api::WindowAdapterRc &window_handle() { return inner; }
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace slint {
|
||||
|
||||
/// The Point structure is used to represent a two-dimensional point
|
||||
|
@ -26,4 +28,9 @@ template<typename T>
|
|||
using Point2D = Point<T>;
|
||||
}
|
||||
|
||||
/// A position in logical pixel coordinates
|
||||
using LogicalPosition = Point<float>;
|
||||
/// A position in physical pixel coordinates
|
||||
using PhysicalPosition = Point<int32_t>;
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace slint {
|
||||
|
||||
/// The Size structure is used to represent a two-dimensional size
|
||||
|
@ -26,4 +28,9 @@ template<typename T>
|
|||
using Size2D = Size<T>;
|
||||
}
|
||||
|
||||
/// A size given in logical pixels
|
||||
using LogicalSize = Size<float>;
|
||||
/// A size given in physical pixels.
|
||||
using PhysicalSize = Size<uint32_t>;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue