Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic window control #670

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

melix99
Copy link
Contributor

@melix99 melix99 commented Oct 14, 2024

This is the first merge-able part of #606.

It allows to implement custom CSDs via window management signals and a new WindowHandle widget which is useful to implement a custom titlebar.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the additional signals; less sure about the new widget

masonry/src/widget/window_handle.rs Outdated Show resolved Hide resolved

/// A titlebar area widget.
///
/// An area that can be dragged to move the window.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some more documentation about how it's expected to be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I hope it's clear enough.

ctx.place_child(child, Point::ORIGIN);
bc.constrain(size)
}
None => bc.max(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect this to impose a max height by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my reply below. This is supposed to be just a container, so users of this widget should wrap it in their titlebar custom widget. So, I think that just filling the constrain is the right thing to do.

fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
match self.child.as_mut() {
Some(child) => {
let size = ctx.run_layout(child, bc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe similarly here, although I can see arguments for not doing so

masonry/src/widget/window_handle.rs Show resolved Hide resolved
masonry/src/widget/window_handle.rs Outdated Show resolved Hide resolved
fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {}

fn accessibility_role(&self) -> Role {
Role::GenericContainer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this is right, but I'm not certain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's right, since this is a container. The actual titlebar should have the Role::TitleBar.

masonry/src/widget/window_handle.rs Outdated Show resolved Hide resolved
}
}

fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing drawn at all here feels a bit weird

Copy link
Contributor Author

@melix99 melix99 Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my reply below. This is supposed to be just a container, so users of this widget should wrap it in their titlebar custom widget and do their drawing in there.

@melix99
Copy link
Contributor Author

melix99 commented Oct 18, 2024

Well, I guess I should've included more information on how the WindowHandle is supposed to work, so that it's clearer what my intentions are with this PR.

The WindowHandle is a widget area that allows you to move the window by dragging with your mouse. It's also a single-child container, so you are expected to put the content of the titlebar in there (title label, buttons, menus, etc.) . It's important to know that it's not supposed to be a titlebar by itself, you are still supposed to implement your own titlebar widget that wraps the WindowHandle. This way this widget is completely flexible on the titlebar design you want to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants