Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added masonry/screenshots/radio_button_hello_checked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added masonry/screenshots/radio_button_hello_hovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added masonry/screenshots/radio_button_hello_unchecked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion masonry/src/properties/border_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::any::TypeId;

use vello::kurbo::{Point, RoundedRect, Size, Vec2};
use vello::kurbo::{Ellipse, Point, RoundedRect, Size, Vec2};

use crate::core::{BoxConstraints, Property, UpdateCtx};
use crate::properties::CornerRadius;
Expand Down Expand Up @@ -62,6 +62,15 @@ impl BorderWidth {
pos + Vec2::new(self.width, self.width)
}

/// Creates an ellipse that is inset by the border width.
///
/// Use to display a circle's background.
///
/// Helper function to be called in [`Widget::paint`](crate::core::Widget::paint).
pub fn bg_ellipse(&self, size: Size) -> Ellipse {
size.to_rect().inset(-self.width).to_ellipse()
}

/// Creates a rounded rectangle that is inset by the border width.
///
/// Use to display a box's background.
Expand All @@ -73,6 +82,15 @@ impl BorderWidth {
.to_rounded_rect((border_radius.radius - self.width).max(0.))
}

/// Creates an ellipse that is inset by half the border width.
///
/// Use to display a circle's border.
///
/// Helper function to be called in [`Widget::paint`](crate::core::Widget::paint).
pub fn border_ellipse(&self, size: Size) -> Ellipse {
size.to_rect().inset(-self.width / 2.0).to_ellipse()
}

/// Creates a rounded rectangle that is inset by half the border width.
///
/// Use to display a box's border.
Expand Down
22 changes: 21 additions & 1 deletion masonry/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::properties::{
DisabledContentColor, HoveredBorderColor, Padding, PlaceholderColor, SelectionColor,
UnfocusedSelectionColor,
};
use crate::widgets::{Button, Checkbox, Label, ProgressBar, Spinner, TextArea, TextInput};
use crate::widgets::{
Button, Checkbox, Label, ProgressBar, RadioButton, Spinner, TextArea, TextInput,
};

pub const BORDER_WIDTH: f64 = 1.;

Expand Down Expand Up @@ -135,6 +137,24 @@ pub fn default_property_set() -> DefaultProperties {
properties.insert::<ProgressBar, _>(BorderColor { color: ZYNC_800 });
properties.insert::<ProgressBar, _>(BarColor(ACCENT_COLOR));

// RadioButton
// TODO: The radius should be 50% instead of pixels.
properties.insert::<RadioButton, _>(CornerRadius { radius: 50. });
properties.insert::<RadioButton, _>(BorderWidth {
width: BORDER_WIDTH,
});

properties.insert::<RadioButton, _>(Background::Color(ZYNC_800));
properties.insert::<RadioButton, _>(ActiveBackground(Background::Color(ZYNC_700)));
properties.insert::<RadioButton, _>(DisabledBackground(Background::Color(Color::BLACK)));
properties.insert::<RadioButton, _>(BorderColor { color: ZYNC_700 });
properties.insert::<RadioButton, _>(HoveredBorderColor(BorderColor { color: ZYNC_500 }));

properties.insert::<RadioButton, _>(CheckmarkColor { color: TEXT_COLOR });
properties.insert::<RadioButton, _>(DisabledCheckmarkColor(CheckmarkColor {
color: DISABLED_TEXT_COLOR,
}));

// Spinner
properties.insert::<Spinner, _>(ContentColor::new(TEXT_COLOR));

Expand Down
4 changes: 4 additions & 0 deletions masonry/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ mod label;
mod portal;
mod progress_bar;
mod prose;
mod radio_button;
mod radio_group;
mod scroll_bar;
mod sized_box;
mod slider;
Expand All @@ -36,6 +38,8 @@ pub use self::label::Label;
pub use self::portal::Portal;
pub use self::progress_bar::ProgressBar;
pub use self::prose::Prose;
pub use self::radio_button::{RadioButton, RadioButtonToggled};
pub use self::radio_group::RadioGroup;
pub use self::scroll_bar::ScrollBar;
pub use self::sized_box::SizedBox;
pub use self::slider::Slider;
Expand Down
Loading