Skip to content

Commit

Permalink
feat: custom titlebar
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jun 9, 2024
1 parent 68a41eb commit 53dab18
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 56 deletions.
27 changes: 14 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ image = { version = "0.24", features = ["png"] }
qrcode-generator = "4.1"
window-vibrancy = "0.5"

[dependencies.windows-sys]
version = "0.52"
features = ["Win32_Foundation", "Win32_UI_Controls"]

[patch.crates-io]
freya = { git = "https://github.com/marc2332/freya", rev = "bf08123c62b94f0ca2d3aaece8374c9569ebb16f" }
freya-engine = { git = "https://github.com/marc2332/freya", rev = "bf08123c62b94f0ca2d3aaece8374c9569ebb16f" }
freya-hooks = { git = "https://github.com/marc2332/freya", rev = "bf08123c62b94f0ca2d3aaece8374c9569ebb16f" }
freya = { git = "https://github.com/marc2332/freya", rev = "b75fd3cbc67fc6e278e20fee4379f2cd38c1cbc8" }
freya-engine = { git = "https://github.com/marc2332/freya", rev = "b75fd3cbc67fc6e278e20fee4379f2cd38c1cbc8" }
freya-hooks = { git = "https://github.com/marc2332/freya", rev = "b75fd3cbc67fc6e278e20fee4379f2cd38c1cbc8" }
38 changes: 24 additions & 14 deletions src/components/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct FluentButtonProps {
pub children: Element,
pub theme: Option<ButtonThemeWith>,
pub enabled: Option<bool>,
pub onclick: Option<EventHandler<Option<MouseEvent>>>,
pub onpress: Option<EventHandler<PressEvent>>,
pub width: Option<String>,
pub height: Option<String>,
pub padding: Option<String>,
Expand All @@ -19,6 +19,7 @@ pub struct FluentButtonProps {
pub cross_align: Option<String>,
pub main_align: Option<String>,
pub flat: Option<bool>,
pub font_size: Option<String>,
}

#[allow(non_snake_case)]
Expand All @@ -31,15 +32,24 @@ pub fn FluentButton(props: FluentButtonProps) -> Element {

let focus_id = focus.attribute();

let user_click = &props.onclick;
let onpress = &props.onpress;

let onclick = {
to_owned![user_click];
move |ev| {
let onpointerup = {
to_owned![onpress];
move |ev: PointerEvent| {
if enabled {
focus.focus();
if let Some(onclick) = &user_click {
onclick.call(Some(ev))
if let Some(onpress) = &onpress {
let is_valid = match ev.data.pointer_type {
PointerType::Mouse {
trigger_button: Some(MouseButton::Left),
} => true,
PointerType::Touch { phase, .. } => phase == TouchPhase::Ended,
_ => false,
};
if is_valid {
onpress.call(PressEvent::Pointer(ev))
}
}
}
}
Expand All @@ -63,12 +73,10 @@ pub fn FluentButton(props: FluentButtonProps) -> Element {
platform.set_cursor(CursorIcon::Default);
});

let onkeydown = {
move |e: KeyboardEvent| {
if enabled && focus.validate_keydown(e) {
if let Some(onclick) = &props.onclick {
onclick(None)
}
let onkeydown = move |e| {
if enabled && focus.validate_keydown(&e) {
if let Some(onpress) = &props.onpress {
onpress(PressEvent::Key(e))
}
}
};
Expand Down Expand Up @@ -113,14 +121,15 @@ pub fn FluentButton(props: FluentButtonProps) -> Element {
let direction = props.direction.as_deref().unwrap_or("vertical");
let cross_align = props.cross_align.as_deref().unwrap_or("center");
let main_align = props.main_align.as_deref().unwrap_or("center");
let font_size = props.font_size.as_deref();
let corner_radius = props
.corner_radius
.as_deref()
.unwrap_or(&theme.corner_radius);

rsx!(
rect {
onclick,
onpointerup,
onmouseenter,
onmouseleave,
onkeydown,
Expand All @@ -136,6 +145,7 @@ pub fn FluentButton(props: FluentButtonProps) -> Element {
direction,
cross_align,
main_align,
font_size,
{&props.children}
}
)
Expand Down
Loading

0 comments on commit 53dab18

Please sign in to comment.