mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-13 09:12:19 +00:00
Consider label when calculating layout info for native groupboxes
This commit is contained in:
parent
5199556e9d
commit
1544158344
1 changed files with 28 additions and 2 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
use i_slint_core::input::FocusEventResult;
|
use i_slint_core::input::FocusEventResult;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(FieldOffsets, Default, SlintElement)]
|
#[derive(FieldOffsets, Default, SlintElement)]
|
||||||
#[pin]
|
#[pin]
|
||||||
|
|
@ -29,6 +30,27 @@ struct GroupBoxData {
|
||||||
paddings: Property<qttypes::QMargins>,
|
paddings: Property<qttypes::QMargins>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn minimum_group_box_size(title: qttypes::QString) -> qttypes::QSize {
|
||||||
|
return cpp!(unsafe [title as "QString"] -> qttypes::QSize as "QSize" {
|
||||||
|
ensure_initialized();
|
||||||
|
|
||||||
|
QStyleOptionGroupBox option;
|
||||||
|
option.text = title;
|
||||||
|
option.lineWidth = 1;
|
||||||
|
option.midLineWidth = 0;
|
||||||
|
option.subControls = QStyle::SC_GroupBoxFrame;
|
||||||
|
if (!title.isEmpty()) {
|
||||||
|
option.subControls |= QStyle::SC_GroupBoxLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFontMetrics metrics = option.fontMetrics;
|
||||||
|
int baseWidth = metrics.horizontalAdvance(title) + metrics.horizontalAdvance(QLatin1Char(' '));
|
||||||
|
int baseHeight = metrics.height();
|
||||||
|
|
||||||
|
return qApp->style()->sizeFromContents(QStyle::CT_GroupBox, &option, QSize(baseWidth, baseHeight), nullptr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
impl Item for NativeGroupBox {
|
impl Item for NativeGroupBox {
|
||||||
fn init(self: Pin<&Self>, _window: &WindowRc) {
|
fn init(self: Pin<&Self>, _window: &WindowRc) {
|
||||||
let shared_data = Rc::pin(GroupBoxData::default());
|
let shared_data = Rc::pin(GroupBoxData::default());
|
||||||
|
|
@ -120,10 +142,14 @@ impl Item for NativeGroupBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_info(self: Pin<&Self>, orientation: Orientation, _window: &WindowRc) -> LayoutInfo {
|
fn layout_info(self: Pin<&Self>, orientation: Orientation, _window: &WindowRc) -> LayoutInfo {
|
||||||
|
let text: qttypes::QString = self.title().as_str().into();
|
||||||
|
|
||||||
|
let size = minimum_group_box_size(text);
|
||||||
|
|
||||||
LayoutInfo {
|
LayoutInfo {
|
||||||
min: match orientation {
|
min: match orientation {
|
||||||
Orientation::Horizontal => self.native_padding_left() + self.native_padding_right(),
|
Orientation::Horizontal => size.width as f32,
|
||||||
Orientation::Vertical => self.native_padding_top() + self.native_padding_bottom(),
|
Orientation::Vertical => size.height as f32,
|
||||||
},
|
},
|
||||||
stretch: 1.,
|
stretch: 1.,
|
||||||
..LayoutInfo::default()
|
..LayoutInfo::default()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue