forked from iced-rs/iced
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iced-rs#348] feat: add horizontal text alignment to TextInput
- Loading branch information
Showing
7 changed files
with
203 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "text_input_aligned" | ||
version = "0.1.0" | ||
authors = ["Subroto Biswas <sub14biswas@gmail.com>"] | ||
edition = "2018" | ||
publish = false | ||
|
||
[dependencies] | ||
iced = { path = "../..", features = ["async-std", "debug"] } | ||
log = "0.4.0" | ||
log4rs = "0.11.0" | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] | ||
async-std = "1.0" | ||
|
||
[package.metadata.deb] | ||
assets = [ | ||
["target/release/todos", "usr/bin/iced-todos", "755"], | ||
["iced-todos.desktop", "usr/share/applications/", "644"], | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
refresh_rate: 30 seconds | ||
appenders: | ||
stdout: | ||
kind: console | ||
requests: | ||
kind: file | ||
path: "log/requests.log" | ||
encoder: | ||
pattern: "{d} - {m}{n}" | ||
root: | ||
level: debug | ||
appenders: | ||
- stdout | ||
loggers: | ||
gfx_backend_metal: | ||
level: warn | ||
wgpu_core: | ||
level: warn | ||
iced_wgpu: | ||
level: debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use iced::{ | ||
text_input, Application, Column, Command, Container, Element, | ||
HorizontalAlignment, Length, Settings, Text, TextInput, | ||
}; | ||
|
||
struct State { | ||
message: String, | ||
|
||
// Local Element States | ||
input_state: text_input::State, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
enum Event { | ||
OnChange(String), | ||
} | ||
|
||
impl Application for State { | ||
type Executor = iced::executor::Default; | ||
type Message = Event; | ||
type Flags = (); | ||
|
||
fn new(_flags: ()) -> (Self, Command<Event>) { | ||
( | ||
State { | ||
message: "Hello World".to_owned(), | ||
input_state: text_input::State::focused(), | ||
}, | ||
Command::none(), | ||
) | ||
} | ||
|
||
fn title(&self) -> String { | ||
"Hello World Example".to_owned() | ||
} | ||
|
||
fn update(&mut self, event: Event) -> Command<Event> { | ||
match event { | ||
Event::OnChange(message) => { | ||
self.message = message; | ||
} | ||
}; | ||
|
||
Command::none() | ||
} | ||
|
||
fn view(&mut self) -> Element<Event> { | ||
let input = TextInput::new( | ||
&mut self.input_state, | ||
"Type a Message", | ||
&self.message, | ||
Event::OnChange, | ||
) | ||
.padding(15) | ||
.size(30) | ||
.horizontal_alignment(HorizontalAlignment::Left); | ||
|
||
let text = Text::new(self.message.to_string()) | ||
.width(Length::Fill) | ||
.size(100) | ||
.color([0.5, 0.5, 0.5]) | ||
.horizontal_alignment(HorizontalAlignment::Center); | ||
|
||
let column = Column::new().push(input).push(text); | ||
|
||
Container::new(column) | ||
.padding(100) | ||
.width(Length::Fill) | ||
.height(Length::Fill) | ||
.into() | ||
} | ||
} | ||
|
||
fn main() { | ||
log4rs::init_file("examples/hello_world/log4rs.yml", Default::default()) | ||
.unwrap(); | ||
|
||
State::run(Settings::default()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters