Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ windows-sys = { version = "0.59", features = [
"Win32_UI_Accessibility",
"Win32_UI_Controls",
"Win32_UI_HiDpi",
"Win32_UI_Input_KeyboardAndMouse",
"Win32_UI_Shell",
"Win32_UI_WindowsAndMessaging",
] }
Expand Down
21 changes: 12 additions & 9 deletions examples/widgets.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use winio::{
App, BrushPen, Button, ButtonEvent, Canvas, CanvasEvent, CheckBox, CheckBoxEvent, Child, Color,
ColorTheme, ComboBox, ComboBoxEvent, ComboBoxMessage, Component, ComponentSender,
DrawingFontBuilder, Edit, GradientStop, Grid, HAlign, Label, Layoutable, LinearGradientBrush,
Margin, MessageBox, MessageBoxButton, ObservableVec, ObservableVecEvent, Orient, Point,
Progress, RadialGradientBrush, RadioButton, RadioButtonGroup, Rect, RelativePoint,
RelativeSize, Size, SolidColorBrush, StackPanel, TextBox, VAlign, Visible, Window, WindowEvent,
DrawingFontBuilder, Edit, Enable, GradientStop, Grid, HAlign, Label, Layoutable,
LinearGradientBrush, Margin, MessageBox, MessageBoxButton, ObservableVec, ObservableVecEvent,
Orient, Point, Progress, RadialGradientBrush, RadioButton, RadioButtonGroup, Rect,
RelativePoint, RelativeSize, Size, SolidColorBrush, StackPanel, TextBox, VAlign, Visible,
Window, WindowEvent,
};

fn main() {
Expand Down Expand Up @@ -219,6 +220,7 @@ impl Component for MainModel {
true
}
MainMessage::List(e) => {
self.pop_button.set_enabled(!self.list.is_empty());
self.combo
.emit(ComboBoxMessage::from_observable_vec_event(e))
.await
Expand Down Expand Up @@ -250,11 +252,12 @@ impl Component for MainModel {
MainMessage::Show => {
MessageBox::new()
.title("Show selected item")
.message(if let Some(index) = self.index {
self.list[index].as_str()
} else {
"No selection."
})
.message(
self.index
.and_then(|index| self.list.get(index))
.map(|s| s.as_str())
.unwrap_or("No selection."),
)
.buttons(MessageBoxButton::Ok)
.show(Some(&*self.window))
.await;
Expand Down
14 changes: 13 additions & 1 deletion src/elm/button.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{BorrowedWindow, Component, ComponentSender, Layoutable, Point, Size, Visible, ui};
use crate::{
BorrowedWindow, Component, ComponentSender, Enable, Layoutable, Point, Size, Visible, ui,
};

/// A simple button.
#[derive(Debug)]
Expand Down Expand Up @@ -28,6 +30,16 @@ impl Visible for Button {
}
}

impl Enable for Button {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for Button {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
14 changes: 12 additions & 2 deletions src/elm/canvas.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
BorrowedWindow, Component, ComponentSender, DrawingContext, Layoutable, MouseButton, Point,
Size, Visible, ui,
BorrowedWindow, Component, ComponentSender, DrawingContext, Enable, Layoutable, MouseButton,
Point, Size, Visible, ui,
};

/// A simple drawing canvas.
Expand All @@ -26,6 +26,16 @@ impl Visible for Canvas {
}
}

impl Enable for Canvas {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for Canvas {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
14 changes: 13 additions & 1 deletion src/elm/check_box.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{BorrowedWindow, Component, ComponentSender, Layoutable, Point, Size, Visible, ui};
use crate::{
BorrowedWindow, Component, ComponentSender, Enable, Layoutable, Point, Size, Visible, ui,
};

/// A simple check box.
#[derive(Debug)]
Expand Down Expand Up @@ -38,6 +40,16 @@ impl Visible for CheckBox {
}
}

impl Enable for CheckBox {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for CheckBox {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
34 changes: 33 additions & 1 deletion src/elm/combo_box.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::ObservableVecEvent;
use crate::{BorrowedWindow, Component, ComponentSender, Layoutable, Point, Size, Visible, ui};
use crate::{
BorrowedWindow, Component, ComponentSender, Enable, Layoutable, Point, Size, Visible, ui,
};

/// A simple combo box.
#[derive(Debug)]
Expand Down Expand Up @@ -64,6 +66,16 @@ impl Visible for ComboBox {
}
}

impl Enable for ComboBox {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for ComboBox {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down Expand Up @@ -236,6 +248,26 @@ impl ComboEntry {
}
}

impl Visible for ComboEntry {
fn is_visible(&self) -> bool {
self.widget.is_visible()
}

fn set_visible(&mut self, v: bool) {
self.widget.set_visible(v);
}
}

impl Enable for ComboEntry {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for ComboEntry {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
13 changes: 12 additions & 1 deletion src/elm/edit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
BorrowedWindow, Component, ComponentSender, HAlign, Layoutable, Point, Size, Visible, ui,
BorrowedWindow, Component, ComponentSender, Enable, HAlign, Layoutable, Point, Size, Visible,
ui,
};

/// A simple single-line text input box.
Expand Down Expand Up @@ -50,6 +51,16 @@ impl Visible for Edit {
}
}

impl Enable for Edit {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for Edit {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
13 changes: 12 additions & 1 deletion src/elm/label.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
BorrowedWindow, Component, ComponentSender, HAlign, Layoutable, Point, Size, Visible, ui,
BorrowedWindow, Component, ComponentSender, Enable, HAlign, Layoutable, Point, Size, Visible,
ui,
};

/// A simple single-line label.
Expand Down Expand Up @@ -40,6 +41,16 @@ impl Visible for Label {
}
}

impl Enable for Label {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for Label {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
19 changes: 19 additions & 0 deletions src/elm/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ pub trait Visible {
}
}

/// Trait for a widget to enable or disable.
pub trait Enable {
/// If the widget is enabled.
fn is_enabled(&self) -> bool;

/// Set if the widget is enabled.
fn set_enabled(&mut self, v: bool);

/// Enable the widget.
fn enable(&mut self) {
self.set_enabled(true);
}

/// Disable the widget.
fn disable(&mut self) {
self.set_enabled(false);
}
}

/// Trait for a layoutable widget.
pub trait Layoutable {
/// The left top location.
Expand Down
14 changes: 13 additions & 1 deletion src/elm/progress.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{BorrowedWindow, Component, ComponentSender, Layoutable, Point, Size, Visible, ui};
use crate::{
BorrowedWindow, Component, ComponentSender, Enable, Layoutable, Point, Size, Visible, ui,
};

/// A progress bar.
#[derive(Debug)]
Expand Down Expand Up @@ -48,6 +50,16 @@ impl Visible for Progress {
}
}

impl Enable for Progress {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for Progress {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
14 changes: 13 additions & 1 deletion src/elm/radio_button.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{BorrowedWindow, Component, ComponentSender, Layoutable, Point, Size, Visible, ui};
use crate::{
BorrowedWindow, Component, ComponentSender, Enable, Layoutable, Point, Size, Visible, ui,
};

/// A simple radio box. See [`RadioButtonGroup`] for making selection groups.
#[derive(Debug)]
Expand Down Expand Up @@ -38,6 +40,16 @@ impl Visible for RadioButton {
}
}

impl Enable for RadioButton {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for RadioButton {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
13 changes: 12 additions & 1 deletion src/elm/text_box.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
BorrowedWindow, Component, ComponentSender, HAlign, Layoutable, Point, Size, Visible, ui,
BorrowedWindow, Component, ComponentSender, Enable, HAlign, Layoutable, Point, Size, Visible,
ui,
};

/// A simple multi-line text input box.
Expand Down Expand Up @@ -42,6 +43,16 @@ impl Visible for TextBox {
}
}

impl Enable for TextBox {
fn is_enabled(&self) -> bool {
self.widget.is_enabled()
}

fn set_enabled(&mut self, v: bool) {
self.widget.set_enabled(v);
}
}

impl Layoutable for TextBox {
fn loc(&self) -> Point {
self.widget.loc()
Expand Down
10 changes: 9 additions & 1 deletion src/ui/gtk/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ impl Button {
self.handle.is_visible()
}

pub fn set_visible(&self, v: bool) {
pub fn set_visible(&mut self, v: bool) {
self.handle.set_visible(v);
}

pub fn is_enabled(&self) -> bool {
self.handle.is_enabled()
}

pub fn set_enabled(&mut self, v: bool) {
self.handle.set_enabled(v);
}

pub fn preferred_size(&self) -> Size {
self.handle.preferred_size()
}
Expand Down
10 changes: 9 additions & 1 deletion src/ui/gtk/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,18 @@ impl Canvas {
self.handle.is_visible()
}

pub fn set_visible(&self, v: bool) {
pub fn set_visible(&mut self, v: bool) {
self.handle.set_visible(v);
}

pub fn is_enabled(&self) -> bool {
self.handle.is_enabled()
}

pub fn set_enabled(&mut self, v: bool) {
self.handle.set_enabled(v);
}

pub fn loc(&self) -> Point {
self.handle.loc()
}
Expand Down
Loading