Initial
This commit is contained in:
commit
1f9eee77ce
9 changed files with 3352 additions and 0 deletions
3
.gitignore
vendored
Executable file
3
.gitignore
vendored
Executable file
|
@ -0,0 +1,3 @@
|
|||
/target
|
||||
*.tar.gz
|
||||
*.minisig
|
3126
Cargo.lock
generated
Normal file
3126
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
15
Cargo.toml
Executable file
15
Cargo.toml
Executable file
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "iced_demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
opt-level = 3
|
||||
strip = true
|
||||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
iced = "0.12.1"
|
BIN
iced_demo
Executable file
BIN
iced_demo
Executable file
Binary file not shown.
9
makefile
Normal file
9
makefile
Normal file
|
@ -0,0 +1,9 @@
|
|||
PROJECT = $(shell basename $(CURDIR))
|
||||
GITHASH = $(shell git rev-parse --short HEAD)
|
||||
|
||||
release:
|
||||
cargo build --release
|
||||
cp target/release/$(PROJECT) $(PROJECT)
|
||||
strip $(PROJECT)
|
||||
tar -czf $(PROJECT)_$(GITHASH).tar.gz $(PROJECT)
|
||||
minisign -Sm $(PROJECT).tar.gz
|
84
src/main.rs
Executable file
84
src/main.rs
Executable file
|
@ -0,0 +1,84 @@
|
|||
use iced::theme::{self, Theme};
|
||||
use iced::widget::{button, column, row, text};
|
||||
use iced::widget::{text_input, TextInput};
|
||||
use iced::{Alignment, Color, Element, Length, Sandbox, Settings};
|
||||
|
||||
mod my_theme;
|
||||
use my_theme::{get_theme, FromHexColor, OneDark};
|
||||
|
||||
mod search_bar;
|
||||
use search_bar::*;
|
||||
|
||||
mod message;
|
||||
use message::*;
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
Counter::run(Settings::default())
|
||||
}
|
||||
|
||||
struct AppSettings {
|
||||
entries_per_page: u32,
|
||||
}
|
||||
|
||||
struct Counter {
|
||||
theme: Theme,
|
||||
value: i32,
|
||||
input_val: String,
|
||||
current_tab: Tab,
|
||||
app_settings: AppSettings,
|
||||
}
|
||||
|
||||
impl Sandbox for Counter {
|
||||
type Message = Message;
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
value: 0,
|
||||
input_val: String::from("0"),
|
||||
theme: get_theme(),
|
||||
current_tab: Tab::Content,
|
||||
app_settings: AppSettings {
|
||||
entries_per_page: 10,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Counter - Iced")
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::InputChanged(value) => {
|
||||
self.input_val = value.clone();
|
||||
if let Ok(value) = value.parse::<i32>() {
|
||||
self.value = value;
|
||||
}
|
||||
}
|
||||
Message::SwitchTab(tab) => {
|
||||
self.current_tab = tab;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
column![
|
||||
row![text::Text::new("TFTool").size(50)],
|
||||
row![tabs(&self)],
|
||||
match self.current_tab {
|
||||
Tab::Content => search_bar(&self),
|
||||
Tab::Settings => text::Text::new("Settings").into(),
|
||||
}
|
||||
]
|
||||
.width(Length::Fill)
|
||||
.padding([55, 0])
|
||||
.align_items(Alignment::Center)
|
||||
.into()
|
||||
// row![TextInput::new("Search", &self.input_val).on_input(Message::InputChanged)].into()
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme.clone()
|
||||
}
|
||||
}
|
16
src/message.rs
Executable file
16
src/message.rs
Executable file
|
@ -0,0 +1,16 @@
|
|||
// #[derive(Debug, Clone)]
|
||||
// pub enum SearchMessage {
|
||||
// InputSubmitted,
|
||||
// }
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Tab {
|
||||
Content,
|
||||
Settings,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
InputChanged(String),
|
||||
SwitchTab(Tab),
|
||||
}
|
63
src/my_theme.rs
Executable file
63
src/my_theme.rs
Executable file
|
@ -0,0 +1,63 @@
|
|||
use iced::{theme, Color, Theme};
|
||||
|
||||
pub trait FromHexColor {
|
||||
fn from_hex_str(hex: &str) -> Option<Box<Self>>;
|
||||
fn from_hex(hex: u32) -> Self;
|
||||
}
|
||||
|
||||
impl FromHexColor for Color {
|
||||
fn from_hex_str(hex: &str) -> Option<Box<Self>> {
|
||||
match u32::from_str_radix(hex.trim_start_matches('#'), 16) {
|
||||
Ok(hex) => Some(Box::new(Self::from_hex(hex))),
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn from_hex(hex: u32) -> Self {
|
||||
let r = ((hex >> 16) & 0xFF) as f32 / 255f32;
|
||||
let g = ((hex >> 8) & 0xFF) as f32 / 255f32;
|
||||
let b = (hex & 0xFF) as f32 / 255f32;
|
||||
let a = ((hex >> 24) & 0xFF) as f32 / 255f32;
|
||||
Color::from_rgba(r, g, b, a)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
pub enum OneDark {
|
||||
Black = 0x282c34,
|
||||
Red = 0xe06c75,
|
||||
Green = 0x98c379,
|
||||
Yellow = 0xe5c07b,
|
||||
Blue = 0x61afef,
|
||||
Purple = 0xc678dd,
|
||||
Cyan = 0x56b6c2,
|
||||
// White = 0xdcdfe4,
|
||||
White = 0xabb2bf,
|
||||
}
|
||||
|
||||
/// One Dark:
|
||||
// Black 40; 44; 52 #282c34
|
||||
// White 171; 178; 191 #abb2bf
|
||||
// Light Red 224; 108; 117 #e06c75
|
||||
// Dark Red 190; 80; 70 #be5046
|
||||
// Green 152; 195; 121 #98c379
|
||||
// Light Yellow 229; 192; 123 #e5c07b
|
||||
// Dark Yellow 209; 154; 102 #d19a66
|
||||
// Blue 97; 175; 239 #61afef
|
||||
// Magenta 198; 120; 221 #c678dd
|
||||
// Cyan 86; 182; 194 #56b6c2
|
||||
// Gutter Grey 76; 82; 99 #4b5263
|
||||
// Comment Grey 92; 99; 112 #5c6370
|
||||
|
||||
pub fn get_theme() -> Theme {
|
||||
Theme::custom(
|
||||
"Wellwell".to_string(),
|
||||
theme::Palette {
|
||||
background: Color::from_hex(OneDark::Black as u32),
|
||||
primary: Color::from_hex(OneDark::Blue as u32),
|
||||
text: Color::from_hex(0xabb2bf),
|
||||
success: Color::from_hex(0x98c379),
|
||||
danger: Color::from_hex(0xe06c75),
|
||||
},
|
||||
)
|
||||
}
|
36
src/search_bar.rs
Executable file
36
src/search_bar.rs
Executable file
|
@ -0,0 +1,36 @@
|
|||
use iced::{
|
||||
application::StyleSheet,
|
||||
theme,
|
||||
widget::{button, row, text_input, TextInput},
|
||||
Element, Length, Padding,
|
||||
};
|
||||
|
||||
use crate::*;
|
||||
use crate::{message::Message::*, Counter};
|
||||
|
||||
pub fn search_bar(state: &Counter) -> Element<Message> {
|
||||
row![TextInput::new("Search", &state.input_val)
|
||||
.on_input(Message::InputChanged)
|
||||
.width(300)]
|
||||
.into()
|
||||
}
|
||||
|
||||
fn menu_tab_button<'a>(label: &'a str, tab: Tab) -> Element<'a, Message> {
|
||||
button(label)
|
||||
.on_press(SwitchTab(tab))
|
||||
.padding(Padding::from([10, 20]))
|
||||
.width(Length::FillPortion(1))
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn tabs(state: &Counter) -> Element<Message> {
|
||||
row![
|
||||
menu_tab_button("Content", Tab::Content),
|
||||
menu_tab_button("Settings", Tab::Settings),
|
||||
]
|
||||
.padding(10)
|
||||
.spacing(20)
|
||||
.width(300)
|
||||
.height(Length::Shrink)
|
||||
.into()
|
||||
}
|
Loading…
Reference in a new issue